2019-12-15 16:09:28 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url="/" #$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2020-04-18 14:53:52 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
2020-03-20 21:16:20 +01:00
|
|
|
# Testing if ZeroTier is installed
|
2020-04-18 17:03:30 +02:00
|
|
|
yunohost app list | grep -q "id: zerotier" || ynh_die "ZeroTier is needed, but it is not installed. There is a package for that!"
|
2020-03-20 21:16:20 +01:00
|
|
|
|
2020-04-16 16:08:39 +02:00
|
|
|
final_path=/opt/yunohost/$app
|
2019-12-15 16:09:28 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-01-09 22:40:37 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=8095)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=2
|
2019-12-15 16:09:28 +01:00
|
|
|
|
2020-04-16 16:08:39 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2020-12-06 09:29:46 +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
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Create a system user
|
2020-04-17 20:16:53 +02:00
|
|
|
ynh_system_user_create $app $final_path
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# NPM INSTALL
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Performing Node app installation..." --weight=3
|
2019-12-15 16:09:28 +01:00
|
|
|
|
2020-04-17 20:16:53 +02:00
|
|
|
chown -R $app: $final_path
|
|
|
|
|
2019-12-15 16:09:28 +01:00
|
|
|
pushd $final_path/src
|
2021-10-24 00:28:27 +02:00
|
|
|
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
|
2021-11-08 23:48:40 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
2022-01-15 16:51:36 +01:00
|
|
|
# Let's retrieve information on the ZeroTier installation
|
2022-01-15 18:14:52 +01:00
|
|
|
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
|
|
|
|
2022-01-15 19:48:44 +01:00
|
|
|
ynh_add_config --template="env" --destination="$final_path/src/.env"
|
|
|
|
chown $app:$app "$final_path/src/.env"
|
|
|
|
chmod 600 "$final_path/src/.env"
|
2019-12-15 16:09:28 +01:00
|
|
|
|
2020-04-18 14:53:52 +02:00
|
|
|
# Setup user credentials file
|
2020-04-18 15:33:31 +02:00
|
|
|
hashedpassword=$(echo -n "$password" | $final_path/src/node_modules/.bin/argon2-cli -e)
|
2022-01-15 16:51:36 +01:00
|
|
|
echo "{\"$admin\":{\"name\":\"$admin\",\"pass_set\":true,\"hash\":\"$hashedpassword\"}}" > "$final_path/src/etc/passwd"
|
2020-04-18 14:53:52 +02:00
|
|
|
|
|
|
|
# Store user settings
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
ynh_app_setting_set --app=$app --key=hashedpassword --value=$hashedpassword
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LINK CERTIFICATES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Even though one can stay in HTTP mode, the ztncui requires SSL certificates
|
|
|
|
# let's use the ones of the domain
|
|
|
|
pushd $final_path/src/etc/tls
|
2020-03-20 22:51:45 +01:00
|
|
|
cp /etc/yunohost/certs/$domain/key.pem privkey.pem
|
|
|
|
cp /etc/yunohost/certs/$domain/crt.pem fullchain.pem
|
2019-12-15 16:09:28 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
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
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2020-12-06 09:29:46 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
yunohost service add $app --description "ZeroTier network controller user interface" --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Starting the systemd service..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-04-18 13:26:22 +02:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2020-04-18 13:26:22 +02:00
|
|
|
ynh_permission_update --permission "main" --add visitors
|
2019-12-15 16:09:28 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
2019-12-15 16:09:28 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-14 17:31:45 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|