<commit_before>#!/bin/bash

##
## Install i-doit on a GNU/Linux operating system
##

##
## Copyright (C) 2017 synetics GmbH, <https://i-doit.com/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##

set -u

##
## Configuration
##
## You **should not** edit this config. You will be asked for your preferred settings.
##

MARIADB_HOSTNAME="localhost"
MARIADB_SUPERUSER_PASSWORD="<PASSWORD>"
MARIADB_INNODB_BUFFER_POOL_SIZE="1G"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
IDOIT_ADMIN_CENTER_PASSWORD="<PASSWORD>"
MARIADB_IDOIT_USERNAME="idoit"
MARIADB_IDOIT_PASSWORD="<PASSWORD>"
IDOIT_DEFAULT_TENANT="CMDB"
INSTALL_DIR="/var/www/html"
DATE=`date +%Y-m-d`
TMP_DIR="/tmp/i-doit_${DATE}"
UPDATE_FILE_PRO="https://i-doit.com/updates.xml"
UPDATE_FILE_OPEN="https://i-doit.org/updates.xml"
OS=""
SCRIPT_SETTINGS="/etc/i-doit/i-doit.sh"
CONTROLLER_BIN="/usr/local/bin/idoit"
JOBS_BIN="/usr/local/bin/idoit-jobs"
CRON_FILE="/etc/cron.d/i-doit"
BACKUP_DIR="/var/backups/i-doit"
BASENAME=`basename $0`
VERSION="0.5"

MARIADB_BIN=""
SUDO_BIN=""
UNZIP_BIN=""
WGET_BIN=""

##--------------------------------------------------------------------------------------------------

function execute {
    log "Install i-doit on a GNU/Linux operating system"
    log ""
    log "Attention:"
    log "This script alters your OS. It will install new packages and will change configuration settings."
    log "Only use it on a fresh installation of a GNU/Linux OS."
    log "It comes with absolutely no warrenty."
    log "Read the documentation carefully before you continue:"
    log ""
    log "    https://github.com/bheisig/i-doit-scripts"
    log ""
    log "This script will automatically…"
    log ""
    log "    1) install additional distribution packages,"
    log "    2) alter configuration of your PHP environment,"
    log "    3) alter configuration of your Apache Web server,"
    log "    4) alter configuration of your MariaDB DBMS, and"
    log "    5) download and install the latest version of i-doit pro or open"
    log "    6) deploy cron jobs and an easy-to-use CLI tool for your i-doit instance"
    log "    7) deploy scripts to backup and restore your i-doit instance"
    log ""
    log "You may skip any step if you like."
    log ""

    askYesNo "Do you really want to continue?"
    if [[ "$?" -gt 0 ]]; then
        log "Bye"
        exit 0
    fi

    log "\n--------------------------------------------------------------------------------\n"

    identifyOS

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the operating system?"
    if [[ "$?" -eq 0 ]]; then
        configureOS
    fi

    checkRequirements

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the PHP environment?"
    if [[ "$?" -eq 0 ]]; then
        configurePHP
    fi

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the Apache Web server?"
    if [[ "$?" -eq 0 ]]; then
        configureApache
    fi

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure MariaDB?"
    if [[ "$?" -eq 0 ]]; then
        configureMariaDB
    fi

    log "\n--------------------------------------------------------------------------------\n"

    local status=0

    askYesNo "Do you want to prepare and install i-doit automatically?"
    if [[ "$?" -eq 0 ]]; then
        prepareIDoit
        installIDoit

        local ipaddress=$(hostname -I |tr -d '[:space:]')
        log "Your setup is ready. Navigate to"
        log ""
        log "    http://${ipaddress}/"
        log ""
        log "with your Web browser and login with username/password 'admin'"

        status=1
    else
        log "Your operating system is prepared for the installation of i-doit."
        log "To complete the setup please follow the instructions as described in the i-doit Knowledge Base:"
        log ""
        log "    https://kb.i-doit.com/display/en/Setup"
    fi

    if [[ "$status" = 1 ]]; then
        log "\n--------------------------------------------------------------------------------\n"

        askYesNo "Do you want to configure i-doit cron jobs?"
        if [[ "$?" -eq 0 ]]; then
            deployScriptSettings
            deployController
            deployJobScript<commit_msg>Get primary IP address on all supported operating systems<commit_after>#!/bin/bash

##
## Install i-doit on a GNU/Linux operating system
##

##
## Copyright (C) 2017 synetics GmbH, <https://i-doit.com/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##

set -u

##
## Configuration
##
## You **should not** edit this config. You will be asked for your preferred settings.
##

MARIADB_HOSTNAME="localhost"
MARIADB_SUPERUSER_PASSWORD="<PASSWORD>"
MARIADB_INNODB_BUFFER_POOL_SIZE="1G"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
IDOIT_ADMIN_CENTER_PASSWORD="<PASSWORD>"
MARIADB_IDOIT_USERNAME="idoit"
MARIADB_IDOIT_PASSWORD="<PASSWORD>"
IDOIT_DEFAULT_TENANT="CMDB"
INSTALL_DIR="/var/www/html"
DATE=`date +%Y-m-d`
TMP_DIR="/tmp/i-doit_${DATE}"
UPDATE_FILE_PRO="https://i-doit.com/updates.xml"
UPDATE_FILE_OPEN="https://i-doit.org/updates.xml"
OS=""
SCRIPT_SETTINGS="/etc/i-doit/i-doit.sh"
CONTROLLER_BIN="/usr/local/bin/idoit"
JOBS_BIN="/usr/local/bin/idoit-jobs"
CRON_FILE="/etc/cron.d/i-doit"
BACKUP_DIR="/var/backups/i-doit"
BASENAME=`basename $0`
VERSION="0.5"

MARIADB_BIN=""
SUDO_BIN=""
UNZIP_BIN=""
WGET_BIN=""

##--------------------------------------------------------------------------------------------------

function execute {
    log "Install i-doit on a GNU/Linux operating system"
    log ""
    log "Attention:"
    log "This script alters your OS. It will install new packages and will change configuration settings."
    log "Only use it on a fresh installation of a GNU/Linux OS."
    log "It comes with absolutely no warrenty."
    log "Read the documentation carefully before you continue:"
    log ""
    log "    https://github.com/bheisig/i-doit-scripts"
    log ""
    log "This script will automatically…"
    log ""
    log "    1) install additional distribution packages,"
    log "    2) alter configuration of your PHP environment,"
    log "    3) alter configuration of your Apache Web server,"
    log "    4) alter configuration of your MariaDB DBMS, and"
    log "    5) download and install the latest version of i-doit pro or open"
    log "    6) deploy cron jobs and an easy-to-use CLI tool for your i-doit instance"
    log "    7) deploy scripts to backup and restore your i-doit instance"
    log ""
    log "You may skip any step if you like."
    log ""

    askYesNo "Do you really want to continue?"
    if [[ "$?" -gt 0 ]]; then
        log "Bye"
        exit 0
    fi

    log "\n--------------------------------------------------------------------------------\n"

    identifyOS

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the operating system?"
    if [[ "$?" -eq 0 ]]; then
        configureOS
    fi

    checkRequirements

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the PHP environment?"
    if [[ "$?" -eq 0 ]]; then
        configurePHP
    fi

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure the Apache Web server?"
    if [[ "$?" -eq 0 ]]; then
        configureApache
    fi

    log "\n--------------------------------------------------------------------------------\n"

    askYesNo "Do you want to configure MariaDB?"
    if [[ "$?" -eq 0 ]]; then
        configureMariaDB
    fi

    log "\n--------------------------------------------------------------------------------\n"

    local status=0

    askYesNo "Do you want to prepare and install i-doit automatically?"
    if [[ "$?" -eq 0 ]]; then
        prepareIDoit
        installIDoit

        local ip_address=`ip route get 1 | awk '{print $NF;exit}'`

        log "Your setup is ready. Navigate to"
        log ""
        log "    http://${ip_address}/"
        log ""
        log "with your Web browser and login with username/password 'admin'"

        status=1
    else
        log "Your operating system is prepared for the installation of i-doit."
        log "To complete the setup please follow the instructions as described in the i-doit Knowledge Base:"
        log ""
        log "    https://kb.i-doit.com/display/en/Setup"
    fi

    if [[ "$status" = 1 ]]; then
        log "\n--------------------------------------------------------------------------------\n"

        askYesNo "Do you want to configure i-doit cron jobs?"
        if [[ "$?" -eq 0 ]]; then
            deployScriptSettings
            deployController
            deployJobScript
{'fraction_non_alphanumeric': 0.22631425517442424, 'fraction_numerical': 0.005344475755514527, 'mean_word_length': 1.806653940550859, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 10, 'lorem ipsum': 0, 'www.': 8, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '181575', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2791, 'n_words': 1003}