mirror of
https://github.com/YunoHost-Apps/ztncui_ynh.git
synced 2024-09-03 18:06:05 +02:00
129 lines
5 KiB
Bash
129 lines
5 KiB
Bash
#!/bin/bash
|
||
|
||
#=================================================
|
||
# IMPORT GENERIC HELPERS
|
||
#=================================================
|
||
|
||
source _common.sh
|
||
source /usr/share/yunohost/helpers
|
||
|
||
#=================================================
|
||
# INITIALIZE AND STORE SETTINGS
|
||
#=================================================
|
||
|
||
# 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
|
||
|
||
# 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)"
|
||
|
||
#=================================================
|
||
# ENSURE DOWNWARD COMPATIBILITY
|
||
#=================================================
|
||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||
|
||
# If admin or password do not exist, assign the standard ones and have them replaced upon first login
|
||
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="$app" --key="hashedpassword" --value="$hashedpassword"
|
||
|
||
# Setup user credentials file
|
||
echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":$pass_set,\"hash\":\"$hashedpassword\"}}" > "$install_dir/src/etc/passwd"
|
||
else
|
||
pass_set="true"
|
||
fi
|
||
|
||
#=================================================
|
||
# STOP SYSTEMD SERVICE
|
||
#=================================================
|
||
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
||
|
||
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
||
|
||
#=================================================
|
||
# INSTALL DEPENDENCIES
|
||
#=================================================
|
||
ynh_script_progression --message="Upgrading NodeJS..." --weight=2
|
||
|
||
ynh_install_nodejs --nodejs_version="$nodejs_version"
|
||
ynh_use_nodejs
|
||
|
||
#=================================================
|
||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||
#=================================================
|
||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||
|
||
# Download, check integrity, uncompress and patch the source from app.src
|
||
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="src/.env"
|
||
|
||
chmod -R o-rwx "$install_dir"
|
||
chown -R "$app:$app" "$install_dir"
|
||
|
||
#=================================================
|
||
# UPDATE A CONFIG FILE
|
||
#=================================================
|
||
ynh_script_progression --message="Updating $app's configuration files..." --weight=1
|
||
|
||
ynh_add_config --template="env" --destination="$install_dir/src/.env"
|
||
|
||
chown "$app:$app" "$install_dir/src/.env"
|
||
chmod 600 "$install_dir/src/.env"
|
||
|
||
#=================================================
|
||
# NPM INSTALL
|
||
#=================================================
|
||
ynh_script_progression --message="Building $app..." --weight=3
|
||
|
||
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
|
||
popd
|
||
|
||
#=================================================
|
||
# LINK CERTIFICATES
|
||
#=================================================
|
||
|
||
# Even though one can stay in HTTP mode, the ztncui requires SSL certificates
|
||
# 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"
|
||
|
||
#=================================================
|
||
# REAPPLY SYSTEM CONFIGURATIONS
|
||
#=================================================
|
||
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
||
|
||
# Create a dedicated nginx config
|
||
ynh_add_nginx_config
|
||
|
||
# Create a dedicated systemd config
|
||
ynh_add_systemd_config
|
||
yunohost service add "$app" --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log"
|
||
|
||
# Use logrotate to manage app-specific logfile(s)
|
||
ynh_use_logrotate --non-append
|
||
|
||
#=================================================
|
||
# START SYSTEMD SERVICE
|
||
#=================================================
|
||
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
||
|
||
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
||
|
||
#=================================================
|
||
# END OF SCRIPT
|
||
#=================================================
|
||
|
||
ynh_script_progression --message="Upgrade of $app completed" --last
|
||
|
||
if [ $pass_set = "false" ]; then
|
||
ynh_print_warn --message="Default ztncui credentials were reset: admin/password"
|
||
fi
|