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
|
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
2020-04-25 15:34:13 +02: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"
|
2020-04-25 15:34:13 +02:00
|
|
|
|
else
|
2024-03-29 12:15:57 +01:00
|
|
|
|
pass_set="true"
|
2020-04-25 15:34:13 +02:00
|
|
|
|
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:21:09 +01:00
|
|
|
|
chmod -R o-rwx "$install_dir"
|
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
|
2021-08-14 16:39:03 +02:00
|
|
|
|
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
|
2020-12-06 09:29:46 +01:00
|
|
|
|
|
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
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2020-05-14 17:31:45 +02:00
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|
2020-04-25 15:34:13 +02:00
|
|
|
|
|
|
|
|
|
if [ $pass_set = "false" ]; then
|
2024-03-29 12:15:57 +01:00
|
|
|
|
ynh_print_warn --message="Default ztncui credentials were reset: admin/password"
|
2020-04-25 15:34:13 +02:00
|
|
|
|
fi
|