mirror of
https://github.com/YunoHost-Apps/ztncui_ynh.git
synced 2024-09-03 18:06:05 +02:00
[enh] to level 6
This commit is contained in:
parent
c874edf301
commit
430f3d9000
5 changed files with 78 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#=================================================
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
#=================================================
|
||||
|
|
|
@ -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=$(</var/lib/zerotier-one/authtoken.secret)" >> $env_file
|
||||
echo "ZT_ADDR=localhost:$(</var/lib/zerotier-one/zerotier-one.port)" >> $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
|
||||
|
|
Loading…
Add table
Reference in a new issue