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/install

104 lines
3.8 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
#=================================================
2020-03-20 21:16:20 +01:00
# Testing if ZeroTier is installed
2024-03-29 12:15:57 +01:00
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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Installing 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
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
2019-12-15 16:09:28 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2024-03-29 12:15:57 +01:00
ynh_setup_source --dest_dir="$install_dir"
2019-12-15 16:09:28 +01:00
2024-03-29 12:21:09 +01:00
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
# APP INITIAL CONFIGURATION
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Adding $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"
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
2019-12-15 16:09:28 +01: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" "$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
2019-12-15 16:09:28 +01:00
popd
2020-04-18 14:53:52 +02:00
# Setup user credentials file
2024-03-29 12:15:57 +01:00
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"
2019-12-15 16:09:28 +01:00
#=================================================
# 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
# SYSTEM CONFIGURATION
2019-12-15 16:09:28 +01:00
#=================================================
2024-03-29 12:15:57 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# 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
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# 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="Installation of $app completed" --last