mirror of
https://github.com/YunoHost-Apps/ztncui_ynh.git
synced 2024-09-03 18:06:05 +02:00
103 lines
3.8 KiB
Bash
103 lines
3.8 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)"
|
||
|
||
#=================================================
|
||
# INSTALL DEPENDENCIES
|
||
#=================================================
|
||
ynh_script_progression --message="Installing NodeJS..." --weight=2
|
||
|
||
ynh_install_nodejs --nodejs_version="$nodejs_version"
|
||
ynh_use_nodejs
|
||
|
||
#=================================================
|
||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||
#=================================================
|
||
ynh_script_progression --message="Setting up source files..." --weight=2
|
||
|
||
# Download, check integrity, uncompress and patch the source from app.src
|
||
ynh_setup_source --dest_dir="$install_dir"
|
||
|
||
chmod -R o-rwx "$install_dir"
|
||
chown -R "$app:$app" "$install_dir"
|
||
|
||
#=================================================
|
||
# APP INITIAL CONFIGURATION
|
||
#=================================================
|
||
ynh_script_progression --message="Adding $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" "$ynh_npm" install node-gyp
|
||
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install argon2-cli
|
||
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install
|
||
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" audit fix
|
||
popd
|
||
|
||
# Setup user credentials file
|
||
hashedpassword=$(echo -n "$password" | $install_dir/src/node_modules/.bin/argon2-cli -e)
|
||
echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":true,\"hash\":\"$hashedpassword\"}}" > "$install_dir/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
|
||
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"
|
||
|
||
#=================================================
|
||
# SYSTEM CONFIGURATION
|
||
#=================================================
|
||
ynh_script_progression --message="Adding 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 application logfile(s)
|
||
ynh_use_logrotate
|
||
|
||
#=================================================
|
||
# 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="Installation of $app completed" --last
|