diff --git a/check_process b/check_process index 2b13920..89023cf 100644 --- a/check_process +++ b/check_process @@ -23,9 +23,9 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=CommitHash + ;upgrade=1 from_commit=CommitHash backup_restore=1 - multi_instance=1 + multi_instance=0 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. # incorrect_path=1 port_already_use=0 diff --git a/scripts/_common.sh b/scripts/_common.sh index 38aa8ed..f55d066 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,6 +17,21 @@ pkg_dependencies="g++" # EXPERIMENTAL HELPERS #================================================= +#!/bin/bash + +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo PATH=$PATH -u "$USER" "$@" + fi +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 25da065..01599c3 100644 --- a/scripts/install +++ b/scripts/install @@ -142,7 +142,7 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring system user..." --time --weight=1 # Create a system user -ynh_system_user_create --username=$app +ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP @@ -151,10 +151,12 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Performing Node app installation..." --time --weight=1 +chown -R $app: $final_path + pushd $final_path/src - ynh_debug_exec $nodejs_path/npm install node-gyp - ynh_debug_exec $nodejs_path/npm install - ynh_debug_exec $nodejs_path/npm audit fix + exec_as $app $nodejs_path/npm install node-gyp + exec_as $app $nodejs_path/npm install + exec_as $app $nodejs_path/npm audit fix popd #================================================= @@ -202,9 +204,9 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei # Create a dedicated systemd config ynh_add_systemd_config -ynh_replace_string "__ENV_PATH__" "$PATH" "/etc/systemd/system/$app.service" -ynh_replace_string "__NODEJS_PATH__" "/opt/node_n/n/versions/node/$nodejs_version/bin/" "/etc/systemd/system/$app.service" -ynh_replace_string "__FINALPATH__" "$final_path" "/etc/systemd/system/$app.service" +ynh_replace_string "__ENV_PATH__" "$PATH" "$finalsystemdconf" +ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$finalsystemdconf" +ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" systemctl daemon-reload diff --git a/scripts/remove b/scripts/remove index c057776..9cf7ddf 100644 --- a/scripts/remove +++ b/scripts/remove @@ -33,6 +33,14 @@ then yunohost service remove $app fi +#================================================= +# STOP AND REMOVE SERVICE +#================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1 + +# Remove the dedicated systemd config +ynh_remove_systemd_config + #================================================= # REMOVE DEPENDENCIES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1957c55..c9b9c15 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION @@ -119,7 +120,10 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 -#ynh_install_app_dependencies $pkg_dependencies +ynh_install_app_dependencies $pkg_dependencies + +ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_use_nodejs #================================================= # CREATE DEDICATED USER @@ -127,7 +131,7 @@ ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create $app $final_path #================================================= # SPECIFIC UPGRADE @@ -136,8 +140,39 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Performing Node app installation..." --time --weight=1 +chown -R $app: $final_path + pushd $final_path/src - npm install + exec_as $app $nodejs_path/npm install node-gyp + exec_as $app $nodejs_path/npm install + exec_as $app $nodejs_path/npm audit fix +popd + +#================================================= +# MODIFY A CONFIG FILE +#================================================= + +# Setup env file +mkdir -p $final_path +env_file=$final_path/src/.env +touch $env_file +chmod 600 $env_file + +echo "ZT_TOKEN=$(> $env_file +echo "ZT_ADDR=localhost:$(> $env_file +echo "HTTP_PORT=$port" >> $env_file + +cp $final_path/src/etc/default.passwd $final_path/src/etc/passwd + +#================================================= +# LINK CERTIFICATES +#================================================= + +# Even though one can stay in HTTP mode, the ztncui requires SSL certificates +# let's use the ones of the domain +pushd $final_path/src/etc/tls + cp /etc/yunohost/certs/$domain/key.pem privkey.pem + cp /etc/yunohost/certs/$domain/crt.pem fullchain.pem popd #================================================= @@ -155,6 +190,11 @@ ynh_script_progression --message="Upgrading systemd configuration..." --time --w # Create a dedicated systemd config ynh_add_systemd_config +ynh_replace_string "__ENV_PATH__" "$PATH" "$finalsystemdconf" +ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$finalsystemdconf" +ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" + +systemctl daemon-reload #================================================= # GENERIC FINALIZATION @@ -163,7 +203,7 @@ ynh_add_systemd_config #================================================= # Set permissions on app files -chown -R root: $final_path +chown -R $app: $final_path #================================================= # SETUP SSOWAT