1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ztncui_ynh.git synced 2024-09-03 18:06:05 +02:00
ztncui_ynh/scripts/upgrade

129 lines
5 KiB
Text
Raw Normal View History

2019-12-15 16:09:28 +01:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-03-29 12:15:57 +01:00
# INITIALIZE AND STORE SETTINGS
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# Testing if ZeroTier is installed
if ! yunohost app list | grep -q "id: zerotier"; then
ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!"
fi
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
# Let's retrieve information on the ZeroTier installation
zt_token="$(</var/lib/zerotier-one/authtoken.secret)"
zt_addr="localhost:$(</var/lib/zerotier-one/zerotier-one.port)"
2019-12-15 16:09:28 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2019-12-15 16:09:28 +01:00
# If admin or password do not exist, assign the standard ones and have them replaced upon first login
2024-03-29 12:15:57 +01:00
if [ -z "${admin:-}" ] || [ -z "${hashedpassword:-}" ]; then
admin="admin"
hashedpassword='$argon2i$v=19$m=4096,t=3,p=1$/VYxjWHBzbkuCEO6Hh0AUw$nJaTJtth57vCAyYvg+UbtnscilR0UcE02AfLOhERe3A'
pass_set="false"
ynh_app_setting_set --app="$app" --key="admin" --value="$admin"
ynh_app_setting_set --app="$hashedpassword" --key="hashedpassword" --value="$hashedpassword"
# Setup user credentials file
echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":$pass_set,\"hash\":\"$hashedpassword\"}}" > "$install_dir/src/etc/passwd"
else
2024-03-29 12:15:57 +01:00
pass_set="true"
fi
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# STOP SYSTEMD SERVICE
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# INSTALL DEPENDENCIES
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Upgrading NodeJS..." --weight=2
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
ynh_install_nodejs --nodejs_version="$nodejs_version"
ynh_use_nodejs
2019-12-15 16:09:28 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
chown -R "$app:$app" "$install_dir"
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# UPDATE A CONFIG FILE
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Updating $app's configuration files..." --weight=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
ynh_add_config --template="env" --destination="$install_dir/src/.env"
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
chown "$app:$app" "$install_dir/src/.env"
chmod 600 "$install_dir/src/.env"
2019-12-15 16:09:28 +01:00
#=================================================
# NPM INSTALL
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Building $app..." --weight=3
2020-04-17 20:16:53 +02:00
2024-03-29 12:15:57 +01:00
pushd "$install_dir/src"
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install node-gyp
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install argon2-cli
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" install
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "HOME=$install_dir" "$ynh_npm" audit fix
2020-04-17 20:16:53 +02:00
popd
#=================================================
# LINK CERTIFICATES
#=================================================
# Even though one can stay in HTTP mode, the ztncui requires SSL certificates
2024-03-29 12:15:57 +01:00
# let's use the ones of the domain
cp "/etc/yunohost/certs/$domain/key.pem" "$install_dir/src/etc/tls/privkey.pem"
cp "/etc/yunohost/certs/$domain/crt.pem" "$install_dir/src/etc/tls/fullchain.pem"
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2019-12-15 16:09:28 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
2024-03-29 12:15:57 +01:00
yunohost service add "$app" --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log"
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2019-12-15 16:09:28 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
2019-12-15 16:09:28 +01:00
2024-03-29 12:15:57 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
2019-12-15 16:09:28 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last
if [ $pass_set = "false" ]; then
2024-03-29 12:15:57 +01:00
ynh_print_warn --message="Default ztncui credentials were reset: admin/password"
fi