From b5391bbfec9c96534f58ecfaef04b471162777ee Mon Sep 17 00:00:00 2001 From: frju365 Date: Tue, 26 Sep 2017 21:08:01 +0200 Subject: [PATCH 01/48] [enh] REFACTORING --- scripts/install | 168 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 149 insertions(+), 19 deletions(-) diff --git a/scripts/install b/scripts/install index 7c1953b..939197e 100755 --- a/scripts/install +++ b/scripts/install @@ -1,33 +1,163 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Load common variables and functions -source ./_common.sh +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE FAILURE OF THE SCRIPT +#================================================= + +ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS +#================================================= -if ! [ "$path" = "/" ] -then - ynh_die "Path must be /" +if sudo yunohost domain list | grep -q $domain # Vérifie la liste des domaines +then # Si le domaine existe dans Yunohost + if sudo yunohost app map | grep -q $domain # Vérifie la liste des apps par domaine + then # Si une app est installée sur ce domaine. + WARNING echo "An app is already installed on the domain $domain. cryptpad needs a whole domain or subdomain to himself." + fi fi -# Save app settings -ynh_app_setting_set "$app" is_public "$is_public" +path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path +CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine. +CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. -# Install the app -install_haste $domain $path $is_public +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= -# Start Haste -sudo systemctl start "$app".service +ynh_app_setting_set $app domain "$domain" +ynh_app_setting_set $app is_public "$is_public" +ynh_app_setting_set $app path_url "$path_url" -# Add Haste to YunoHost's monitored services -sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= + +port=$(ynh_find_port 3000) # Cherche un port libre. +ynh_app_setting_set $app port $port + +#================================================= +# INSTALL NODEJS +#================================================= + +ynh_install_nodejs $NODEJS_VERSION + +#================================================= +# CREATE DEDICATED USER +#================================================= + +ynh_system_user_create $app + +#================================================= +# SPECIFIC SETUP +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= + +# Créer le dossier de log +sudo mkdir -p /var/log/$app +sudo touch /var/log/$app/$app.log +sudo chown $app -R /var/log/$app + +# Setup logrotate +ynh_use_logrotate + + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +final_path=/var/www/$app +ynh_app_setting_set $app final_path $final_path +ynh_setup_source $final_path + +# Set files ownership during installation +sudo chown $app: $final_path -R +sudo chmod 755 $final_path -R + +#================================================= +# Modify Nginx configuration file and copy it to Nginx conf directory +#================================================= + +ynh_nginx_config + +#================================================= +# ADD SYSTEMD SERVICE +#================================================= + +ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" +ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" +ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" +ynh_systemd_config + +#================================================= +# INSTALL HASTEBIN +#================================================= + +script_dir="$PWD" +pushd "$final_path" +sudo chown -R $app: $final_path +sudo_path npm install + +#================================================= +# Configure haste with config.js file +#================================================= + + sudo cp ../conf/config.js "$DESTDIR"/config.js + sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js + +#================================================= +# Add HASTE AS A BINARY FILE +#================================================= + +ynh_replace_string "YNH_HASTE_URL" "${DOMAIN}${path%/}" "../conf/haste.sh" +sudo cp ../conf/haste.sh /usr/bin/"$app" +sudo chmod +x /usr/bin/"$app" + +================================================= +# ENABLE SERVICE IN ADMIN PANEL +#================================================= + +# Ajoute le service au monitoring de Yunohost. +sudo yunohost service add $app --log "/var/log/$app/$app.log" + +#================================================= +# START HASTEBIN IN BACKGROUND +#================================================= + +sudo systemctl start $app + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 1 ]; +then + ynh_app_setting_set "$app" unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +sudo systemctl reload nginx From bfd3e46c60fb09f926db61dfeb00a820e9536e85 Mon Sep 17 00:00:00 2001 From: frju365 Date: Tue, 26 Sep 2017 21:33:09 +0200 Subject: [PATCH 02/48] [Fix] __PORT__ --- conf/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/config.js b/conf/config.js index 00e98c5..57cab27 100644 --- a/conf/config.js +++ b/conf/config.js @@ -1,7 +1,7 @@ { "host": "127.0.0.1", - "port": 7777, + "port": __PORT__, "keyLength": 10, From 5cd7b67d2db3ba46db1ff8619afc04c902450d1a Mon Sep 17 00:00:00 2001 From: frju365 Date: Tue, 26 Sep 2017 21:40:21 +0200 Subject: [PATCH 03/48] [Fix] Config.js --- conf/config.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/conf/config.js b/conf/config.js index 57cab27..15ed883 100644 --- a/conf/config.js +++ b/conf/config.js @@ -10,14 +10,14 @@ "staticMaxAge": 86400, "recompressStaticAssets": true, - + "logging": [ { - "level": "info", + "level": "verbose", "type": "Console", "colorize": true } - ], +], "keyGenerator": { "type": "phonetic" @@ -33,9 +33,12 @@ }, "storage": { - "type": "file", - "file": "YNH_DATA_PATH" - }, + "type": "redis", + "host": "0.0.0.0", + "port": 6379, + "db": 2, + "expire": 2592000 +}, "documents": { "about": "./about.md" From 196578749869f6e5297640f52d9514b95e567019 Mon Sep 17 00:00:00 2001 From: frju365 Date: Tue, 26 Sep 2017 21:45:54 +0200 Subject: [PATCH 04/48] Update config.js --- conf/config.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/conf/config.js b/conf/config.js index 15ed883..226bf72 100644 --- a/conf/config.js +++ b/conf/config.js @@ -33,11 +33,8 @@ }, "storage": { - "type": "redis", - "host": "0.0.0.0", - "port": 6379, - "db": 2, - "expire": 2592000 + "type": "file", + "file": "YNH_DATA_PATH" }, "documents": { From 06347c5af83330233762e22f0adce00ab44b26c7 Mon Sep 17 00:00:00 2001 From: frju365 Date: Tue, 26 Sep 2017 22:01:25 +0200 Subject: [PATCH 05/48] [Fix] Haste.service --- conf/{haste.service => systemd.service} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename conf/{haste.service => systemd.service} (50%) diff --git a/conf/haste.service b/conf/systemd.service similarity index 50% rename from conf/haste.service rename to conf/systemd.service index 136d796..65ca2c6 100644 --- a/conf/haste.service +++ b/conf/systemd.service @@ -5,12 +5,13 @@ After=network.target [Service] Type=simple -User=haste -Group=haste -WorkingDirectory=/opt/haste -ExecStart=/usr/bin/npm start +User=__APP__ +Group=__APP__ +ExecStartPre=__NODEJS__ +WorkingDirectory=__FINALPATH__ +Environment="PATH=__ENV_PATH__" +ExecStart=/opt/node_n/n/versions/node/__VERSION__/bin/npm start Restart=always -Environment=USER=haste HOME=/opt/haste [Install] WantedBy=multi-user.target From 19a16f51d555962ecaad26a4245bb438d7709e68 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sun, 8 Oct 2017 22:30:35 +0200 Subject: [PATCH 06/48] Create app.src --- conf/app.src | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 conf/app.src diff --git a/conf/app.src b/conf/app.src new file mode 100644 index 0000000..5b0660a --- /dev/null +++ b/conf/app.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://github.com/seejohnrun/haste-server/archive/f19c5d10498e214b8323fff9e5eab77cbb7eebff.tar.gz +SOURCE_SUM=6e67fd09bc7782d23d612c209a2de39212682239018a1bd2618c120f9cc36a47 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.gz +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= From 0dab42e897b91e9bdbff99a542aa92fba16f68a0 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sun, 8 Oct 2017 22:31:36 +0200 Subject: [PATCH 07/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 939197e..0685c48 100755 --- a/scripts/install +++ b/scripts/install @@ -60,7 +60,7 @@ ynh_app_setting_set $app port $port # INSTALL NODEJS #================================================= -ynh_install_nodejs $NODEJS_VERSION +ynh_install_nodejs 6.0.0 #================================================= # CREATE DEDICATED USER From 62f42f457f209d1a2532fd266d6e4ea8120a4ec9 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:03:26 +0200 Subject: [PATCH 08/48] Update install --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index 0685c48..6cb8fa1 100755 --- a/scripts/install +++ b/scripts/install @@ -21,6 +21,7 @@ ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est dét domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH +path_url="" is_public=$YNH_APP_ARG_IS_PUBLIC #================================================= From 360cb1a9db7e15e0404833d3af4dfcf06c26cd33 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:05:35 +0200 Subject: [PATCH 09/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 6cb8fa1..7821ef0 100755 --- a/scripts/install +++ b/scripts/install @@ -46,7 +46,7 @@ CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilis ynh_app_setting_set $app domain "$domain" ynh_app_setting_set $app is_public "$is_public" -ynh_app_setting_set $app path_url "$path_url" +ynh_app_setting_set $app path "$path" #================================================= # STANDARD MODIFICATIONS From d0ad9b7d375da75bbe172b21b13d9a73ef6e0aa2 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:08:29 +0200 Subject: [PATCH 10/48] Update install --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 7821ef0..50b086b 100755 --- a/scripts/install +++ b/scripts/install @@ -20,8 +20,7 @@ ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est dét #================================================= domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH -path_url="" +path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC #================================================= From bb217a845ca5a19d3f1ce9a478e1beafd2a820bf Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:11:05 +0200 Subject: [PATCH 11/48] Update install --- scripts/install | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/install b/scripts/install index 50b086b..804614c 100755 --- a/scripts/install +++ b/scripts/install @@ -27,17 +27,16 @@ is_public=$YNH_APP_ARG_IS_PUBLIC # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= -if sudo yunohost domain list | grep -q $domain # Vérifie la liste des domaines -then # Si le domaine existe dans Yunohost - if sudo yunohost app map | grep -q $domain # Vérifie la liste des apps par domaine - then # Si une app est installée sur ce domaine. - WARNING echo "An app is already installed on the domain $domain. cryptpad needs a whole domain or subdomain to himself." - fi -fi +final_path=/var/www/$app +test ! -e "$final_path" || ynh_die "This path already contains a folder" -path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path -CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine. -CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé. +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) + +# 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 From d26f56ebf51010097acb14ec805f2635f5093d67 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:12:30 +0200 Subject: [PATCH 12/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 804614c..f46de2b 100755 --- a/scripts/install +++ b/scripts/install @@ -44,7 +44,7 @@ ynh_webpath_register $app $domain $path_url ynh_app_setting_set $app domain "$domain" ynh_app_setting_set $app is_public "$is_public" -ynh_app_setting_set $app path "$path" +ynh_app_setting_set $app path_url "$path_url" #================================================= # STANDARD MODIFICATIONS From 83e5fa3292d097a73c5e63de6f972e13558db5df Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Mon, 9 Oct 2017 17:15:07 +0200 Subject: [PATCH 13/48] Update _common.sh --- scripts/_common.sh | 222 ++++++++++++++++++++++++++++----------------- 1 file changed, 137 insertions(+), 85 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b199e56..0447a00 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,107 +1,159 @@ -# -# Common variables -# +# 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. -APPNAME="haste" -app=${YNH_APP_INSTANCE_NAME:-haste} +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" -# Haste version -VERSION="master" +ynh_use_nodejs () { + nodejs_version=$(ynh_app_setting_get $app nodejs_version) -# set globals variables -DESTDIR="/opt/"${app} -DATA_PATH="/home/yunohost.app/"$app + load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir"" -# Remote URL to fetch Haste tarball -HASTE_URL="https://github.com/seejohnrun/haste-server/archive/"${VERSION}".zip" + nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" -# Source YunoHost helpers -source /usr/share/yunohost/helpers + # "Load" a version of node + eval $load_n_path; $nodejs_use_version -# -# Common helpers -# + # Get the absolute path of this version of node + nodejs_path="$(n bin $nodejs_version)" -check_or_install_npm() { - if ! dpkg -s npm | grep "installed" > /dev/null 2>&1 \ - || ! dpkg -s nodejs-legacy | grep "installed" > /dev/null 2>&1; then - sudo apt-get update - sudo apt-get install -y npm nodejs-legacy - fi + # Make an alias for node use + ynh_node_exec="eval $load_n_path; n use $nodejs_version" } -pre_inst_haste() { - # retrieve, extract, copy haste, add user if necessary - local TMPDIR=$(mktemp -d) - local HASTE_SOURCE=$1 +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" - haste_tarball="/tmp/haste.zip" - rm -f "$haste_tarball" - if [ "$HASTE_SOURCE" = "backup" ] - then - # Restore the app and data files - sudo cp -a ./www "$DESTDIR" - sudo cp -a ./data/. "$DATA_PATH" - # Restore directories and permissions - sudo chown -R "$app":"$app" "$DESTDIR" "$DATA_PATH" - else - wget -q -O "$haste_tarball" "$HASTE_URL" \ - || ynh_die "Unable to download haste" - unzip -q "$haste_tarball" -d "$TMPDIR" \ - || ynh_die "Unable to extract haste" - sudo rsync -a "$TMPDIR"/haste-server-master/* "$DESTDIR" - fi - rm -rf "$haste_tarball" "$TMPDIR" + # Create $n_install_dir + mkdir -p "$n_install_dir" - # Add user if not exist - id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet - id -u "$app" &>/dev/null || sudo adduser "$app" \ - --ingroup "$app" --system --quiet --shell /bin/bash + # 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:@@') - # Configure init script - sudo cp ../conf/"$app".service /etc/systemd/system/ - sudo systemctl daemon-reload - sudo systemctl enable "$app".service - } + # 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 -# Download, extract and install Haste to the given directory -# usage: install_haste DESTDIR -install_haste() { - local DOMAIN=$1 - local YNH_PATH=$2 - local IS_PUBLIC=$3 + # If n is not previously setup, install it + n --version > /dev/null 2>&1 || \ + ( echo "Installation of N - Node.js version management" >&2; \ + curl -sL $n_install_script | N_PREFIX=$N_PREFIX bash -s -- -y - 2>&1 ) - check_or_install_npm - pre_inst_haste none + # 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" - # install haste - current_dir=$(pwd) - cd "$DESTDIR" - sudo npm install - cd $current_dir + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH - sudo mkdir -p $DATA_PATH - sudo chown -R "$app":"$app" $DESTDIR $DATA_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 - # Configure haste with config.js file - sudo cp ../conf/config.js "$DESTDIR"/config.js - sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js + # Install the requested version of nodejs + n $nodejs_version - # Modify Nginx configuration file and copy it to Nginx conf directory - sed -i "s@PATHTOCHANGE@${YNH_PATH%/}@g" ../conf/nginx.conf - sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf + # 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) - # If app is public, add url to SSOWat conf as skipped_uris - if [[ $IS_PUBLIC -eq 1 ]]; then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" - fi + # 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 - # Reload services - sudo systemctl reload nginx.service + # 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" - # install haste cli client - sed -i "s@YNH_HASTE_URL@${DOMAIN}${path%/}@g" ../conf/haste.sh - sudo cp ../conf/haste.sh /usr/bin/"$app" - sudo chmod +x /usr/bin/"$app" + # 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" } From f6202baaa700d0a20401bb827422e90b81b86780 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Tue, 10 Oct 2017 22:11:57 +0200 Subject: [PATCH 14/48] Update _common.sh --- scripts/_common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index 0447a00..3234d4a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,3 +1,4 @@ +#!/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 From 8c93bc4bd43babfd3a83adcdc9f0c46b34c66f16 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:06:42 +0200 Subject: [PATCH 15/48] Update install --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index f46de2b..c030b3a 100755 --- a/scripts/install +++ b/scripts/install @@ -23,6 +23,8 @@ domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC +app=$YNH_APP_INSTANCE_NAME + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= From 1b989e0c68ce342dbae561f0ff530d06192da3e2 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:09:15 +0200 Subject: [PATCH 16/48] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index c030b3a..bfe12a8 100755 --- a/scripts/install +++ b/scripts/install @@ -100,7 +100,7 @@ sudo chmod 755 $final_path -R # Modify Nginx configuration file and copy it to Nginx conf directory #================================================= -ynh_nginx_config +ynh_add_nginx_config #================================================= # ADD SYSTEMD SERVICE @@ -109,7 +109,7 @@ ynh_nginx_config ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_systemd_config +ynh_add_systemd_config #================================================= # INSTALL HASTEBIN From b214a1a5d9a9fedf18c6e30980478c6f10b174da Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:13:17 +0200 Subject: [PATCH 17/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index bfe12a8..25f538d 100755 --- a/scripts/install +++ b/scripts/install @@ -118,7 +118,7 @@ ynh_add_systemd_config script_dir="$PWD" pushd "$final_path" sudo chown -R $app: $final_path -sudo_path npm install +sudo npm install #================================================= # Configure haste with config.js file From 2dc651657d63522fa694ee16d4954e1d8391da90 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:18:38 +0200 Subject: [PATCH 18/48] Update install --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 25f538d..387f7f5 100755 --- a/scripts/install +++ b/scripts/install @@ -61,8 +61,7 @@ ynh_app_setting_set $app port $port # INSTALL NODEJS #================================================= -ynh_install_nodejs 6.0.0 - +ynh_install_nodejs 8.0.0 #================================================= # CREATE DEDICATED USER #================================================= From 6218d44ecd80e3eff758560585f7ddf51d7bca80 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:22:29 +0200 Subject: [PATCH 19/48] Update install --- scripts/install | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/install b/scripts/install index 387f7f5..4a060f3 100755 --- a/scripts/install +++ b/scripts/install @@ -75,9 +75,9 @@ ynh_system_user_create $app #================================================= # Créer le dossier de log -sudo mkdir -p /var/log/$app -sudo touch /var/log/$app/$app.log -sudo chown $app -R /var/log/$app +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown $app -R /var/log/$app # Setup logrotate ynh_use_logrotate @@ -92,8 +92,8 @@ ynh_app_setting_set $app final_path $final_path ynh_setup_source $final_path # Set files ownership during installation -sudo chown $app: $final_path -R -sudo chmod 755 $final_path -R +chown $app: $final_path -R +chmod 755 $final_path -R #================================================= # Modify Nginx configuration file and copy it to Nginx conf directory @@ -114,38 +114,39 @@ ynh_add_systemd_config # INSTALL HASTEBIN #================================================= +ynh_use_nodejs script_dir="$PWD" pushd "$final_path" -sudo chown -R $app: $final_path -sudo npm install +chown -R $app: $final_path +npm install #================================================= # Configure haste with config.js file #================================================= - sudo cp ../conf/config.js "$DESTDIR"/config.js - sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js + cp ../conf/config.js "$DESTDIR"/config.js + sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js #================================================= # Add HASTE AS A BINARY FILE #================================================= ynh_replace_string "YNH_HASTE_URL" "${DOMAIN}${path%/}" "../conf/haste.sh" -sudo cp ../conf/haste.sh /usr/bin/"$app" -sudo chmod +x /usr/bin/"$app" +cp ../conf/haste.sh /usr/bin/"$app" +chmod +x /usr/bin/"$app" ================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= # Ajoute le service au monitoring de Yunohost. -sudo yunohost service add $app --log "/var/log/$app/$app.log" +yunohost service add $app --log "/var/log/$app/$app.log" #================================================= # START HASTEBIN IN BACKGROUND #================================================= -sudo systemctl start $app +systemctl start $app #================================================= # SETUP SSOWAT @@ -160,4 +161,4 @@ fi # RELOAD NGINX #================================================= -sudo systemctl reload nginx +systemctl reload nginx From 8af50a702cb082e7d1f9bd5f7fa78d9bfa8f1319 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:24:39 +0200 Subject: [PATCH 20/48] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 4a060f3..ab54a3f 100755 --- a/scripts/install +++ b/scripts/install @@ -124,8 +124,8 @@ npm install # Configure haste with config.js file #================================================= - cp ../conf/config.js "$DESTDIR"/config.js - sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js + cp ../conf/config.js "$final_path"/config.js + sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$final_path"/config.js #================================================= # Add HASTE AS A BINARY FILE From f62a8cf6fdea5835aee3db8140807082ee64a43a Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:25:35 +0200 Subject: [PATCH 21/48] Create check_process --- check_process | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 check_process diff --git a/check_process b/check_process new file mode 100644 index 0000000..d7e2812 --- /dev/null +++ b/check_process @@ -0,0 +1,43 @@ +# 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) + admin="john" (USER) + language="fr" + is_public=1 (PUBLIC|public=1|private=0) + password="pass" + port="666" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + backup_restore=1 + 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: + Level 4=0 +# Level 5: + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +;;; Options +Email= +Notification=none From 4a9e01f2e4fd5f128c950c850b39f778555baa2e Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:26:17 +0200 Subject: [PATCH 22/48] Update check_process --- check_process | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_process b/check_process index d7e2812..f44a27d 100644 --- a/check_process +++ b/check_process @@ -6,7 +6,7 @@ ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) - path="/path" (PATH) + path="/" (PATH) admin="john" (USER) language="fr" is_public=1 (PUBLIC|public=1|private=0) @@ -14,7 +14,7 @@ port="666" (PORT) ; Checks pkg_linter=1 - setup_sub_dir=1 + setup_sub_dir=0 setup_root=1 setup_nourl=0 setup_private=1 From 7ad69886188940d426be1d62bed016393b3692f8 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:35:48 +0200 Subject: [PATCH 23/48] Update install --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index ab54a3f..b897fa6 100755 --- a/scripts/install +++ b/scripts/install @@ -124,8 +124,7 @@ npm install # Configure haste with config.js file #================================================= - cp ../conf/config.js "$final_path"/config.js - sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$final_path"/config.js + ynh_replace_string "YNH_DATA_PATH" "$DATAPATH" "$final_path/config.js" #================================================= # Add HASTE AS A BINARY FILE From 3c4a38bd424981a516d066696729ff154949133c Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:40:23 +0200 Subject: [PATCH 24/48] Update install --- scripts/install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install b/scripts/install index b897fa6..dbb4048 100755 --- a/scripts/install +++ b/scripts/install @@ -119,6 +119,9 @@ script_dir="$PWD" pushd "$final_path" chown -R $app: $final_path npm install +DATA_PATH="/home/yunohost.app/$app" +mkdir -p $DATA_PATH +chown -R "$app":"$app" $final_path $DATA_PATH #================================================= # Configure haste with config.js file From 12d005f28e11fbec071e09386104c64288b7f120 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:42:41 +0200 Subject: [PATCH 25/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index dbb4048..9c9bf72 100755 --- a/scripts/install +++ b/scripts/install @@ -119,7 +119,7 @@ script_dir="$PWD" pushd "$final_path" chown -R $app: $final_path npm install -DATA_PATH="/home/yunohost.app/$app" +DATA_PATH="/home/yunohost.app/"$app mkdir -p $DATA_PATH chown -R "$app":"$app" $final_path $DATA_PATH From 80c8a3e07f5e1ddfe6f773bc7ee285e69da05bab Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:44:43 +0200 Subject: [PATCH 26/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 9c9bf72..19962e3 100755 --- a/scripts/install +++ b/scripts/install @@ -127,7 +127,7 @@ chown -R "$app":"$app" $final_path $DATA_PATH # Configure haste with config.js file #================================================= - ynh_replace_string "YNH_DATA_PATH" "$DATAPATH" "$final_path/config.js" + ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js" #================================================= # Add HASTE AS A BINARY FILE From 0f2fd51d17ae5f2c9d311734b0bbcded8e4e9102 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:47:23 +0200 Subject: [PATCH 27/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 19962e3..6638a1d 100755 --- a/scripts/install +++ b/scripts/install @@ -133,7 +133,7 @@ chown -R "$app":"$app" $final_path $DATA_PATH # Add HASTE AS A BINARY FILE #================================================= -ynh_replace_string "YNH_HASTE_URL" "${DOMAIN}${path%/}" "../conf/haste.sh" +ynh_replace_string "YNH_HASTE_URL" "${domain}${path%/}" "../conf/haste.sh" cp ../conf/haste.sh /usr/bin/"$app" chmod +x /usr/bin/"$app" From 098a650bb8465e04713c1e016c3b9ddc68c18146 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:50:01 +0200 Subject: [PATCH 28/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 6638a1d..9d49513 100755 --- a/scripts/install +++ b/scripts/install @@ -133,7 +133,7 @@ chown -R "$app":"$app" $final_path $DATA_PATH # Add HASTE AS A BINARY FILE #================================================= -ynh_replace_string "YNH_HASTE_URL" "${domain}${path%/}" "../conf/haste.sh" +ynh_replace_string "YNH_HASTE_URL" "${domain}${path_url%/}" "../conf/haste.sh" cp ../conf/haste.sh /usr/bin/"$app" chmod +x /usr/bin/"$app" From 116e96c54412a6d3ab45261602998579e389ee08 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:50:29 +0200 Subject: [PATCH 29/48] Update nginx.conf --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 8c68c6e..41a3833 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ location / { - proxy_pass http://localhost:7777/; + proxy_pass http://localhost:__PORT__/; proxy_set_header Host $host; proxy_buffering off; fastcgi_param REMOTE_USER $remote_user; From 9f61e57e9949c7d5238225daf6584d499ce455e7 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:56:51 +0200 Subject: [PATCH 30/48] Update install --- scripts/install | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scripts/install b/scripts/install index 9d49513..b49683d 100755 --- a/scripts/install +++ b/scripts/install @@ -129,14 +129,6 @@ chown -R "$app":"$app" $final_path $DATA_PATH ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js" -#================================================= -# Add HASTE AS A BINARY FILE -#================================================= - -ynh_replace_string "YNH_HASTE_URL" "${domain}${path_url%/}" "../conf/haste.sh" -cp ../conf/haste.sh /usr/bin/"$app" -chmod +x /usr/bin/"$app" - ================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= From 5282a88724720c2695d0cc8aa1986ba826af66df Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 18:58:51 +0200 Subject: [PATCH 31/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index b49683d..187a6ef 100755 --- a/scripts/install +++ b/scripts/install @@ -129,7 +129,7 @@ chown -R "$app":"$app" $final_path $DATA_PATH ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js" -================================================= +#================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= From 2289d398cbf9c2dc562f352e0a6e354cf110f31e Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 19:03:49 +0200 Subject: [PATCH 32/48] Update nginx.conf --- conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 41a3833..aa601d9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ location / { - proxy_pass http://localhost:__PORT__/; + proxy_pass http://localhost:__PORT__; proxy_set_header Host $host; proxy_buffering off; fastcgi_param REMOTE_USER $remote_user; From 94c418b8347fae669e403ac99a12268c9aeedc7c Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 19:07:49 +0200 Subject: [PATCH 33/48] Update install --- scripts/install | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 187a6ef..27b7c8d 100755 --- a/scripts/install +++ b/scripts/install @@ -54,9 +54,11 @@ ynh_app_setting_set $app path_url "$path_url" # FIND AND OPEN A PORT #================================================= -port=$(ynh_find_port 3000) # Cherche un port libre. +# Find a free port +port=$(ynh_find_port 8095) +# Open this port +yunohost firewall allow --no-upnp TCP $port 2>&1 ynh_app_setting_set $app port $port - #================================================= # INSTALL NODEJS #================================================= From d159bb0d6e45018c974c4821404284bc196fa748 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Fri, 13 Oct 2017 19:10:03 +0200 Subject: [PATCH 34/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 27b7c8d..7927e0d 100755 --- a/scripts/install +++ b/scripts/install @@ -63,7 +63,7 @@ ynh_app_setting_set $app port $port # INSTALL NODEJS #================================================= -ynh_install_nodejs 8.0.0 +ynh_install_nodejs 4 #================================================= # CREATE DEDICATED USER #================================================= From cf045d74352ed6bd2d0bce31a336d1bbaa1a33dd Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 14:33:42 +0200 Subject: [PATCH 35/48] Update systemd.service --- conf/systemd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/systemd.service b/conf/systemd.service index 65ca2c6..8d92c8b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -10,7 +10,7 @@ Group=__APP__ ExecStartPre=__NODEJS__ WorkingDirectory=__FINALPATH__ Environment="PATH=__ENV_PATH__" -ExecStart=/opt/node_n/n/versions/node/__VERSION__/bin/npm start +ExecStart=/opt/node_n/n/versions/node/4/bin/npm start Restart=always [Install] From cb980170b75aa5c402a637d7b344d7b3d54f95d0 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 14:38:56 +0200 Subject: [PATCH 36/48] Update remove --- scripts/remove | 127 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 22 deletions(-) diff --git a/scripts/remove b/scripts/remove index 7bf6d53..4367e39 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,33 +1,116 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Load common variables and functions -source ./_common.sh +source _common.sh +source /usr/share/yunohost/helpers -# Retrieve app settings -domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# LOAD SETTINGS +#================================================= -# Stop haste -sudo systemctl stop "$app".service +app=$YNH_APP_INSTANCE_NAME -# Remove sources -sudo rm -rf "/opt/"${app} +domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) +db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get $app final_path) -# Remove nginx configuration file -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= +# STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= -# Remove haste user and data -sudo userdel -r "$app" +# Remove the dedicated systemd config +ynh_remove_systemd_config -# Remove init script -sudo systemctl disable "$app".service -sudo rm -f /etc/systemd/system/"$app".service -sudo systemctl daemon-reload +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= -# Remove monitor -sudo yunohost service remove "$app" +if yunohost service status | grep -q $app +then + echo "Remove $app service" + yunohost service remove $app +fi -# Reload nginx service -sudo systemctl reload nginx.service +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db $db_name $db_name + +#================================================= +# 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 + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" + yunohost firewall disallow TCP $port 2>&1 +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= + +# Remove a cron file +ynh_secure_remove "/etc/cron.d/$app" + +# Remove a directory securely +ynh_secure_remove "/etc/$app/" + +# Remove the log files +ynh_secure_remove "/var/log/$app/" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete $app From aa1a6a5e3c20d293db079765ca73ad1ede975c18 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 15:36:26 +0200 Subject: [PATCH 37/48] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 7927e0d..f1a3baf 100755 --- a/scripts/install +++ b/scripts/install @@ -55,7 +55,7 @@ ynh_app_setting_set $app path_url "$path_url" #================================================= # Find a free port -port=$(ynh_find_port 8095) +port=$(ynh_find_port 7777) # Open this port yunohost firewall allow --no-upnp TCP $port 2>&1 ynh_app_setting_set $app port $port From ff328fbd510cc6a116a4c927af466d7ca73f728a Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 15:37:16 +0200 Subject: [PATCH 38/48] Update remove --- scripts/remove | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/remove b/scripts/remove index 4367e39..8664a5c 100755 --- a/scripts/remove +++ b/scripts/remove @@ -46,12 +46,6 @@ fi # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR @@ -67,12 +61,6 @@ ynh_secure_remove "$final_path" # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= - -# Remove the dedicated php-fpm config -ynh_remove_fpm_config #================================================= # REMOVE LOGROTATE CONFIGURATION From 1449bbeb7abdde179f6319808ca74cd16d17050b Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 15:55:02 +0200 Subject: [PATCH 39/48] Update backup --- scripts/backup | 74 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/scripts/backup b/scripts/backup index e5071aa..2e77816 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,22 +1,66 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Load common variables and functions -source ./_common.sh +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers -domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Copy the app source and data files -ynh_backup "$DESTDIR" "www" -ynh_backup "$DATA_PATH" "data" +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors -# Copy the conf files -mkdir ./conf -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf" -ynh_backup "/etc/systemd/system/${app}.service" "conf/systemd.service" -ynh_backup "/usr/bin/${app}" "conf/haste.sh" +#================================================= +# LOAD SETTINGS +#================================================= -# Copy NGINX configuration -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get $app domain) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup "/etc/logrotate.d/$app" + +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup "/etc/systemd/system/$app.service" + +#================================================= +# BACKUP THE CRON FILE +#================================================= + +ynh_backup "/etc/cron.d/$app" From 3996d72672fb1555a065202b6f39659a20dc8ab1 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 15:59:58 +0200 Subject: [PATCH 40/48] Update restore --- scripts/restore | 147 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 119 insertions(+), 28 deletions(-) diff --git a/scripts/restore b/scripts/restore index 633d74b..18ec9f7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,39 +1,130 @@ + #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Load common variables and functions -source ./_common.sh +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers -# Retrieve old app settings -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors -# Check destination directory -[[ -d $DESTDIR ]] && ynh_die \ -"The destination directory '$DESTDIR' already exists.\ - You should safely delete it before restoring this app." +#================================================= +# LOAD SETTINGS +#================================================= - # Check configuration files - nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" - [[ -f $nginx_conf ]] && ynh_die \ - "The NGINX configuration already exists at '${nginx_conf}'. - You should safely delete it before restoring this app." +app=$YNH_APP_INSTANCE_NAME -pre_inst_haste backup +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) +db_name=$(ynh_app_setting_get $app db_name) -# Restore NGINX configuration -sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= -# Restart webserver and app -sudo systemctl reload nginx.service -sudo systemctl start "$app".service +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " -# Add Haste to YunoHost's monitored services -sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= + +# Create the dedicated user (if not existing) +ynh_system_user_create $app + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chown -R root: $final_path + + +#================================================= +# SPECIFIC RESTORATION +#================================================= +ynh_install_nodejs 4 +#================================================= +# INSTALL HASTEBIN +#================================================= + +ynh_use_nodejs +script_dir="$PWD" +pushd "$final_path" +chown -R $app: $final_path +npm install +DATA_PATH="/home/yunohost.app/"$app +mkdir -p $DATA_PATH +chown -R "$app":"$app" $final_path $DATA_PATH + + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app --log "/var/log/$app/APP.log" + +#================================================= +# RESTORE SYSTEMD +#================================================= + +ynh_restore_file "/etc/systemd/system/$app.service" +systemctl enable $app.service + +#================================================= +# START HASTEBIN IN BACKGROUND +#================================================= + +systemctl start $app + +#================================================= +# RESTORE THE CRON FILE +#================================================= + +ynh_restore_file "/etc/cron.d/$app" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file "/etc/logrotate.d/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload nginx From 09300e510c584b7d5e16f42a772d92f4d4f1bfc3 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:08:49 +0200 Subject: [PATCH 41/48] Update restore --- scripts/restore | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/restore b/scripts/restore index 18ec9f7..f316133 100755 --- a/scripts/restore +++ b/scripts/restore @@ -109,12 +109,6 @@ systemctl enable $app.service systemctl start $app -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file "/etc/cron.d/$app" - #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= @@ -124,7 +118,7 @@ ynh_restore_file "/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX #================================================= systemctl reload nginx From 60361bd875098556e0e23e2ebd87b28aa14f9c5b Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:09:19 +0200 Subject: [PATCH 42/48] Update backup --- scripts/backup | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/backup b/scripts/backup index 2e77816..ea25bb2 100755 --- a/scripts/backup +++ b/scripts/backup @@ -59,8 +59,3 @@ ynh_backup "/etc/logrotate.d/$app" ynh_backup "/etc/systemd/system/$app.service" -#================================================= -# BACKUP THE CRON FILE -#================================================= - -ynh_backup "/etc/cron.d/$app" From 0349d57cb03a7b80d57cf9cecd885c22f4903df2 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:28:52 +0200 Subject: [PATCH 43/48] Update upgrade --- scripts/upgrade | 176 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 164 insertions(+), 12 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index af5a271..85c2139 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,18 +1,170 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Load common variables and functions -source ./_common.sh +source _common.sh +source /usr/share/yunohost/helpers -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) -is_public=$(ynh_app_setting_get "$app" is_public) +#================================================= +# LOAD SETTINGS +#================================================= -# Install the app -install_haste $domain $path $is_public +app=$YNH_APP_INSTANCE_NAME -# Start Haste -sudo systemctl restart "$app".service +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +is_public=$(ynh_app_setting_get $app is_public) +final_path=$(ynh_app_setting_get $app final_path) +port=$(ynh_app_setting_get $app port) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + +# If db_name doesn't exist, create it +if [ -z $db_name ]; then + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name +fi + +# If final_path doesn't exist, create it +if [ -z $final_path ]; then + final_path=/var/www/$app + ynh_app_setting_set $app final_path $final_path +fi + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# INSTALL NODEJS +#================================================= + +ynh_install_nodejs 4 +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source "$final_path" +# Set files ownership during installation +chown $app: $final_path -R +chmod 755 $final_path -R + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create $app + +#================================================= +# INSTALL HASTEBIN +#================================================= + +ynh_use_nodejs +script_dir="$PWD" +pushd "$final_path" +chown -R $app: $final_path +npm install +DATA_PATH="/home/yunohost.app/"$app +mkdir -p $DATA_PATH +chown -R "$app":"$app" $final_path $DATA_PATH + +#================================================= +# Configure haste with config.js file +#================================================= + + ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js" + + +# Verify the checksum and backup the file if it's different +ynh_backup_if_checksum_is_different "$final_path/config.js" +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/config.js" + +#================================================= +# SETUP LOGROTATE +#================================================= + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate + +#================================================= +# ADD SYSTEMD SERVICE +#================================================= + +ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" +ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" +ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" +ynh_add_systemd_config + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set right permissions for curl installation +chown -R root: $final_path + +#================================================= +# SETUP SSOWAT +#================================================= + +if [ $is_public -eq 0 ] +then # Remove the public access + ynh_app_setting_delete $app skipped_uris +fi +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set $app unprotected_uris "/" +fi + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx From 63b0ce67406aae2f804e9c0135a825825982e591 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:36:30 +0200 Subject: [PATCH 44/48] Update upgrade --- scripts/upgrade | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 85c2139..228b472 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -97,6 +97,14 @@ ynh_add_nginx_config # Create a system user ynh_system_user_create $app +#================================================= +# ADD SYSTEMD SERVICE +#================================================= + +ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" +ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" +ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" +ynh_add_systemd_config #================================================= # INSTALL HASTEBIN #================================================= @@ -110,12 +118,6 @@ DATA_PATH="/home/yunohost.app/"$app mkdir -p $DATA_PATH chown -R "$app":"$app" $final_path $DATA_PATH -#================================================= -# Configure haste with config.js file -#================================================= - - ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js" - # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different "$final_path/config.js" @@ -129,16 +131,6 @@ ynh_store_file_checksum "$final_path/config.js" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate -#================================================= -# ADD SYSTEMD SERVICE -#================================================= - -ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service" -ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" -ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_add_systemd_config - - #================================================= # GENERIC FINALIZATION #================================================= From 916f0e02fe523cdd5cb0d948e117437d960555ea Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:40:35 +0200 Subject: [PATCH 45/48] Update manifest.json --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 188a1ff..82dc24b 100644 --- a/manifest.json +++ b/manifest.json @@ -7,14 +7,14 @@ "fr": "Haste is an open-source pastebin software written in node.js" }, "url": "https://github.com/seejohnrun/haste-server", - "license": "free", + "license": "MIT", "maintainer": { "name": "mbugeia", "email": "maxime.bugeia@gmail.com", "url": "https://github.com/YunoHost-Apps/haste_ynh" }, "requirements": { - "yunohost": ">> 2.4.0" + "yunohost": ">>= 2.7.2" }, "multi_instance": false, "services": [ From 9654f7a81a1d5af8341cbb288d2f6f326f9cffaa Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:43:37 +0200 Subject: [PATCH 46/48] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 228b472..ca651c0 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,7 +16,7 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) +path_url=$(ynh_app_setting_get $app path_url) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) From f8db5b8302700de7a9f853ff47fa52f46bf17cb9 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 16:49:48 +0200 Subject: [PATCH 47/48] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 82dc24b..306ddff 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "url": "https://github.com/YunoHost-Apps/haste_ynh" }, "requirements": { - "yunohost": ">>= 2.7.2" + "yunohost": ">= 2.7.2" }, "multi_instance": false, "services": [ From 84d6f48745874c25a2543b31421283d532b8b684 Mon Sep 17 00:00:00 2001 From: Rafi59 Date: Sat, 14 Oct 2017 18:21:41 +0200 Subject: [PATCH 48/48] Update remove --- scripts/remove | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/scripts/remove b/scripts/remove index 8664a5c..90f608e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -39,13 +39,6 @@ then yunohost service remove $app fi -#================================================= -# REMOVE DEPENDENCIES -#================================================= - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE APP MAIN DIR @@ -82,17 +75,6 @@ fi #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE -#================================================= - -# Remove a cron file -ynh_secure_remove "/etc/cron.d/$app" - -# Remove a directory securely -ynh_secure_remove "/etc/$app/" - -# Remove the log files -ynh_secure_remove "/var/log/$app/" #================================================= # GENERIC FINALIZATION