From 4e10ece8ca640f99b41d6239bcbb949fd5e16c4a Mon Sep 17 00:00:00 2001 From: Sylvain Dangin Date: Sun, 23 Feb 2020 21:50:20 +0100 Subject: [PATCH] Revert install --- install/OS_specific/Docker/supervisord.conf | 26 - install/OS_specific/windows/pre_inst.sh | 0 install/apache/nextdom-common | 0 install/apache/nextdom-ssl.conf | 0 install/apache/nextdom.conf | 0 .../{scripts => }/fix_apache_private_tmp.sh | 0 install/install_docker.sh | 61 -- install/install_git.sh | 15 - install/install_git_dev.sh | 16 - install/postinst | 790 +++++++++++++++++- install/restore.php | 0 install/scripts/config.sh | 43 - install/scripts/debian-update.sh | 4 - install/scripts/postinst.sh | 560 ------------- install/scripts/preinst.sh | 495 ----------- install/scripts/utils.sh | 235 ------ install/supervisord.conf | 28 - install/update.php | 3 +- 18 files changed, 782 insertions(+), 1494 deletions(-) delete mode 100644 install/OS_specific/Docker/supervisord.conf mode change 100755 => 100644 install/OS_specific/windows/pre_inst.sh mode change 100755 => 100644 install/apache/nextdom-common mode change 100755 => 100644 install/apache/nextdom-ssl.conf mode change 100755 => 100644 install/apache/nextdom.conf rename install/{scripts => }/fix_apache_private_tmp.sh (100%) delete mode 100755 install/install_docker.sh delete mode 100755 install/install_git.sh delete mode 100755 install/install_git_dev.sh mode change 100755 => 100644 install/postinst mode change 100755 => 100644 install/restore.php delete mode 100644 install/scripts/config.sh delete mode 100755 install/scripts/debian-update.sh delete mode 100755 install/scripts/postinst.sh delete mode 100644 install/scripts/preinst.sh delete mode 100644 install/scripts/utils.sh delete mode 100644 install/supervisord.conf diff --git a/install/OS_specific/Docker/supervisord.conf b/install/OS_specific/Docker/supervisord.conf deleted file mode 100644 index 6afa7d2d2..000000000 --- a/install/OS_specific/Docker/supervisord.conf +++ /dev/null @@ -1,26 +0,0 @@ -[supervisord] -nodaemon=true -user=root - -[program:cron] -command = /usr/sbin/cron -f -user = root -autostart = true -startretries= 2 -stdout_logfile = /var/log/supervisor/%(program_name)s.log -stderr_logfile = /var/log/supervisor/%(program_name)s.log - -[program:apache2] -command = /usr/sbin/apache2ctl -DFOREGROUND -autorestart = false - -[program:atd] -command = /usr/sbin/atd -stdout_logfile = /var/log/supervisor/%(program_name)s.log -stderr_logfile = /var/log/supervisor/%(program_name)s.log -autostart = true -startretries = 2 - -#[program:sshd] -#command=/usr/sbin/sshd -D -#autorestart=true \ No newline at end of file diff --git a/install/OS_specific/windows/pre_inst.sh b/install/OS_specific/windows/pre_inst.sh old mode 100755 new mode 100644 diff --git a/install/apache/nextdom-common b/install/apache/nextdom-common old mode 100755 new mode 100644 diff --git a/install/apache/nextdom-ssl.conf b/install/apache/nextdom-ssl.conf old mode 100755 new mode 100644 diff --git a/install/apache/nextdom.conf b/install/apache/nextdom.conf old mode 100755 new mode 100644 diff --git a/install/scripts/fix_apache_private_tmp.sh b/install/fix_apache_private_tmp.sh similarity index 100% rename from install/scripts/fix_apache_private_tmp.sh rename to install/fix_apache_private_tmp.sh diff --git a/install/install_docker.sh b/install/install_docker.sh deleted file mode 100755 index 4e88e1e1a..000000000 --- a/install/install_docker.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -#set -e - -################################################################################################# -################################## NextDom Installation from docker ############################# -################################################################################################# - -# docker variables are given at run time not build time. - -#https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -#remove running parts -sed -i 's/preinstall_nextdom$//g' ${CURRENT_DIR}/scripts/preinst.sh -sed -i 's/exit 0$//g' ${CURRENT_DIR}/scripts/preinst.sh -#not known at build time -sed -i 's/PHP_DIRECTORY=/#PHP_DIRECTORY=/g' ${CURRENT_DIR}//scripts/config.sh - -source ${CURRENT_DIR}/scripts/config.sh -source ${CURRENT_DIR}/scripts/utils.sh -source ${CURRENT_DIR}/preinst.sh - -#build a script for docker build time -#at build time, unwanted steps are commented -#needed to generate assets -savePRODUCTION=${PRODUCTION} -PRODUCTION=false -step0_prepare_prerequisites -addLogScript "============ Starting preinst.sh ============" -step1_generate_nextdom_assets -#step2_configure_mysql -step3_prepare_var_www_html -step4_configure_apache -#step5_configure_mysql_database -#step6_generate_mysql_structure -#restore wanted status (prod or dev php ini config) -PRODUCTION=${savePRODUCTION} -step7_configure_php - -addLogScript "============ End preinst.sh ============" - -sed -i 's/postinstall_nextdom$//g' ${CURRENT_DIR}/postinst.sh -sed -i 's/exit 0$//g' ${CURRENT_DIR}/postinst.sh -source ${CURRENT_DIR}/postinst.sh - -addLogScript "============ Starting postinst.sh ============" -#commented step are the one needed at runtime not build time -step1_create_prerequisite_files_and_directories -step2_prepare_directory_layout -step5_create_symLink_var_www_html -step6_configure_apache -step7_configure_crontab -step9_specific_action_for_OS -step10_configure_file_permissions -step11_change_owner_for_nextdom_directories -addLogScript "============ End postinst.sh ============" - -#add supervisor -apt install -y supervisor -mkdir -p /var/log/supervisor/ -cp ${CURRENT_DIR}/../supervisord.conf /etc/supervisor/conf.d/supervisord.conf \ No newline at end of file diff --git a/install/install_git.sh b/install/install_git.sh deleted file mode 100755 index aba912d69..000000000 --- a/install/install_git.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -e - -################################################################################################# -################################### NextDom Installation from git ############################### -################################################################################################# - -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -cd ${CURRENT_DIR}/../ -export ROOT_DIRECTORY=${PWD} -bash ${CURRENT_DIR}/scripts/preinst.sh -bash ${CURRENT_DIR}/scripts/postinst.sh - - - diff --git a/install/install_git_dev.sh b/install/install_git_dev.sh deleted file mode 100755 index 7cd540cbb..000000000 --- a/install/install_git_dev.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -e - -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -################################################################################################# -################################### NextDom Installation from git ############################### -################################################################################################# - -sed -i "s|PRODUCTION=true|PRODUCTION=false|g" ${CURRENT_DIR}/scripts/config.sh -cd ${CURRENT_DIR}/../ -export ROOT_DIRECTORY=${PWD} -bash ${CURRENT_DIR}/scripts/preinst.sh -bash ${CURRENT_DIR}/scripts/postinst.sh - - diff --git a/install/postinst b/install/postinst old mode 100755 new mode 100644 index ccaa82684..73e692040 --- a/install/postinst +++ b/install/postinst @@ -1,17 +1,787 @@ #!/usr/bin/env bash set -e -################################################################################################# -################################### NextDom Installation from deb ############################### -################################### Script to remove in the futur ############################### -################################### .deb package should call ############################### -################################### # scripts/postinst.sh instead ############################### -################################################################################################# +# Parameters +DEBUG="/tmp/output.txt" +declare -a DETAILS -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -cd ${CURRENT_DIR}/../ -export ROOT_DIRECTORY=${PWD} -bash ${CURRENT_DIR}/scripts/postinst.sh +ENV_TYPE="prod" +# Functions +usage() { + cat - >&2 < : database hostname, defaults to localhost + -z : database port, defaults to 3306 + -d : database name, defaults to nextdom (nextdomdev for dev version) + -u : database user name, defaults to nextdom (nextdomdev for dev version) + -p : database user password, randomly generated if not given + -r : database root password + -L : set log directory, defaults to /var/log/nextdom + -l : set lib directory, defaults to /var/lib/nextdom + -t : set tmp directory, defaults to /tmp/nextdom + -v : enable verbose output +EOS + exit 1; +} + + +# Get current directory +set_root() { + local this=`readlink -n -f $1` + local bin=`dirname $this` + root=`dirname $bin` +} + + +print_log_in() { + txt=$1 + if [ 1 -eq "0${isdev}" ] ; then + format="%- 50s" + if [ ${VERBOSE} -eq 1 ]; then + format="%s" + fi + printf "${format}" "${txt}" + fi + printf ${txt} >> ${LOG_DIRECTORY}/postinst.log +} + +print_log_ok() { + NORMAL="\\033[0;39m" + GREEN="\\033[1;92m" + + if [ 1 -eq "0${isdev}" ] ; then + echo -e " ${GREEN}Success${NORMAL}" + if [ "${#DETAILS[@]}" -ne 0 ]; then + for c_line in "${DETAILS[@]}"; do + echo " -> ${c_line}" + done + fi + fi + echo " Success" >> ${LOG_DIRECTORY}/postinst.log + if [ "${#DETAILS[@]}" -ne 0 ]; then + for c_line in "${DETAILS[@]}"; do + echo " -> ${c_line}" >> ${LOG_DIRECTORY}/postinst.log + done + DETAILS=() + fi +} + +print_verbose() { + if [ ${VERBOSE} -eq 1 ]; then + DETAILS+=("$@") + fi +} + +print_error() { + NORMAL="\\033[0;39m" + ROUGE="\\033[1;31m" + + if [ 1 -eq "0${isdev}" ] ; then + echo -e " ${ROUGE}Failure${NORMAL}" + echo -e " -> error: $@" + fi + echo -e " Failure" >> ${LOG_DIRECTORY}/postinst.log + echo -e " -> error: $@" >> ${LOG_DIRECTORY}/postinst.log + exit 1 +} + +detect_dev_version() { + isdev=0 + WEBSERVER_HOME=/usr/share/nextdom + + # detect if there is a .git directory (development version) + if [ -d ${root}/.git ] ; then + isdev=1 + WEBSERVER_HOME=${root} + fi +} + +prereq_create_dirs() { + # directories + mkdir -p ${LOG_DIRECTORY}/scenarioLog + + mkdir -p ${LIB_DIRECTORY} + mkdir -p ${LIB_DIRECTORY}/{market_cache,cache,backup} + mkdir -p ${LIB_DIRECTORY}/custom/desktop + mkdir -p ${LIB_DIRECTORY}/public/css + mkdir -p ${LIB_DIRECTORY}/public/img/plan + mkdir -p ${LIB_DIRECTORY}/public/img/profils + mkdir -p ${LIB_DIRECTORY}/public/img/market_cache + + mkdir -p ${root}/plugins + + rm -f ${LOG_DIRECTORY}/postinst.ok + rm -f ${LOG_DIRECTORY}/postinst.warn + rm -f ${LOG_DIRECTORY}/postinst.log + + touch ${LOG_DIRECTORY}/postinst.log + touch ${LOG_DIRECTORY}/cron + touch ${LOG_DIRECTORY}/cron_execution + touch ${LOG_DIRECTORY}/event + touch ${LOG_DIRECTORY}/http.error + touch ${LOG_DIRECTORY}/plugin + touch ${LOG_DIRECTORY}/scenario_execution +} + +step_nexdom_environement() { + php_ini_path=$(php --ini | head -n 1 | sed -E "s/.*Path: (.*)\/cli/\\1/") + if [ -e ${WEBSERVER_HOME}/assets/config/default.config.ini ]; then + rm ${WEBSERVER_HOME}/assets/config/default.config.ini + fi + if [ -e ${php_ini_path}/apache2/conf.d/10-opcache.ini ]; then + rm ${php_ini_path}/apache2/conf.d/10-opcache.ini + fi + + if [ ${ENV_TYPE} = "dev" ]; then + cp -f ${WEBSERVER_HOME}/assets/config/dist/default.config.ini.dev ${WEBSERVER_HOME}/assets/config/default.config.ini + print_verbose "disable PHP opcache" + cp -f ${WEBSERVER_HOME}/assets/config/dist/opcache.ini.dev ${php_ini_path}/apache2/conf.d/10-opcache.ini + else + cp -f ${WEBSERVER_HOME}/assets/config/dist/default.config.ini.dist ${WEBSERVER_HOME}/assets/config/default.config.ini + print_verbose "enable PHP opcache" + cp -f ${WEBSERVER_HOME}/assets/config/dist/opcache.ini.dist ${php_ini_path}/apache2/conf.d/10-opcache.ini + fi + print_verbose "restart Apache" + service apache2 restart +} + +step_nextdom_file_permissions() { + # configure file permissions + # ${WEBSERVER_HOME}/plugins and ${WEBSERVER_HOME}/public/img should not be given + # www-data ownership, still needed until proper migration handling + local directories=("${LIB_DIRECTORY}" "${LOG_DIRECTORY}" "${TMP_DIRECTORY}" "${WEBSERVER_HOME}/plugins" "${WEBSERVER_HOME}/public/img") + for c_dir in ${directories[*]}; do + chown -R www-data:www-data ${c_dir} + find ${c_dir} -type d -exec chmod 0755 {} \; + find ${c_dir} -type f -exec chmod 0644 {} \; + print_verbose "set file owner: www-data, perms: 0755/0644 on directory ${c_dir}" + done +} + + +step_nextdom_mysql_parameters() { + if [ 1 -eq "0${isdev}" ] ; then + # Development version + [[ -z "${MYSQL_NEXTDOM_DB}" ]] && MYSQL_NEXTDOM_DB="nextdomdev" + [[ -z "${MYSQL_NEXTDOM_USER}" ]] && MYSQL_NEXTDOM_USER="nextdomdev" + else + # Debian package configuration... + # nextdom-mysql preconfiguration + if [[ -f /etc/nextdom/mysql/secret ]] ; then + source /etc/nextdom/mysql/secret + fi + [[ -z "${MYSQL_NEXTDOM_DB}" ]] && MYSQL_NEXTDOM_DB="nextdom" + [[ -z "${MYSQL_NEXTDOM_USER}" ]] && MYSQL_NEXTDOM_USER="nextdom" + fi + + # All parameters + HOSTPASS="" + if [ -n "${MYSQL_ROOT_PASSWD}" ]; then + HOSTPASS="${HOSTPASS} -p${MYSQL_ROOT_PASSWD}" + fi + if [ -n "${MYSQL_HOSTNAME}" ]; then + HOSTPASS="${HOSTPASS} -h${MYSQL_HOSTNAME}" + fi + if [ -n "${MYSQL_PORT}" ]; then + HOSTPASS="${HOSTPASS} --port=${MYSQL_PORT}" + fi + + MYSQL_NEXTDOM_PASSWD=${MYSQL_NEXTDOM_PASSWD:-$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 15)} + MYSQL_HOSTNAME=${MYSQL_HOSTNAME:-localhost} + MYSQL_PORT=${MYSQL_PORT:-3306} + MYSQL_NEXTDOM_DB=${MYSQL_NEXTDOM_DB:nextdom} + + + print_verbose "install directory: ${WEBSERVER_HOME}" + print_verbose "database host: ${MYSQL_HOSTNAME}" + print_verbose "database port: ${MYSQL_PORT}" + print_verbose "database name: ${MYSQL_NEXTDOM_DB}" + print_verbose "database user: ${MYSQL_NEXTDOM_USER}" + print_verbose "database passwd: ${MYSQL_NEXTDOM_PASSWD}" + + # slow start of docker mysql + try=0 + while [ ${try} -lt 5 ]; do + mysql -uroot ${HOSTPASS} -e "SHOW DATABASES;" >/dev/null 2>&1 || { + try=$((try + 1)) + sleep 5 + continue + } + return 0 + done + + print_error "can't connect to mysql database" +} + + +step_nextdom_prerequisites_verification() { + # These prerequistes are instaled by nextdom-common or nextdom-minimal package, + # but this part is for other distribution compatibility + + # Create apache configuration if missing + local dstdir="/etc/apache2/sites-available" + local srcdir="${WEBSERVER_HOME}/install/apache/" + local wwwdir="${WEBSERVER_HOME}" + + if [[ ! -d "${dstdir}" ]] ; then + print_error "apache2 not installed" + fi + + # check that WEBSERVER_HOME is readable by www-data + sudo -u www-data test -r "${wwwdir}" || { + wwwdir="/var/www/html/" + print_verbose "${wwwdir} not readable by www-data" + print_verbose "enabled compatibility mode, DocumentRoot targets /var/www/html" + } + + for c_file in nextdom.conf nextdom-ssl.conf nextdom-common; do + if [ ! -f ${dstdir}/${c_file} ] || [ 1 -eq "0${isdev}" ] ; then + cp ${srcdir}/${c_file} ${dstdir}/${c_file} >> ${DEBUG} 2>&1 + sed -i -r "s%\s+Define\s+wwwdir\s.*%Define wwwdir \"${wwwdir}\"%gI" ${dstdir}/${c_file} >> ${DEBUG} 2>&1 + sed -i -r "s%\s+Define\s+logdir\s.*%Define logdir \"${LOG_DIRECTORY}\"%gI" ${dstdir}/${c_file} >> ${DEBUG} 2>&1 + print_verbose "created file: ${dstdir}/${c_file}" + fi + done + + # Configure private tmp + if [[ ! -f "/etc/systemd/system/apache2.service.d/privatetmp.conf" ]] ; then + mkdir -p /etc/systemd/system/apache2.service.d + cp ${srcdir}/privatetmp.conf /etc/systemd/system/apache2.service.d/privatetmp.conf >> ${DEBUG} 2>&1 + print_verbose "created file: /etc/systemd/system/apache2.service.d/privatetmp.conf" + fi + + # Windows hack (bash for windows) + if [[ ! $(uname -r | grep -i microsoft) = "" ]] ; then + bash ${WEBSERVER_HOME}/install/OS_specific/windows/pre_inst.sh >> ${DEBUG} 2>&1 + fi + + # Certificat SSL auto signe + if [[ ! -f /etc/nextdom/ssl/nextdom.crt ]] || [[ ! -f /etc/nextdom/ssl/nextdom.csr ]] || [[ ! -f /etc/nextdom/ssl/nextdom.key ]] ; then + mkdir -p /etc/nextdom/ssl/ >> ${DEBUG} 2>&1 + cd /etc/nextdom/ssl/ >> ${DEBUG} 2>&1 + openssl genrsa -out nextdom.key 2048 >> ${DEBUG} 2>&1 + openssl req -new -key nextdom.key -out nextdom.csr -subj "/C=FR/ST=Paris/L=Paris/O=Global Security/OU=IT Department/CN=example.com" >> ${DEBUG} 2>&1 + openssl x509 -req -days 3650 -in nextdom.csr -signkey nextdom.key -out nextdom.crt >> ${DEBUG} 2>&1 + print_verbose "created SSL self-signed certificates in /etc/nextdom/ssl/" + fi +} + + +step_nextdom_apache_php() { + a2enmod ssl >> ${DEBUG} 2>&1 + a2enmod rewrite >> ${DEBUG} 2>&1 + a2dismod status >> ${DEBUG} 2>&1 + a2dissite 000-default >> ${DEBUG} 2>&1 + a2dissite default-ssl >> ${DEBUG} 2>&1 + a2ensite nextdom-ssl >> ${DEBUG} 2>&1 + a2ensite nextdom >> ${DEBUG} 2>&1 + print_verbose "apache: disabled site default" + print_verbose "apache: disabled site default-ssl" + print_verbose "apache: enabled site nextdom" + print_verbose "apache: enabled site nextdom-ssl" + + service apache2 restart >> ${DEBUG} 2>&1 || { + service apache2 restart >> ${DEBUG} 2>&1 || { + print_error "unable to restart apache2" + } + } +} + +step_nextdom_directory_layout() { + # we delete existing config since it is regenerated from asset sample (step_nextdom_configuration) + rm -rf ${LIB_DIRECTORY}/config + cp -r ${WEBSERVER_HOME}/assets/config ${LIB_DIRECTORY} + print_verbose "created configuration directory ${LIB_DIRECTORY}/config" + + # we delete existing data, since its re-imported from assets + rm -rf ${LIB_DIRECTORY}/data + cp -r ${WEBSERVER_HOME}/assets/data ${LIB_DIRECTORY} + print_verbose "created data directory ${LIB_DIRECTORY}/data" + + # jeedom backup compatibility: ./core/config is a symlink + if [ -L ${WEBSERVER_HOME}/core/config ]; then + rm -f ${WEBSERVER_HOME}/core/config + fi + ln -s ${LIB_DIRECTORY}/config ${WEBSERVER_HOME}/core/config + print_verbose "created core configuration symlink: ${WEBSERVER_HOME}/core/config" + + # jeedom backup compatibility: ./var is a symlink + if [ -L ${WEBSERVER_HOME}/var ]; then + rm -f ${WEBSERVER_HOME}/var + fi + if [ -d ${WEBSERVER_HOME}/var ]; then + content=$(ls -A ${WEBSERVER_HOME}/var) + if [ ! -z "${content}" ]; then + tmpvar=$(mktemp -d ${WEBSERVER_HOME}/var.XXXXXXXX) + mv ${WEBSERVER_HOME}/var/* ${tmpvar}/ + fi + rm -rf ${WEBSERVER_HOME}/var + fi + ln -s ${LIB_DIRECTORY} ${WEBSERVER_HOME}/var + print_verbose "created var symlink: ${WEBSERVER_HOME}/var" + + # jeedom backup compatibility: ./core/css is a symlink + # -> some important plugins like widget are writing direclty to core/css/... + # and there fore need www-data write permission + if [ -L ${WEBSERVER_HOME}/core/css ]; then + rm -f ${WEBSERVER_HOME}/core/css + fi + if [ -d ${WEBSERVER_HOME}/core/css ]; then + mv ${WEBSERVER_HOME}/core/css/* ${LIB_DIRECTORY}/public/css/ + rm -rf ${WEBSERVER_HOME}/core/css + fi + ln -s ${LIB_DIRECTORY}/public/css/ ${WEBSERVER_HOME}/core/css + print_verbose "created core/css symlink: ${WEBSERVER_HOME}/core/css" + + # jeedom javascript compatibility + if [ ! -e ${WEBSERVER_HOME}/core/js ]; then + ln -s ${WEBSERVER_HOME}/assets/js/core/ ${WEBSERVER_HOME}/core/js + fi + print_verbose "created core/js symlink: ${WEBSERVER_HOME}/assets/js/core" + + # jeedom template location compatibility + if [ ! -e ${WEBSERVER_HOME}/core/template ]; then + ln -s ${WEBSERVER_HOME}/views/templates/ ${WEBSERVER_HOME}/core/template + fi + print_verbose "created core/template symlink: ${WEBSERVER_HOME}/core/template" + + # jeedom backup compatibility: ./data is a symlink + if [ -L ${WEBSERVER_HOME}/data ]; then + rm -f ${WEBSERVER_HOME}/data + fi + if [ -d ${WEBSERVER_HOME}/data ]; then + content=$(ls -A ${WEBSERVER_HOME}/data) + if [ ! -z "${content}" ]; then + tmpvar=$(mktemp -d ${WEBSERVER_HOME}/data.XXXXXXXX) + mv ${WEBSERVER_HOME}/data/* ${tmpvar}/ + fi + rm -rf ${WEBSERVER_HOME}/data + fi + if [ -f ${WEBSERVER_HOME}/data ]; then + rm -f ${WEBSERVER_HOME}/data + fi + if [ ! -e ${WEBSERVER_HOME}/data ]; then + ln -s ${LIB_DIRECTORY}/data ${WEBSERVER_HOME}/data + fi + print_verbose "created data symlink: ${WEBSERVER_HOME}/data" + # + # jeedom logs compatibility + if [ ! -f ${WEBSERVER_HOME}/log ]; then + rm -f ${WEBSERVER_HOME}/log + fi + if [ ! -e ${WEBSERVER_HOME}/log ]; then + ln -s ${LOG_DIRECTORY} ${WEBSERVER_HOME}/log + fi + #clear cache + sh ${WEBSERVER_HOME}/scripts/clear_cache.sh + print_verbose "cache cleared" +} + +step_nextdom_configuration() { + # recreate configuration from sample + cp ${WEBSERVER_HOME}/core/config/common.config.sample.php ${WEBSERVER_HOME}/core/config/common.config.php + SECRET_KEY=$(> ${DEBUG} 2>&1 + fi + ln -s ${TMP_DIRECTORY} /tmp/jeedom + else + if [[ -d "${TMP_DIRECTORY}" ]]; then + mv /tmp/jeedom/* ${TMP_DIRECTORY}/ + else + mv /tmp/jeedom ${TMP_DIRECTORY} + ln -s ${TMP_DIRECTORY} /tmp/jeedom + fi + fi + else + if [[ ! -d "${TMP_DIRECTORY}" ]]; then + mkdir -p ${TMP_DIRECTORY} + fi + rm -f /tmp/jeedom + ln -s ${TMP_DIRECTORY} /tmp/jeedom + fi + print_verbose "created temporary directory: ${TMP_DIRECTORY}" + + # allow www-data to use usb/serial ports + usermod -a -G dialout,tty www-data + + # set tmp directory as ramfs mount point if enough memory is available + if [[ -f "/proc/meminfo" ]] ; then + if [ $(cat /proc/meminfo | grep MemTotal | awk '{ print $2 }') -gt 600000 ]; then + if [[ -f "/etc/fstab" ]] ; then + if [ $(cat /etc/fstab | grep ${TMP_DIRECTORY} | grep tmpfs | wc -l) -eq 0 ];then + cat - >> /etc/fstab </dev/null + if [ $? -ne 0 ]; then + print_error "unable to add www-data to sudoers" + fi + fi + print_verbose "added user as sudoer: www-data" +} + + +step_nextdom_mysql_configuration() { + # check that mysql is locally installed before any further configuration + # default value for mysql_host is localhost + [[ "localhost" != "$HOSTNAME" ]] && { + print_log_ok "Remote mysql server detected" + return 0 + } + + service mysql status 2>&1 >>${DEBUG} + isService=$? + if [ ! -f /etc/init.d/mysql -o ${isService} -gt 0 ]; then + print_log_ok "no mysql service locally" + return 0 + fi + + service mysql stop >> ${DEBUG} 2>&1 || { + service mysql stop >> ${DEBUG} 2>&1 || { + print_error "unable to stop mysql" + } + } + + rm -f /var/lib/mysql/ib_logfile* + + if [ -d /etc/mysql/conf.d ]; then + cat - > /etc/mysql/conf.d/nextdom_my.cnf <> ${DEBUG} 2>&1 || { + service mysql start >> ${DEBUG} 2>&1 || { + print_error "unable to restart mysql" + } + } +} + +step_nextdom_crontab() { + cat - > /etc/cron.d/nextdom << EOS +* * * * * www-data /usr/bin/php ${WEBSERVER_HOME}/src/Api/start_cron.php >> /dev/null +EOS + print_verbose "created nextdom cron configuration: /etc/cron.d/nextdom" + + cat - > /etc/cron.d/nextdom_watchdog << EOS +*/5 * * * * root /usr/bin/php ${WEBSERVER_HOME}/scripts/watchdog.php >> /dev/null +EOS + print_verbose "created nextdom cron configuration: /etc/cron.d/nextdom_watchdog" + + service cron reload >> ${DEBUG} 2>&1 +} + +step_nextdom_assets() { + # Generate CSS files + if [ 1 -eq "0${isdev}" ]; then + # A faire dans une version developpeur (apres git clone) + cd ${WEBSERVER_HOME} + ./scripts/gen_global.sh >> ${DEBUG} 2>&1 || { + print_error "error during asset generation" + } + print_verbose "installed nodejs" + print_verbose "installed composer manager" + print_verbose "installed project dependencies" + print_verbose "copied icons, themes and images from assets" + print_verbose "generated css files" + print_verbose "generated javascript files" + fi +} + +step_nextdom_check() { + php ${WEBSERVER_HOME}/scripts/sick.php >> ${DEBUG} 2>&1 +} + +step_os_specific(){ + if [ -f /etc/armbian.txt ]; then + cat ${WEBSERVER_HOME}/install/OS_specific/armbian/post-install.sh | bash >> ${DEBUG} 2>&1 + fi + + if [ -f /usr/bin/raspi-config ]; then + cat ${WEBSERVER_HOME}/install/OS_specific/rpi/post-install.sh | bash >> ${DEBUG} 2>&1 + fi +} + + +step_nextdom_var_www_html() { + # Link ${WEBSERVER_HOME} to /var/www/html. Required by old plugins that may hardcode this path. + # Any previously installed content are moved to temporairy directories in check_var_www_html() + # (useless for docker since this directory is empty) + + dirn="/var/www/html" + if [ "${WEBSERVER_HOME}" == "${dirn}" ] ; then + return 0 + fi + + # moving any content of /var/www/html to /var/www/html.XXXXXXXX + if [[ -d "${dirn}" ]] ; then + count="$( find ${dirn} -mindepth 1 -maxdepth 1 | wc -l )" + if [ $count -gt 0 ] ; then + tmpd="$(mktemp -d -u /var/www/html.XXXXXXXX)" + mv ${dirn} ${tmpd} + print_verbose "warning : directory ${dirn} isn't empty, renamed to ${tmpd}" + fi + fi + + # rename any pre-exiting link + if [[ -L "${dirn}" ]] ; then + dest=$(readlink "${dirn}") + if [ "${dest}" == "${WEBSERVER_HOME}" ]; then + rm -f "${dirn}" + else + tfile="$(mktemp -u /var/www/html.XXXXXXXX)" + cd /var/www/ + mv ${dirn} ${tfile} + print_verbose "warning : directory ${dirn} is a link, renamed it ${tfile}" + fi + fi + + # strange but why not + if [[ -f "${dirn}" ]] ; then + tfile=$(mktemp -u /var/www/html.XXXXXXXX) + mv ${dirn} ${tfile} + print_verbose "warning : ${dirn} is a file, renamed it ${tfile}" + fi + + # link /var/www/html to nextdom root + ln -s "${WEBSERVER_HOME}" /var/www/html +} + +step_restore_owner() { + chown -R www-data:www-data ${WEBSERVER_HOME} + if [ -d "/tmp/nextdom" ]; then + chown -R www-data:www-data /tmp/nextdom + fi +} + +step_nextdom_mysql_populate() { + CONSTRAINT="%"; + if [ ${MYSQL_HOSTNAME} == "localhost" ]; then + CONSTRAINT='localhost'; + fi + + QUERY="DROP USER IF EXISTS '${MYSQL_NEXTDOM_USER}'@'${CONSTRAINT}';" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + print_verbose "deleted mysql user: ${MYSQL_NEXTDOM_USER}" + + QUERY="CREATE USER '${MYSQL_NEXTDOM_USER}'@'${CONSTRAINT}' IDENTIFIED BY '${MYSQL_NEXTDOM_PASSWD}';" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + print_verbose "created mysql user: ${MYSQL_NEXTDOM_USER}" + + QUERY="DROP DATABASE IF EXISTS ${MYSQL_NEXTDOM_DB};" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + print_verbose "deleted mysql table: ${MYSQL_NEXTDOM_DB}" + + QUERY="CREATE DATABASE ${MYSQL_NEXTDOM_DB};" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + print_verbose "created mysql table: ${MYSQL_NEXTDOM_DB}" + + QUERY="GRANT ALL PRIVILEGES ON ${MYSQL_NEXTDOM_DB}.* TO '${MYSQL_NEXTDOM_USER}'@'${CONSTRAINT}';" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + QUERY="FLUSH PRIVILEGES;" + mysql -uroot -h${MYSQL_HOSTNAME} ${HOSTPASS} -e "${QUERY}" >> ${DEBUG} 2>&1 + print_verbose "configured table privileges: ${MYSQL_NEXTDOM_DB}" + + php ${WEBSERVER_HOME}/install/install.php mode=force >> ${DEBUG} 2>&1 || { + print_error "NextDom installation script failed" + } + print_verbose "ran installation procedure: ${WEBSERVER_HOME}/install/install.php" +} + + +# ====================================================================== +# Main + +main() { + LIB_DIRECTORY=/var/lib/nextdom + LOG_DIRECTORY=/var/log/nextdom + TMP_DIRECTORY=/tmp/nextdom + VERBOSE=0 + + while getopts "vhi:p:d:r:u:z:L:l:t:D" option; do + case "${option}" in + h) + usage + ;; + D) + ENV_TYPE="dev" + ;; + v) + VERBOSE=1 + ;; + i) + MYSQL_HOSTNAME=${OPTARG} + ;; + z) + MYSQL_PORT=${OPTARG} + ;; + d) + MYSQL_NEXTDOM_DB=${OPTARG} + ;; + u) + MYSQL_NEXTDOM_USER=${OPTARG} + ;; + p) + MYSQL_NEXTDOM_PASSWD=${OPTARG} + ;; + r) + MYSQL_ROOT_PASSWD=${OPTARG} + ;; + L) + LOG_DIRECTORY=${OPTARG} + ;; + l) + LIB_DIRECTORY=${OPTARG} + ;; + t) + TMP_DIRECTORY=${OPTARG} + ;; + *) + usage + ;; + esac + done + shift $((OPTIND-1)) + + if [ $(id -u) != 0 ] ; then + echo "Les droits de super-utilisateur (root) sont requis pour installer NextDom" + echo "Veuillez lancer sudo $0 ou connectez-vous en tant que root, puis relancez $0" + exit 1 + fi + + # Start all services + service apache2 start + service cron start + service mysql start + + set_root $0 + detect_dev_version + prereq_create_dirs + + print_log_in "step_nextdom_directory_layout ... " + step_nextdom_directory_layout + print_log_ok + + print_log_in "step_nextdom_assets ... " + step_nextdom_assets + print_log_ok + + print_log_in "step_nextdom_mysql_parameters ... " + step_nextdom_mysql_parameters + print_log_ok + + print_log_in "step_nextdom_var_www_html ... " + step_nextdom_var_www_html + print_log_ok + + print_log_in "step_nextdom_prerequisites_verification ... " + step_nextdom_prerequisites_verification + print_log_ok + + print_log_in "step_nextdom_apache_php ... " + step_nextdom_apache_php + print_log_ok + + print_log_in "step_nextdom_configuration ... " + step_nextdom_configuration + print_log_ok + + print_log_in "step_nextdom_mysql_configuration ... " + step_nextdom_mysql_configuration + print_log_ok + + print_log_in "step_nextdom_mysql_populate ... " + step_nextdom_mysql_populate + print_log_ok + + print_log_in "step_nextdom_crontab ... " + step_nextdom_crontab + print_log_ok + + print_log_in "step_nextdom_check ... " + step_nextdom_check + print_log_ok + + print_log_in "step_os_specific ... " + step_os_specific + print_log_ok + + print_log_in "step_nextdom_permissions ..." + step_nextdom_file_permissions + print_log_ok + + print_log_in "step_restore_owner ..." + step_restore_owner + print_log_ok + + print_log_in "step_nextdom_copy_config.ini ... " + step_nexdom_environement + print_log_ok + + [[ -f /root/.mysqlroot ]] && rm -f /root/.mysqlroot + + if [ -f .git ] ; then + cat - < A self-signed SSL Certificate created in /etc/nextdom/ssl/ + > Please feel free to use another Certificate + + >>>>> COMPLETED <<<<< +EOS + fi +} + +main $@ diff --git a/install/restore.php b/install/restore.php old mode 100755 new mode 100644 diff --git a/install/scripts/config.sh b/install/scripts/config.sh deleted file mode 100644 index e2bd66380..000000000 --- a/install/scripts/config.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -set -e -################################################################################################# -############################################ Global variables ################################### -################################################################################################# - -# false for dev -PRODUCTION=${PRODUCTION:-true} - -# For log output -BLUE="\\033[1;34m" -GREEN="\\033[1;92m" -GREY="\\033[1;30m" -NORMAL="\\033[0;39m" -RED="\\033[1;31m" -CURRENT_DATE=$(date "+%D %r") - -# root UID -ROOT_UID=0 - -# Apache path -APACHE_CONFIG_DIRECTORY="/etc/apache2/sites-available" -APACHE_HTML_DIRECTORY="/var/www/html" -APACHE_SYSTEMD_DIRECTORY="/etc/systemd/system/apache2.service.d" - - -### NextDom path -CONFIG_DIRECTORY="/etc/nextdom" -LIB_DIRECTORY="/var/lib/nextdom" -LOG_DIRECTORY="/var/log/nextdom" -LOG_FILE="install.log" -ROOT_DIRECTORY=${ROOT_DIRECTORY:-"/usr/share/nextdom"} -TMP_DIRECTORY="/tmp/nextdom" - -### MySQL/MariaDB configuration - -MYSQL_HOSTNAME=${MYSQL_HOSTNAME:-"localhost"} -MYSQL_PORT=${MYSQL_PORT:-"3306"} -MYSQL_SUBNET="192.168.1.%" -MYSQL_ROOT_PASSWD="" -MYSQL_NEXTDOM_DB=${MYSQL_NEXTDOM_DB:-"nextdom"} -MYSQL_NEXTDOM_USER=${MYSQL_NEXTDOM_USER:-"nextdom"} -MYSQL_NEXTDOM_PASSWD='#MYSQL_NEXTDOM_PASSWD#' \ No newline at end of file diff --git a/install/scripts/debian-update.sh b/install/scripts/debian-update.sh deleted file mode 100755 index cce9b81ab..000000000 --- a/install/scripts/debian-update.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -apt update -apt install -y nextdom diff --git a/install/scripts/postinst.sh b/install/scripts/postinst.sh deleted file mode 100755 index 812b4bc7a..000000000 --- a/install/scripts/postinst.sh +++ /dev/null @@ -1,560 +0,0 @@ -#!/usr/bin/env bash -set -e - -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -source ${CURRENT_DIR}/utils.sh - -################################################################################################# -########################################### NextDom Steps ####################################### -################################################################################################# - -step0_prepare_prerequisites() { - # Start all services - startService apache2 - addLogInfo "Apache2 service started" - startService cron - addLogInfo "Cron service started" - if [ "localhost" == "${MYSQL_HOSTNAME}" ] || [ "$(hostname -I)" == "${MYSQL_HOSTNAME}" ]; then - addLogInfo "Local mysql server detected" - startService mysql - addLogInfo "MySQL/MariaDB service started" - fi -} - -step1_create_prerequisite_files_and_directories() { - result=true - addLogStep "Postinst -- Create needed files and directories - 1/11" - - local directories=("${ROOT_DIRECTORY}/plugins" "${LIB_DIRECTORY}" "${LIB_DIRECTORY}/market_cache" - "${LIB_DIRECTORY}/cache" "${LIB_DIRECTORY}/backup" "${LIB_DIRECTORY}/core/config" "${LIB_DIRECTORY}/custom/desktop" "${LIB_DIRECTORY}/public/css" - "${LIB_DIRECTORY}/public/img/plan" "${LIB_DIRECTORY}/public/img/profils" "${LIB_DIRECTORY}/public/img/market_cache" - "${LOG_DIRECTORY}/scenarioLog") - - for c_dir in ${directories[*]}; do - createDirectory ${c_dir} - done - - removeDirectoryOrFile "${LOG_DIRECTORY}/${LOG_FILE}" - - local files=("${LOG_DIRECTORY}/${LOG_FILE}" "${LOG_DIRECTORY}/cron" "${LOG_DIRECTORY}/cron_execution" - "${LOG_DIRECTORY}/event" "${LOG_DIRECTORY}/http.error" "${LOG_DIRECTORY}/plugin" "${LOG_DIRECTORY}/scenario_execution") - - for c_file in ${files[*]}; do - createFile ${c_file} - done - - { ##try - # some other compatibilty ugly stuff - if [ -d "/tmp/jeedom" ]; then - if [ -L "/tmp/jeedom" ]; then - removeDirectoryOrFile /tmp/jeedom - if [ ! -d "${TMP_DIRECTORY}" ]; then - mkdir -p ${TMP_DIRECTORY} - fi - ln -s ${TMP_DIRECTORY} /tmp/jeedom - else - if [ -d "${TMP_DIRECTORY}" ]; then - mv /tmp/jeedom/* ${TMP_DIRECTORY}/ - else - mv /tmp/jeedom ${TMP_DIRECTORY} - ln -s ${TMP_DIRECTORY} /tmp/jeedom - fi - fi - else - if [ ! -d "${TMP_DIRECTORY}" ]; then - mkdir -p ${TMP_DIRECTORY} - fi - removeDirectoryOrFile /tmp/jeedom - ln -s ${TMP_DIRECTORY} /tmp/jeedom - fi - addLogInfo "created temporary directory: ${TMP_DIRECTORY}" - } || { ##catch - addLogError "Error while creating tmp folders/links" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "Files and directories are created with success" - fi -} - -step2_prepare_directory_layout() { - result=true - - addLogStep "Postinst -- Prepare directory layout - 2/11" - - # we delete existing config since it is regenerated from asset sample (step_nextdom_configuration) - removeDirectoryOrFile ${LIB_DIRECTORY}/config - cp -r ${ROOT_DIRECTORY}/assets/config ${LIB_DIRECTORY} - addLogInfo "created configuration directory ${LIB_DIRECTORY}/config" - - # we delete existing data, since its re-imported from assets - removeDirectoryOrFile ${LIB_DIRECTORY}/data - cp -r ${ROOT_DIRECTORY}/assets/data ${LIB_DIRECTORY} - addLogInfo "created data directory ${LIB_DIRECTORY}/data" - - # jeedom backup compatibility: ./core/config is a symlink - if [ -L ${ROOT_DIRECTORY}/core/config ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/core/config - fi - { ##try - ln -s ${LIB_DIRECTORY}/config ${ROOT_DIRECTORY}/core/config - addLogInfo "created core configuration symlink: ${ROOT_DIRECTORY}/core/config" - } || { ##catch - addLogInfo "core/config symlink: ${ROOT_DIRECTORY}/core/config already exists" - } - - # jeedom backup compatibility: ./var is a symlink - if [ -L ${ROOT_DIRECTORY}/var ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/var - fi - if [ -d ${ROOT_DIRECTORY}/var ]; then - content=$(ls -A ${ROOT_DIRECTORY}/var) - if [ ! -z "${content}" ]; then - tmpvar=$(mktemp -d ${ROOT_DIRECTORY}/var.XXXXXXXX) - mv ${ROOT_DIRECTORY}/var/* ${tmpvar}/ - fi - removeDirectoryOrFile ${ROOT_DIRECTORY}/var - fi - { ##try - ln -s ${LIB_DIRECTORY} ${ROOT_DIRECTORY}/var - addLogInfo "created var symlink: ${ROOT_DIRECTORY}/var" - } || { ##catch - addLogInfo "var symlink: ${ROOT_DIRECTORY}/var already exists" - } - - # jeedom backup compatibility: ./core/css is a symlink - # -> some important plugins like widget are writing direclty to core/css/... - # and there fore need www-data write permission - if [ -L ${ROOT_DIRECTORY}/core/css ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/core/css - fi - if [ -d ${ROOT_DIRECTORY}/core/css ]; then - mv ${ROOT_DIRECTORY}/core/css/* ${LIB_DIRECTORY}/public/css/ - removeDirectoryOrFile ${ROOT_DIRECTORY}/core/css - fi - { ##try - ln -s ${LIB_DIRECTORY}/public/css/ ${ROOT_DIRECTORY}/core/css - addLogInfo "created core/css symlink: ${ROOT_DIRECTORY}/core/css" - } || { ##catch - addLogInfo "core/css symlink: ${ROOT_DIRECTORY}/core/css already exists" - } - - # jeedom javascript compatibility - if [ ! -e ${ROOT_DIRECTORY}/core/js ]; then - { ##try - ln -s ${ROOT_DIRECTORY}/assets/js/core/ ${ROOT_DIRECTORY}/core/js - addLogInfo "created core/js symlink: ${ROOT_DIRECTORY}/assets/core/js" - } || { ##catch - addLogInfo "assets/core/js symlink: ${ROOT_DIRECTORY}/assets/core/js already exists" - } - fi - - # jeedom template location compatibility - if [ ! -e ${ROOT_DIRECTORY}/core/template ]; then - { ##try - ln -s ${ROOT_DIRECTORY}/views/templates/ ${ROOT_DIRECTORY}/core/template - addLogInfo "created core/template symlink: ${ROOT_DIRECTORY}/core/template" - } || { ##catch - addLogInfo "core/template symlink: ${ROOT_DIRECTORY}/core/template already exists" - } - fi - - # jeedom backup compatibility: ./data is a symlink - if [ -L ${ROOT_DIRECTORY}/data ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/data - fi - if [ -d ${ROOT_DIRECTORY}/data ]; then - content=$(ls -A ${ROOT_DIRECTORY}/data) - if [ ! -z "${content}" ]; then - tmpvar=$(mktemp -d ${ROOT_DIRECTORY}/data.XXXXXXXX) - mv ${ROOT_DIRECTORY}/data/* ${tmpvar}/ - fi - removeDirectoryOrFile ${ROOT_DIRECTORY}/data - fi - { ##try - if [ -f ${ROOT_DIRECTORY}/data ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/data - fi - if [ ! -e ${ROOT_DIRECTORY}/data ]; then - { ##try - ln -s ${LIB_DIRECTORY}/data ${ROOT_DIRECTORY}/data - addLogInfo "created data symlink: ${ROOT_DIRECTORY}/data" - } || { ##catch - addLogInfo "data symlink: ${ROOT_DIRECTORY}/data already exists" - } - fi - } || { ##catch - addLogError "Error while linking ${ROOT_DIRECTORY}/data" - } - { ##try - # jeedom logs compatibility - if [ ! -f ${ROOT_DIRECTORY}/log ]; then - removeDirectoryOrFile ${ROOT_DIRECTORY}/log - fi - if [ ! -e ${ROOT_DIRECTORY}/log ]; then - { ##try - ln -s ${LOG_DIRECTORY} ${ROOT_DIRECTORY}/log - addLogInfo "created log symlink: ${ROOT_DIRECTORY}/log" - } || { ##catch - addLogInfo "log symlink: ${ROOT_DIRECTORY}/log already exists" - } - fi - } || { ##catch - addLogError "Error while linking ${LOG_DIRECTORY}" - } - { ##try - #clear cache - sh ${ROOT_DIRECTORY}/scripts/clear_cache.sh - addLogInfo "cache cleared" - } || { ##catch - addLogError "Error while clearing cache" - } - if [ "true" == "${result}" ]; then - addLogSuccess "NextDom is configured with success" - fi -} - -step3_create_symLink_var_www_html() { - # Link ${ROOT_DIRECTORY} to /var/www/html. Required by old plugins that may hardcode this path. - # Any previously installed content are moved to temporairy directories in check_var_www_html() - # link /var/www/html to nextdom root - result=true - - addLogStep "Postinst -- Configure symbolic links - 4/11" - if [ "${ROOT_DIRECTORY}" != "${APACHE_HTML_DIRECTORY}" ]; then - { ##try - ln -s "${ROOT_DIRECTORY}" ${APACHE_HTML_DIRECTORY} - } || { ##catch - addLogError "Error while linking ${ROOT_DIRECTORY} to ${APACHE_HTML_DIRECTORY}" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "${ROOT_DIRECTORY} linked with success to ${APACHE_HTML_DIRECTORY}" - fi - else - addLogSuccess "${ROOT_DIRECTORY} don't need to be linked to ${APACHE_HTML_DIRECTORY}" - fi -} - -step4_configure_apache() { - result=true - - addLogStep "Postinst -- Configure Apache - 5/11" - - # check that APACHE_HTML_DIRECTORY is readable by www-data - { ##try - sudo -u www-data test -r "${APACHE_HTML_DIRECTORY}" - } || { - addLogError "${APACHE_HTML_DIRECTORY} is not readable by www-data user \n enabled compatibility mode, DocumentRoot targets /var/www/html" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "Apache is configured with success" - fi -} - -step5_configure_nextdom() { - result=true - - addLogStep "Postinst -- Configure NextDom - 6/11" - - { ##try - # recreate configuration from sample - cp ${ROOT_DIRECTORY}/core/config/common.config.sample.php ${ROOT_DIRECTORY}/core/config/common.config.php - } || { ##catch - addLogError "Error while copying ${ROOT_DIRECTORY}/core/config/common.config.php" - } - { ##try - SECRET_KEY=$( - tr >/etc/fstab </dev/null - if [ $? -ne 0 ]; then - print_error "unable to add www-data to sudoers" - fi - fi - addLogInfo "added user as sudoer: www-data" - } || { ##catch - addLogError "Error while adding www-data as sudoer" - } - if [ "true" == "${result}" ]; then - addLogSuccess "NextDom is configured with success" - fi -} - -step6_restart_mysql_database() { - result=true - addLogStep "Postinst -- Restart MySQL/MariaDB - 7/11" - - if [ "localhost" != "${MYSQL_HOSTNAME}" ] && [ "$(hostname)" != "${MYSQL_HOSTNAME}" ] && [ "$(hostname -I)" != "${MYSQL_HOSTNAME}" ]; then - addLogInfo "Remote mysql server detected" - return 0 - fi - { ##try - restartService mysql - } || { ##catch - addLogError "MySQL/MariaDB is not running" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "MySQL/MariaDB is configured with success" - fi -} - -step7_configure_crontab() { - result=true - - addLogStep "Postinst -- Configure Cron - 8/11" - - { ##try - cat - >/etc/cron.d/nextdom <> /dev/null -EOS - addLogInfo "created nextdom cron configuration: /etc/cron.d/nextdom" - } || { ##catch - addLogError "Error while creating /etc/cron.d/nextdom" - } - { - cat - >/etc/cron.d/nextdom_watchdog <> /dev/null -EOS - addLogInfo "created nextdom cron configuration: /etc/cron.d/nextdom_watchdog" - } || { ##catch - addLogError "Error while creating /etc/cron.d/nextdom_watchdog" - } - - reloadService cron - - if [ "true" == "${result}" ]; then - addLogSuccess "Cron is configured with success" - fi -} - -step8_check_nextdom() { - result=true - - addLogStep "Postinst -- Check NextDom - 9/11" - - { ##try - php ${APACHE_HTML_DIRECTORY}/scripts/sick.php - } || { ##catch - addLogError "Error while checking nextdom" - } - if [ "true" == "${result}" ]; then - addLogSuccess "Check is done with success" - fi -} - -step9_specific_action_for_OS() { - result=true - - addLogStep "Postinst -- Execute scripts for specific OS- 10/11" - - { ##try - if [ -f /etc/armbian.txt ]; then - cat ${ROOT_DIRECTORY}/install/OS_specific/armbian/post-install.sh | bash - fi - } || { ##catch - addLogError "Error while specific action for armbian" - } - - { ##try - if [ -f /usr/bin/raspi-config ]; then - cat ${ROOT_DIRECTORY}/install/OS_specific/rpi/post-install.sh | bash - fi - } || { ##catch - addLogError "Error while specific action for raspberry pi" - } - - { ##try - # Windows hack (bash for windows) - if [ ! $(uname -r | grep -i microsoft) = "" ]; then - bash ${WEBSERVER_HOME}/install/OS_specific/windows/pre_inst.sh - fi - } || { ##catch - addLogError "Error while specific action for microsoft windows" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "OS specific actions are done with success" - fi -} - -step10_configure_file_permissions() { - # configure file permissions - # ${ROOT_DIRECTORY}/plugins and ${ROOT_DIRECTORY}/public/img should not be given - # www-data ownership, still needed until proper migration handling - result=true - - addLogStep "Postinst -- Configure file permission - 11/11" - - { ##try - local directories=("${LIB_DIRECTORY}" "${LOG_DIRECTORY}" "${TMP_DIRECTORY}" "${ROOT_DIRECTORY}/plugins" "${ROOT_DIRECTORY}/public/img") - for c_dir in ${directories[*]}; do - if [ -d ${c_dir} ]; then - chown -Rf www-data:www-data ${c_dir} - find ${c_dir} -type d -exec chmod 0755 {} \; - find ${c_dir} -type f -exec chmod 0644 {} \; - addLogInfo "set file owner: www-data, perms: 0755/0644 on directory ${c_dir}" - fi - done - } || { ##catch - addLogError "Error while checking file permission" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "Files permissions are configured with success" - fi -} - -step11_change_owner_for_nextdom_directories() { - result=true - - addLogStep "Postinst -- Configure owner for NextDom directory - 12/11" - - { ##try - local directories=("${ROOT_DIRECTORY}" "${LIB_DIRECTORY}" "${LOG_DIRECTORY}" "${TMP_DIRECTORY}") - for c_dir in ${directories[*]}; do - { ##try - if [ -d "${c_dir}" ]; then - chown -Rf www-data:www-data "${c_dir}" - fi - } || { ##catch - addLogError "Error while changing owner on ${c_dir}" - } - done - } || { ##catch - addLogError "Error while changing owner" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "${ROOT_DIRECTORY}, ${LIB_DIRECTORY}, ${LOG_DIRECTORY} and ${TMP_DIRECTORY} folder's owner is changed with success" - fi -} - -################################################################################################# -############################################# Installation ###################################### -################################################################################################# - -postinstall_nextdom() { - - if [ $(id -u) != 0 ]; then - addLogError "Les droits de super-utilisateur (root) sont requis pour installer NextDom - Veuillez lancer sudo $0 ou connectez-vous en tant que root, puis relancez $0" - exit 1 - fi - - addLogScript "============ Starting postinst.sh ============" - - - step0_prepare_prerequisites - step1_create_prerequisite_files_and_directories - step2_prepare_directory_layout - step3_create_symLink_var_www_html - step4_configure_apache - step5_configure_nextdom - step6_restart_mysql_database - step7_configure_crontab - step8_check_nextdom - step9_specific_action_for_OS - step10_configure_file_permissions - step11_change_owner_for_nextdom_directories - - if [ -f /root/.mysqlroot ]; then - rm -f /root/.mysqlroot - fi - - if [ "${PRODUCTION}" != "true" ]; then - cat - < A self-signed SSL Certificate created in /etc/nextdom/ssl/ - > Please feel free to use another Certificate - - >>>>> COMPLETED <<<<< -EOS - fi - - addLogScript "============ Postinst.sh is executed ... ============" - -} - -postinstall_nextdom - -exit 0 \ No newline at end of file diff --git a/install/scripts/preinst.sh b/install/scripts/preinst.sh deleted file mode 100644 index bd66f03df..000000000 --- a/install/scripts/preinst.sh +++ /dev/null @@ -1,495 +0,0 @@ -#!/usr/bin/env bash -set -e - -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -source ${CURRENT_DIR}/utils.sh - -################################################################################################# -########################################### NextDom Steps ####################################### -################################################################################################# - -step0_prepare_prerequisites() { - - result=true - - # IMPORTANT : keep ${LOG_DIRECTORY} created first ! the info log is done once it's created - { ##try - mkdir -p ${LOG_DIRECTORY} - } || { ##catch - echo -e "${RED}${CURRENT_DATE} ERROR : Unable to create ${LOG_DIRECTORY} ${NORMAL}" - return 0 - } - - addLogStep "Preinst -- Prepare and check prerequisites - 0/7" - - for dir in ${CONFIG_DIRECTORY} ${LIB_DIRECTORY} ${ROOT_DIRECTORY} ${TMP_DIRECTORY} - do - createDirectory ${dir} - done - addLogInfo "Local needed directories checked" - - if [ "localhost" == "${MYSQL_HOSTNAME}" ] || [ "$(hostname -I)" == "${MYSQL_HOSTNAME}" ]; then - addLogInfo "Local mysql server detected" - startService mysql - addLogInfo "MySQL/MariaDB service started" - checkMySQLIsRunning - fi - { ##try - unset command_not_found_handle - php --ini | head -n 1 | sed -E "s/.*Path: (.*)\/cli/\\1/" - - if [ "$?" -eq 127 ]; then - addLogError "PHP is not installed" - return 0 - fi - addLogInfo "PHP detected" - startService apache2 - addLogInfo "Apache2 service started" - startService cron - addLogInfo "Cron service started" - set command_not_found_handle - } || { - addLogError "PHP is not installed" - } - - if [ "true" == "${result}" ]; then - addLogSuccess "Prerequisites are checked with success" - fi -} - -step1_generate_nextdom_assets() { - - result=true - - addLogStep "Preinst -- Generate Assets - 1/7" - # Generate CSS files - # A faire dans une version developpeur (apres git clone) - if [ ! -f ${ROOT_DIRECTORY}/vendor ]; then - { ##try - cd ${ROOT_DIRECTORY} - ./scripts/gen_composer_npm.sh - } || { ##catch - addLogError "error during composer and npm initialize" - } - fi - { ##try - cd ${ROOT_DIRECTORY} - ./scripts/gen_global.sh - } || { ##catch - addLogError "error during asset generation" - } - addLogInfo "installed nodejs" - addLogInfo "installed composer manager" - addLogInfo "installed project dependencies" - addLogInfo "copied icons, themes and images from assets" - addLogInfo "generated css files" - addLogInfo "generated javascript files" - if [ "true" == "${result}" ]; then - addLogSuccess "Assets are generated with success" - fi -} - -step2_configure_mysql() { - # check that mysql is locally installed before any further configuration - # default value for mysql_host is localhost - result=true - - addLogStep "Preinst -- Configure MySQL/MariaDB - 2/7" - - if [ "localhost" != "${MYSQL_HOSTNAME}" ] && [ "$(hostname)" != "${MYSQL_HOSTNAME}" ] && [ "$(hostname -I)" != "${MYSQL_HOSTNAME}" ]; then - addLogInfo "Remote mysql server detected" - return 0 - fi - - { ##try - mysqlStatus=$(pgrep mysql | wc -l) - if [ "${mysqlStatus}" -eq 0 ]; then - addLogInfo "no mysql service locally" - return 0 - fi - } || { ##catch - addLogError "Error while checking mysql status" - } - - stopService mysql - - { ##try - rm -f /var/lib/mysql/ib_logfile* - } || { ##catch - addLogError "Error while cleaning mysql data" - } - - { ##try - if [ -d /etc/mysql/conf.d ]; then - cat - >/etc/mysql/conf.d/nextdom_my.cnf </dev/null 2>&1 && pwd)" - -source ${CURRENT_DIR}/config.sh - -################################################################################################# -############################################ Usual functions #################################### -################################################################################################# - -####################################### Directory/File management ############################### - -checkIfDirectoryExists() { - [ -d $1 ] -} - -createFile() { - local fileToCreate=$1 - { ##try - if [ ! -f ${fileToCreate} ]; then - touch ${fileToCreate} - addLogInfo "File : ${fileToCreate} created" - fi - } || { ##catch - addLogError "Error while creating : ${fileToCreate}" - } -} - -createDirectory() { - local directoryToCreate=$1 - { ##try - if [ ! -e ${directoryToCreate} ]; then - mkdir -p ${directoryToCreate} - addLogInfo "Directory : ${directoryToCreate} created" - fi - } || { ##catch - addLogError "Error while creating : ${directoryToCreate}" - } -} - -goToDirectory() { - local directory=$1 - { ##try - if [ -d ${directory} ]; then - cd ${directory} >/dev/null - pushd ${directory} >/dev/null - fi - } || { ##catch - addLogError "Error while going : ${directory}" - } -} - -removeDirectoryOrFile() { - local directoryToRemove=$1 - { ##try - if [ -d "${directoryToRemove}" ]; then - rm -Rf "${directoryToRemove}" - fi - addLogInfo "Directory or file : ${directoryToRemove} removed" - } || { ##catch - addLogError "Error while removing : ${directoryToRemove}" - } -} -############################################ Log management ##################################### - -addLogError() { - local error=$1 - { - echo -e "${RED}${CURRENT_DATE} ERROR : ${error}${NORMAL}" | tee -a ${LOG_DIRECTORY}/${LOG_FILE} - } - result=false -} - -addLogInfo() { - local info=$1 - { - echo -e "${CURRENT_DATE} INFO : ${info}" | tee -a ${LOG_DIRECTORY}/${LOG_FILE} - } -} - -addLogSuccess() { - local info=$1 - { - echo -e "${GREEN}${CURRENT_DATE} SUCCESS : ${info}${NORMAL}" | tee -a ${LOG_DIRECTORY}/${LOG_FILE} - } -} - -addLogStep() { - local info=$1 - { - echo -e "${BLUE}${CURRENT_DATE} STEP : ${info}${NORMAL}" | tee -a ${LOG_DIRECTORY}/${LOG_FILE} - } -} - -addLogScript() { - local info=$1 - { - echo -e "${GREY}${CURRENT_DATE} SCRIPT : ${info}${NORMAL}" | tee -a ${LOG_DIRECTORY}/${LOG_FILE} - } -} -########################################### Rights management ################################### - -checkCurrentUser() { - if [ "${UID}" -ne "${ROOT_UID}" ]; then - addLogError "You are not authorized to run this script … Permission Denied !!!" - ##exit ${ERROR_INVALID_USER} - fi -} - -########################################## Services management ################################## - -# slow start of docker service -checkMySQLIsRunning() { - local MYSQL_OPTIONS=$1 - local try=0 - - while [ ${try} -lt 5 ]; do - { ##try - mysql -uroot ${MYSQL_OPTIONS} -e "SHOW DATABASES;" >/dev/null 2>&1 - } || { ##catch - try=$((try + 1)) - sleep 5 - continue - } - return 0 - done - addLogError "Can't connect to database" - ##exit ${ERROR_INVALID_DATABASE_CONNECTION} -} - -setNextdomPasswordForMySQL() { - MYSQL_NEXTDOM_PASSWD="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 15)" - { ##try - if [ ! -d ${CONFIG_DIRECTORY}/mysql ]; then - createDirectory ${CONFIG_DIRECTORY}/mysql/ - fi - cat - >${CONFIG_DIRECTORY}/mysql/secret < ' . NEXTDOM_LOG . '/update &'); + exec(SystemHelper::getCmdSudo() . 'apt update > /dev/null 2>&1'); + exec(SystemHelper::getCmdSudo() . 'apt-get install -y nextdom'); } /**