From 769f39a3b270bf1224ae58d83b2dd59f603f921c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 14 Apr 2018 22:02:50 +0200 Subject: [PATCH] basic installation and removal rewrote --- check_process | 38 ++++++++++ conf/app.src | 6 ++ conf/config.ini | 126 +++++++++++++++++++++++++++++++ conf/kresus.service | 17 ----- conf/nginx.conf | 4 +- conf/systemd.service | 22 ++++++ manifest.json | 9 ++- scripts/_common.sh | 166 ++++++++++++++++++++++++++++++++++++++++ scripts/install | 176 ++++++++++++++++++++++++++++++++++--------- scripts/remove | 65 ++++++++++++---- scripts/upgrade | 51 ++++++++----- 11 files changed, 591 insertions(+), 89 deletions(-) create mode 100644 check_process create mode 100644 conf/app.src create mode 100644 conf/config.ini delete mode 100644 conf/kresus.service create mode 100644 conf/systemd.service create mode 100644 scripts/_common.sh diff --git a/check_process b/check_process new file mode 100644 index 0000000..280a215 --- /dev/null +++ b/check_process @@ -0,0 +1,38 @@ +# See here for more informations +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=0 + upgrade=1 + backup_restore=0 + multi_instance=1 + incorrect_path=1 + port_already_use=0 + change_url=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto +# Level 4: https://github.com/YunoHost-Apps/weblate_ynh/issues/4 + Level 4=1 +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email=jean-baptiste@holcroft.fr +Notification=all diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..6c70c70 --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://framagit.org/bnjbvr/kresus/repository/0.13.1/archive.tar.bz2 +SOURCE_SUM=0fc6679e564f151b6671aa4768a863f3acb10cf7b4ed116ab6b7d22a9e53e76a +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= diff --git a/conf/config.ini b/conf/config.ini new file mode 100644 index 0000000..41166bf --- /dev/null +++ b/conf/config.ini @@ -0,0 +1,126 @@ +; Hi there! This is the configuration file for Kresus. Please make sure to +; read all the options before setting up Kresus for the first time. +[kresus] + +; This is where Kresus stores additional data, as the latest bank scrapping +; modules. It should be writeable by the user which launches the Kresus +; executable. +; Can be removed; defaults to HOME_DIR/.kresus. +; Overridden by the KRESUS_DIR environment variable, if it's set. +; Example: +; dataDir=/home/ben/.kresus +datadir=__FINALPATH__/data/ + +; The host on which the Kresus server will listen to. +; Can be removed; defaults to "127.0.0.1". +; Overridden by the HOST environment variable, if it's set. +host=127.0.0.1 + +; This is the port that Kresus will run on. It is recommended not to +; expose it on port 80 directly but to use a reverse-proxy configuration +; like Nginx, Caddy or Apache. +; Can be removed; defaults to 9876. +; Overridden by the PORT environment variable, if it's set. +port=__PORT__ + +; The directory prefix in the URL, if Kresus is to be served from a +; subdirectory. For instance, if your website is hosted at example.com and +; the url prefix is "money", then Kresus will be reachable at +; example.com/money. +; Can be removed; defaults to "", i.e. Kresus has its own (sub)domain. +; Overridden by the KRESUS_URL_PREFIX environment variable, if it's set. +; Example: +; url_prefix=/money +url_prefix=__PATH__ + +; The executable version of Python that is going to get used when interacting +; with Python scripts. This can be python, python2 or python3. +; Can be removed; defaults to "python2". +; Overridden by the KRESUS_PYTHON_EXEC environment variable, if it's set. +; Example: +; python_exec=python3 +python_exec= + +[weboob] +; The directory in which Weboob core is stored. +; Can be removed; defaults to "", indicating that weboob is already in the +; PYTHON_PATH (e.g. installed at the global level). +; Overridden by the KRESUS_WEBOOB_DIR environment variable, if it's set. +; Example: +; srcdir=/home/ben/code/weboob +srcdir= + +; Path to a file containing a valid Weboob's source list directory. +; Can be removed; defaults to "", indicating that Kresus will generate its own +; source list file and will store it in ${datadir}/weboob-data/sources.list. +; Overridden by the KRESUS_WEBOOB_SOURCES_LIST environment variable, if it's +; set. +; Example: +; sources_list/home/ben/code/weboob/sources.list +sources_list= + +[email] +; The transport method you want to use. Can be either: +; * "sendmail": relies on sendmail executable to be available on your system +; and only sendmail-specific parameters are used, +; * "smtp": you should provide proper SMTP credentials to use, in the dedicated +; configuration entries. +; +; Can be removed; defaults to "", which means no emails will be sent. +; Overridden by the KRESUS_EMAIL_TRANSPORT environment variable, if it's set. +transport= + +; The path to the sendmail executable to use. +; Can be removed; defaults to "", which means defaults to "sendmail" +; executable. +; Overridden by the KRESUS_EMAIL_SENDMAIL_BIN environment variable, if it's +; set. +sendmail_bin= + +; The email address from which email alerts will be sent. Make sure that +; your domain DNS is correctly configured and that you've done what's +; needed to prevent email alerts from landing in the spam folder. +; Can be removed; defaults to "", which means no email will be sent. +; Overridden by the KRESUS_EMAIL_FROM environment variable, if it's set. +from= + +; The network address (ipv4, ipv6 or FQDN) of the SMTP server. +; Can be removed; defaults to "", which means no email will be sent. +; Overridden by the KRESUS_EMAIL_HOST environment variable, if it's set. +host= + +; The port to which the SMTP server listens. Default values tend to be +; 25 (server to server), or 587 (clients to server), or 465 (nonstandard). +; Can be removed; defaults to "", which means no email will be sent. +; Overridden by the KRESUS_EMAIL_PORT environment variable, if it's set. +port= + +; The username used during authentication to the SMTP server. +; Can be removed; defaults to "", which means an anonymous connection. +; Overridden by the KRESUS_EMAIL_USER environment variable, if it's set. +user= + +; The password used during authentication to the SMTP server. +; Can be removed; defaults to "", which means no password. +; Overridden by the KRESUS_EMAIL_PASSWORD environment variable, if it's set. +password= + +; If set to true, will force using a TLS connection. By default, emails +; are sent with STARTTLS, i.e. using TLS if available. +; Can be removed; defaults to false. +; Overridden by the KRESUS_EMAIL_FORCE_TLS environment variable, if it's set. +force_tls=false + +; If set to false, will allow self-signed TLS certificates. +; Can be removed; defaults to true. +; Overridden by the KRESUS_EMAIL_REJECT_UNAUTHORIZED_TLS environment +; variable, if it's set. +reject_unauthorized_tls=true + +[logs] +; The path to the log file to use. +; Can be removed; defaults to kresus.log in kresus' datadir. +; Overridden by the KRESUS_LOG_FILE environment variable, if it's set. +; Logs will still be written to stdout. +log_file= + diff --git a/conf/kresus.service b/conf/kresus.service deleted file mode 100644 index 0a92034..0000000 --- a/conf/kresus.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Kresus -After=syslog.target network.target - -[Service] -WorkingDirectory=YNH_HOME -Environment=NODE_ENV=production HOME=YNH_HOME -ExecStart=YNH_HOME/node_modules/kresus/bin/kresus.js -Type=simple -Restart=always - -StandardOutput=journal -StandardError=inherit -SyslogIdentifier=kresus - -[Install] -WantedBy=multi-user.target diff --git a/conf/nginx.conf b/conf/nginx.conf index 7df73b0..521a8f2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ -location YNH_WWW_PATH/ { - proxy_pass http://127.0.0.1:9876/; +location __PATH__ { + proxy_pass http://127.0.0.1:__PORT__; proxy_set_header Host $host; proxy_redirect off; diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..3a10453 --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,22 @@ +[Unit] +Description=__APP__ +After=syslog.target network.target + +[Service] +Type=simple +User=__APP__ +Group=__APP__ +ExecStartPre=__NODEJS__ +WorkingDirectory=__FINALPATH__ +Environment="PATH=__ENV_PATH__" +Environment=NODE_ENV=production +Environment=HOME=__NODEPATH__ +ExecStart=__FINALPATH__/bin/kresus.js --config __FINALPATH__/config.ini +Restart=always + +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=__APP__ + +[Install] +WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index 84bb464..b499dcf 100644 --- a/manifest.json +++ b/manifest.json @@ -7,14 +7,15 @@ "fr": "Kresus est un outil personnel de gestion de finances." }, "url": "https://framagit.org/bnjbvr/kresus", - "license": "free", + "license": "AGPL-3.0-only", "maintainer": { "name": "Scith", "url": "https://github.com/scith" }, "requirements": { - "yunohost": ">= 2.6.4" + "yunohost": ">= 2.7.10" }, + "version": "0.13.1-1", "multi_instance": true, "services": [ "nginx" @@ -23,7 +24,7 @@ "install" : [ { "name": "domain", - "type": "domain", + "type": "domain", "ask": { "en": "Choose a domain name for Kresus", "fr": "Choisissez un nom de domaine pour Kresus" @@ -32,7 +33,7 @@ }, { "name": "path", - "type": "path", + "type": "path", "ask": { "en": "Choose a path for Kresus", "fr": "Choisissez un chemin pour Kresus" diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..c7e475c --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,166 @@ +#!/bin/bash + +# INFOS +# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser. +# C'est ainsi qu'il change de version +# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n +# ynh_use_nodejs active une version de nodejs dans le script courant +# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app +# - nodejs_path: Le chemin absolu de cette version de node +# Utilisé pour des appels directs à node. +# - nodejs_version: Simplement le numéro de version de nodejs pour cette application +# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant. +# Utilisé pour démarrer un service ou un script qui utilise node ou npm +# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire. + +n_install_dir="/opt/node_n" +node_version_path="/opt/node_n/n/versions/node" +# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n. +export N_PREFIX="$n_install_dir" + +ynh_install_n () { + echo "Installation of N - Node.js version management" >&2 + # Build an app.src for n + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz +SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src" + # Download and extract n + ynh_setup_source "$n_install_dir/git" n + # Install n + (cd "$n_install_dir/git" + PREFIX=$N_PREFIX make install 2>&1) +} + +ynh_use_nodejs () { + nodejs_version=$(ynh_app_setting_get $app nodejs_version) + + load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir"" + + nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" + + # "Load" a version of node + eval $load_n_path; $nodejs_use_version + + # Get the absolute path of this version of node + nodejs_path="$(n bin $nodejs_version)" + + # Make an alias for node use + ynh_node_exec="eval $load_n_path; n use $nodejs_version" +} + +ynh_install_nodejs () { + # Use n, https://github.com/tj/n to manage the nodejs versions + nodejs_version="$1" + local n_install_script="https://git.io/n-install" + + # Create $n_install_dir + mkdir -p "$n_install_dir" + + # Load n path in PATH + CLEAR_PATH="$n_install_dir/bin:$PATH" + # Remove /usr/local/bin in PATH in case of node has already setup. + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing node binary, to avoid to block n. + test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n + test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n + + # If n is not previously setup, install it + if ! test n --version > /dev/null 2>&1 + then + ynh_install_n + fi + + # Modify the default N_PREFIX in n script + ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n" + + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH + + # And replace the old node binary. + test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node + test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm + + # Install the requested version of nodejs + n $nodejs_version + + # Find the last "real" version for this major version of node. + real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) + real_nodejs_version=$(basename $real_nodejs_version) + + # Create a symbolic link for this major version. If the file doesn't already exist + if [ ! -e "$node_version_path/$nodejs_version" ] + then + ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version + fi + + # Store the ID of this app and the version of node requested for it + echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version" + + # Store nodejs_version into the config of this app + ynh_app_setting_set $app nodejs_version $nodejs_version + + # Build the update script and set the cronjob + ynh_cron_upgrade_node + + ynh_use_nodejs +} + +ynh_remove_nodejs () { + ynh_use_nodejs + + # Remove the line for this app + sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version" + + # If none another app uses this version of nodejs, remove it. + if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version" + then + n rm $nodejs_version + fi + + # If none another app uses n, remove n + if [ ! -s "$n_install_dir/ynh_app_version" ] + then + ynh_secure_remove "$n_install_dir" + ynh_secure_remove "/usr/local/n" + sed --in-place "/N_PREFIX/d" /root/.bashrc + fi +} + +ynh_cron_upgrade_node () { + # Build the update script + cat > "$n_install_dir/node_update.sh" << EOF +#!/bin/bash +version_path="$node_version_path" +n_install_dir="$n_install_dir" +# Log the date +date +# List all real installed version of node +all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")" +# Keep only the major version number of each line +all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//') +# Remove double entries +all_real_version=\$(echo "\$all_real_version" | sort --unique) +# Read each major version +while read version +do + echo "Update of the version \$version" + sudo \$n_install_dir/bin/n \$version + # Find the last "real" version for this major version of node. + real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1) + real_nodejs_version=\$(basename \$real_nodejs_version) + # Update the symbolic link for this version + sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version +done <<< "\$(echo "\$all_real_version")" +EOF + + chmod +x "$n_install_dir/node_update.sh" + + # Build the cronjob + cat > "/etc/cron.daily/node_update" << EOF +#!/bin/bash +$n_install_dir/node_update.sh >> $n_install_dir/node_update.log +EOF + + chmod +x "/etc/cron.daily/node_update" +} diff --git a/scripts/install b/scripts/install index 51b1374..bfd6f0d 100644 --- a/scripts/install +++ b/scripts/install @@ -1,50 +1,158 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -app=$YNH_APP_INSTANCE_NAME +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================ # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path_url=$YNH_APP_ARG_PATH +port=$(ynh_find_port 9876) -# Compute parameters -install_path="/home/ynh$app" +app=$YNH_APP_INSTANCE_NAME -# Source YunoHost helpers -source /usr/share/yunohost/helpers +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= -# Check domain/path availability -yunohost app checkurl "${domain}${path}" -a "$app" \ -|| ynh_die "Path not available: ${domain}${path}" +final_path="/var/www/$app" +test ! -e "$final_path" || ynh_die "This path already contains a folder" -# Check system user availability -if ynh_system_user_exists "$app" ; then - ynh_die "System user $app already exists !" -else - ynh_system_user_create "$app" "$install_path" -fi +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path "$path_url") -# Install dependencies -apt-get update -apt-get install nodejs-legacy npm python-pip python-dev python-lxml python-imaging -y -qq +# Check web path availability +ynh_webpath_available "$domain" "$path_url" +# Register (book) web path +ynh_webpath_register "$app" "$domain" "$path_url" + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" path "$path_url" +ynh_app_setting_set "$app" port "$port" + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +ynh_install_app_dependencies python-pip python-dev python-lxml python-imaging python-virtualenv + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# TODO: this app should be installable from a specific version +ynh_app_setting_set "$app" final_path "$final_path" + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" +mkdir "$final_path/data" + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create "$app" + +#================================================= +# SPECIFIC SETUP +#================================================= +# Install nodesjs +#================================================= + +# install nodejs +ynh_install_nodejs 8 + +#================================================= +# Install weboob with pip +#================================================= + +# TODO: use virtualenv +# virtualenv "${final_path}/venv" +# ( +# set +o nounset +# source "${final_path}/venv/bin/activate" +# set -o nounset + +# pip install --upgrade pip + +# ) pip install weboob -# Install Kresus -sudo -u $app sh -c 'cd $final_path && prefix=$final_path npm install kresus' +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= -# Modify Nginx configuration file and copy it to Nginx conf directory -nginx_conf=../conf/nginx.conf -sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +# Set permissions to app files +# chown -R $app: $final_path -# Setup service -systemd_service=../conf/kresus.service -sed -i "s@YNH_HOME@$install_path@g" $systemd_service -sudo cp $systemd_service /etc/systemd/system/$app.service -systemctl enable $app -systemctl start $app +#================================================= +# Install Kresus with npm +#================================================= -# Reload services -sudo service nginx reload +ynh_use_nodejs +( + cd "$final_path" + chown -R $app: "$final_path" + npm install --unsafe-perm + npm run build:prod +) + +#================================================= +# CONFIGURE HASTE +#================================================= + +cp ../conf/config.ini "$final_path/config.ini" + +ynh_replace_string "__PORT__" "$port" "$final_path/config.ini" +ynh_replace_string "__PATH__" "$path_url" "$final_path/config.ini" +ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/config.ini" + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/config.ini" + +#================================================= +# SETUP SYSTEMD +#================================================= + +ynh_replace_string "__NODEJS__" "$nodejs_use_version" ../conf/systemd.service +ynh_replace_string "__ENV_PATH__" "$PATH" ../conf/systemd.service +ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" ../conf/systemd.service + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# RELOAD NGINX +#================================================= + +service nginx reload diff --git a/scripts/remove b/scripts/remove index 2a21211..c4cb8dd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,23 +1,60 @@ #!/bin/bash -set -u +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= app=$YNH_APP_INSTANCE_NAME -# Source YunoHost helpers -source /usr/share/yunohost/helpers - -# Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) +port=$(ynh_app_setting_get "$app" port) +final_path=$(ynh_app_setting_get "$app" final_path) -# Remove sources -systemctl stop $app -systemctl disable $app -ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf -ynh_secure_remove /etc/systemd/system/$app.service +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= -# Reload nginx service -sudo service nginx reload +# Remove the dedicated systemd config +ynh_remove_systemd_config -# Remove dedicated system user -ynh_system_user_delete $app +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +ynh_remove_nodejs + +#================================================= +# REMOVE APP MAIN DIR +#================================================= + +# Remove the app directory securely +ynh_secure_remove "$final_path" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete "$app" diff --git a/scripts/upgrade b/scripts/upgrade index 1c5bc97..3e8f3c0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,22 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +# TODO: handle "/home/ynh$app" to final_path migration app=$YNH_APP_INSTANCE_NAME @@ -9,27 +24,27 @@ app=$YNH_APP_INSTANCE_NAME source /usr/share/yunohost/helpers # Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +# domain=$(ynh_app_setting_get "$app" domain) +# path=$(ynh_app_setting_get "$app" path) # Build the app -src_path=/home/yunohost.app/$app -sudo mkdir -p $src_path $src_path/node_modules -sudo git clone https://framagit.org/bnjbvr/kresus.git $src_path -sudo npm install --prefix $src_path $src_path -sudo .$src_path/scripts/build.sh +# src_path=/home/yunohost.app/$app +# mkdir -p $src_path $src_path/node_modules +# git clone https://framagit.org/bnjbvr/kresus.git $src_path +# npm install --prefix $src_path $src_path +# .$src_path/scripts/build.sh # Modify Nginx configuration file and copy it to Nginx conf directory -nginx_conf=../conf/nginx.conf -sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf -sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf +# nginx_conf=../conf/nginx.conf +# sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf +# cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf # Setup service -systemd_service=../conf/kresus.service -sed -i "s@APP_TO_CHANGE@$app@g" $systemd_service -sudo cp $systemd_service /etc/systemd/system/$app.service -systemctl enable $app -systemctl start $app +# systemd_service=../conf/kresus.service +# sed -i "s@APP_TO_CHANGE@$app@g" $systemd_service +# cp $systemd_service /etc/systemd/system/$app.service +# systemctl enable $app +# systemctl start $app # Reload nginx service -sudo service nginx reload +service nginx reload