1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wetty_ynh.git synced 2024-09-03 18:16:29 +02:00

Apply last example_ynh

This commit is contained in:
yalh76 2021-05-12 00:42:40 +02:00 committed by Félix Piédallu
parent 5983c1366f
commit 50b756a5e6
11 changed files with 213 additions and 258 deletions

View file

@ -1,14 +1,9 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet ;; Test complet
; Manifest ; Manifest
domain="domain.tld" (DOMAIN) domain="domain.tld"
path="/path" (PATH) path="/path"
language="fr" language="fr"
is_public=1 (PUBLIC|public=1|private=0) is_public=1
password="pass" password="pass"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
@ -18,7 +13,8 @@
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
# New app, no upgrade. upgrade=1 from_commit=CommitHash # 2.0.3~ynh4
upgrade=1 from_commit=a3ac3d094feaa8ea45d98fb8c067c532216bb1a8
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
port_already_use=0 port_already_use=0
@ -27,6 +23,5 @@
Email= Email=
Notification=none Notification=none
;;; Upgrade options ;;; Upgrade options
; commit=CommitHash ; commit=a3ac3d094feaa8ea45d98fb8c067c532216bb1a8
name=Name and date of the commit. name=2.0.3~ynh4
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666&

View file

@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME= SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -10,12 +10,11 @@ location __PATH__/ {
# break tells nginx to continue processing the location block # break tells nginx to continue processing the location block
rewrite ^__PATH__/$ __PATH__ break; rewrite ^__PATH__/$ __PATH__ break;
proxy_pass http://localhost:__PORT__; proxy_pass http://127.0.0.1:__PORT__;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
# TODO why doesn't this work ? new feature of nginx ? proxy_read_timeout 43200000;
# proxy_read_timeout 43200000;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View file

@ -4,18 +4,18 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
Environment=NODE_ENV=production
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
Environment=NODE_ENV=production WorkingDirectory=__FINALPATH__/
Environment="__YNH_NODE_LOAD_PATH__" ExecStart=__YNH_NODE__ . --conf __FINALPATH__/config.json5
WorkingDirectory=__FINALPATH__
ExecStart=node . --conf ./config.json5
TimeoutStopSec=20 TimeoutStopSec=20
KillMode=mixed KillMode=mixed
Restart=always Restart=always
RestartSec=2 RestartSec=2
StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -25,29 +25,18 @@
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
"ask": {
"en": "Choose a domain name for Wetty",
"fr": "Choisissez un nom de domaine pour Wetty"
},
"example": "example.com" "example": "example.com"
}, },
{ {
"name": "path", "name": "path",
"type": "path", "type": "path",
"ask": {
"en": "Choose a path for Wetty",
"fr": "Choisissez un chemin pour Wetty"
},
"example": "/wetty", "example": "/wetty",
"default": "/wetty" "default": "/wetty"
}, },
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"ask": {
"en": "Is it a public application?",
"fr": "Est-ce une application publique ?"
},
"help": { "help": {
"en": "Even if public, it still requires authentication.", "en": "Even if public, it still requires authentication.",
"fr": "Même publique, vous devrez vous authentifier" "fr": "Même publique, vous devrez vous authentifier"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
#================================================= #=================================================
# GENERIC START # GENERIC START
@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -26,8 +27,8 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
@ -52,7 +53,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
# ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
@ -64,4 +65,4 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for Wetty. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
#================================================= #=================================================
# GENERIC STARTING # GENERIC STARTING
@ -27,15 +27,14 @@ app=$YNH_APP_INSTANCE_NAME
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port)
port=$(ynh_app_setting_get --app="$app" --key=port)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up Wetty before changing its URL (may take a while)..." --weight=1 ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -43,7 +42,7 @@ ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -54,12 +53,14 @@ ynh_abort_if_errors
#================================================= #=================================================
change_domain=0 change_domain=0
if [ "$old_domain" != "$new_domain" ]; then if [ "$old_domain" != "$new_domain" ]
then
change_domain=1 change_domain=1
fi fi
change_path=0 change_path=0
if [ "$old_path" != "$new_path" ]; then if [ "$old_path" != "$new_path" ]
then
change_path=1 change_path=1
fi fi
@ -68,9 +69,9 @@ fi
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping the systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
@ -80,7 +81,8 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file # Change the path in the NGINX config file
if [ $change_path -eq 1 ]; then if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified # Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper # Set global variables for NGINX helper
@ -91,10 +93,11 @@ if [ $change_path -eq 1 ]; then
fi fi
# Change the domain for NGINX # Change the domain for NGINX
if [ $change_domain -eq 1 ]; then if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv "$nginx_conf_path" "/etc/nginx/conf.d/$new_domain.d/$app.conf" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
@ -110,7 +113,6 @@ domain="$new_domain"
path_url="$new_path" path_url="$new_path"
# port is already defined in this file # port is already defined in this file
ynh_backup_if_checksum_is_different --file="$final_path/config.json5"
ynh_add_config --template="config.json5" --destination="$final_path/config.json5" ynh_add_config --template="config.json5" --destination="$final_path/config.json5"
#================================================= #=================================================
@ -120,7 +122,8 @@ ynh_add_config --template="config.json5" --destination="$final_path/config.json5
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server started"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
@ -133,4 +136,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for Wetty" --last ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
#================================================= #=================================================
# GENERIC START # GENERIC START
@ -37,16 +37,15 @@ final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path # Register (book) web path
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app="$app" --key=domain --value="$domain" ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app="$app" --key=path --value="$path_url" ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app="$app" --key=is_public --value="$is_public"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -57,7 +56,7 @@ ynh_script_progression --message="Finding an available port..." --weight=1
# Find an available port # Find an available port
port=$(ynh_find_port --port=8095) port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app="$app" --key=port --value="$port" ynh_app_setting_set --app=$app --key=port --value=$port
# DO NOT OPEN THIS PORT # DO NOT OPEN THIS PORT
@ -70,19 +69,28 @@ ynh_script_progression --message="Installing dependencies..." --weight=6
ynh_install_nodejs --nodejs_version="$YNH_NODEJS_VERSION" ynh_install_nodejs --nodejs_version="$YNH_NODEJS_VERSION"
# Install Yarn # Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" \ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
--package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=1 ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" ynh_setup_source --dest_dir="$final_path"
ynh_add_config --template="config.json5" --destination="$final_path/config.json5" chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -92,30 +100,28 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username="$app" --home_dir="$final_path"
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --time --weight=1
ynh_add_config --template="config.json5" --destination="$final_path/config.json5"
chmod 400 "$final_path/config.json5"
chown $app:$app "$final_path/config.json5"
#================================================= #=================================================
# BUILD YARN DEPENDENCIES # BUILD YARN DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Building Yarn dependencies... This may take several minutes for a first install." --weight=6 ynh_script_progression --message="Building Yarn dependencies... This may take several minutes for a first install." --weight=6
chown -R "$app":"$app" "$final_path"
pushd "$final_path" || return 1 pushd "$final_path" || return 1
ynh_use_nodejs ; set "${ynh_node_load_PATH:?}" ynh_use_nodejs ; set "${ynh_node_load_PATH:?}"
sudo -u "$app" env "$ynh_node_load_PATH" yarn sudo -u $app env "$ynh_node_load_PATH" yarn
sudo -u "$app" env "$ynh_node_load_PATH" yarn build sudo -u $app env "$ynh_node_load_PATH" yarn build
sudo -u "$app" env "$ynh_node_load_PATH" yarn install --production --ignore-scripts --prefer-offline sudo -u $app env "$ynh_node_load_PATH" yarn install --production --ignore-scripts --prefer-offline
yarn_bin_dir="$(sudo -u "$app" env "$ynh_node_load_PATH" yarn global bin)"
popd || return 1 popd || return 1
#================================================= #=================================================
@ -124,8 +130,7 @@ popd || return 1
ynh_script_progression --message="Configuring the systemd service..." --weight=1 ynh_script_progression --message="Configuring the systemd service..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
test -n "${ynh_node_load_PATH}${yarn_bin_dir}" ynh_add_systemd_config
ynh_add_systemd_config --others_var="ynh_node_load_PATH yarn_bin_dir"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -142,31 +147,27 @@ ynh_use_logrotate
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app" --description "Wetty Web Terminal service" --log "/var/log/$app/$app.log" yunohost service add $app --description="Wetty Web Terminal service" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting the systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server started"
#=================================================
# SETUP FAIL2BAN
#=================================================
# ynh_script_progression --message="Configuring fail2ban..." --weight=1
# Create a dedicated fail2ban config
# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=1 ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary # Make app public if necessary
if [ "$is_public" -eq 1 ]; then if [ $is_public -eq 1 ]
ynh_permission_update --permission "main" --add "visitors" then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi fi
#================================================= #=================================================
@ -180,4 +181,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of Wetty completed" --last ynh_script_progression --message="Installation of $app completed" --last

View file

@ -16,18 +16,19 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Removing Wetty service integration..." --weight=1
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then if ynh_exec_warn_less yunohost service status $app >/dev/null
yunohost service remove "$app" then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
fi fi
#================================================= #=================================================
@ -49,7 +50,7 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing Wetty main directory..." --weight=1 ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file="$final_path" ynh_secure_remove --file="$final_path"
@ -70,29 +71,6 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight=
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
#=================================================
# REMOVE FAIL2BAN CONFIGURATION
#=================================================
# ynh_script_progression --message="Removing fail2ban configuration..." --weight=1
# # Remove the dedicated fail2ban config
# ynh_remove_fail2ban_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
# # Remove a cron file
# ynh_secure_remove --file="/etc/cron.d/$app"
# # Remove a directory securely
# ynh_secure_remove --file="/etc/$app/"
# # Remove the log files
# ynh_secure_remove --file="/var/log/$app/"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -101,10 +79,10 @@ ynh_remove_logrotate
ynh_script_progression --message="Removing the dedicated system user..." --weight=1 ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user # Delete a system user
ynh_system_user_delete --username="$app" ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of Wetty completed" --last ynh_script_progression --message="Removal of $app completed" --last

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/bash
#================================================= #=================================================
# GENERIC START # GENERIC START
@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -26,18 +27,18 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain)
domain=$(ynh_app_setting_get --app="$app" --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path)
path_url=$(ynh_app_setting_get --app="$app" --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_script_progression --message="Validating restoration parameters..." --weight=1
ynh_webpath_available --domain="$domain" --path_url="$path_url" \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d "$final_path" \ test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
@ -45,30 +46,28 @@ test ! -d "$final_path" \
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring Wetty main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create --username="$app" ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
# Restore permissions on app files ynh_restore_file --origin_path="$final_path"
chown -R "$app":"$app" "$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -81,8 +80,7 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=3
ynh_install_nodejs --nodejs_version="$YNH_NODEJS_VERSION" ynh_install_nodejs --nodejs_version="$YNH_NODEJS_VERSION"
# Install Yarn # Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" \ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
--package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
@ -90,27 +88,28 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_systemd_action --service_name="$app" --action="enable" --log_path="/var/log/$app/$app.log" systemctl enable $app.service --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app" --description "Wetty Web Terminal service" --log "/var/log/$app/$app.log" yunohost service add $app --description="Wetty Web Terminal service" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server started"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
# ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -16,11 +16,10 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app="$app" --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port)
port=$(ynh_app_setting_get --app="$app" --key=port)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
@ -28,26 +27,6 @@ port=$(ynh_app_setting_get --app="$app" --key=port)
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app="$app" --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app="$app" --key=is_public --value=0
is_public=0
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path="/var/www/$app"
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
@ -56,7 +35,7 @@ ynh_script_progression --message="Backing up Wetty before upgrading (may take a
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
# restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -67,9 +46,60 @@ ynh_abort_if_errors
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping the systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path="/var/www/$app"
ynh_app_setting_set --app=$app --key=final_path --value="$final_path"
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
@ -84,49 +114,29 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
--package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # SPECIFIC UPGRADE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1 # UPDATE A CONFIG FILE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]; then ynh_script_progression --message="Updating a configuration file..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
ynh_add_config --template="config.json5" --destination="$final_path/config.json5" ynh_add_config --template="config.json5" --destination="$final_path/config.json5"
#================================================= chmod 400 "$final_path/config.json5"
# NGINX CONFIGURATION chown $app:$app "$final_path/config.json5"
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username="$app" --home_dir="$final_path"
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# BUILD YARN DEPENDENCIES # BUILD YARN DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Rebuilding Yarn dependencies..." --weight=2 ynh_script_progression --message="Rebuilding Yarn dependencies..." --weight=2
chown -R "$app":"$app" "$final_path" chown -R $app:$app "$final_path"
pushd "$final_path" || return 1 pushd "$final_path" || return 1
ynh_use_nodejs ; set "${ynh_node_load_PATH:?}" ynh_use_nodejs ; set "${ynh_node_load_PATH:?}"
sudo -u "$app" env "$ynh_node_load_PATH" yarn sudo -u $app env "$ynh_node_load_PATH" yarn
sudo -u "$app" env "$ynh_node_load_PATH" yarn build sudo -u $app env "$ynh_node_load_PATH" yarn build
sudo -u "$app" env "$ynh_node_load_PATH" yarn install --production --ignore-scripts --prefer-offline sudo -u $app env "$ynh_node_load_PATH" yarn install --production --ignore-scripts --prefer-offline
yarn_bin_dir="$(sudo -u "$app" env "$ynh_node_load_PATH" yarn global bin)"
popd || return 1 popd || return 1
#================================================= #=================================================
@ -135,8 +145,7 @@ popd || return 1
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
test -n "${ynh_node_load_PATH}${yarn_bin_dir}" ynh_add_systemd_config
ynh_add_systemd_config --others_var="ynh_node_load_PATH yarn_bin_dir"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -145,7 +154,7 @@ ynh_add_systemd_config --others_var="ynh_node_load_PATH yarn_bin_dir"
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage application logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= #=================================================
@ -153,34 +162,14 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app" --description "Wetty Web Terminal service" --log "/var/log/$app/$app.log" yunohost service add $app --description="Wetty Web Terminal service" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting the systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Server started"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
# ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1
# Create a dedicated fail2ban config
# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
# Make app public if necessary
if [ "$is_public" -eq 1 ]; then
ynh_permission_update --permission "main" --add "visitors"
else
ynh_permission_update --permission "main" --remove "visitors"
fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
@ -193,4 +182,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of Wetty completed" --last ynh_script_progression --message="Upgrade of $app completed" --last