1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/thelounge_ynh.git synced 2024-09-03 20:35:54 +02:00

Apply last example_ynh

This commit is contained in:
yalh76 2020-05-30 19:18:05 +02:00
parent 4968b15075
commit b97fafcd5b
7 changed files with 141 additions and 157 deletions

View file

@ -56,7 +56,6 @@
}, },
"default": true "default": true
} }
] ]
} }
} }

View file

@ -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
@ -19,7 +20,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info --message="Backing up The Lounge..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
@ -27,11 +28,17 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path) config_path=$(ynh_app_setting_get --app=$app --key=config_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
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path=$final_path ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
@ -39,12 +46,6 @@ ynh_backup --src_path=$final_path
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
@ -55,7 +56,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# BACKUP CONFIG # BACKUP CONFIG
#================================================= #=================================================
ynh_backup --src_path=$config_path ynh_backup --src_path="$config_path"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -104,4 +104,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression --message="Change of URL completed for $app"

View file

@ -16,7 +16,6 @@ source /usr/share/yunohost/helpers
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -36,28 +35,11 @@ ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
config_path=/home/yunohost.app/$app config_path=/home/yunohost.app/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# 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
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..."
# Find a free port
port=$(ynh_find_port 9000)
ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
@ -66,16 +48,26 @@ ynh_script_progression --message="Storing installation settings..."
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 ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_app_setting_set --app=$app --key=config_path --value=$config_path ynh_app_setting_set --app=$app --key=config_path --value=$config_path
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..."
# Find an available port
port=$(ynh_find_port 9000)
ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." ynh_script_progression --message="Installing dependencies..."
# Install Nodejs # Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_install_nodejs --nodejs_version=$nodejs_version
# Install Yarn # Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
@ -85,16 +77,34 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." ynh_script_progression --message="Setting up source files..."
mkdir -p $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
mkdir -p $config_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
#================================================= #=================================================
# COPY A CONFIG FILE # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC SETUP
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..."
mkdir -p $config_path
# Main config File # Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js"
@ -109,27 +119,10 @@ ynh_store_file_checksum "$config_path/config.js"
ynh_script_progression --message="Installing The Lounge..." ynh_script_progression --message="Installing The Lounge..."
pushd $final_path pushd $final_path
yarn install
yarn install && ynh_exec_warn_less NODE_ENV=production yarn build ynh_exec_warn_less NODE_ENV=production yarn build
popd popd
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
@ -142,25 +135,23 @@ ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path
ynh_add_systemd_config ynh_add_systemd_config
yunohost service add $app --description "Self-hosted web IRC client" --log "/var/log/$app/$app.log"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Securing files and directories..."
# Set permissions to app files # Set permissions to app files
chown -R $app: $final_path chown -R $app: $final_path
chown -R $app: $config_path chown -R $app: $config_path
#================================================= #=================================================
# SETUP LOGROTATE # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." ynh_script_progression --message="Integrating service in YunoHost..."
# Use logrotate to manage application logfile(s) yunohost service add $app --description "Self-hosted web IRC client" --log_type "systemd"
ynh_use_logrotate
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -189,4 +180,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression --message="Installation of $app completed"

View file

@ -24,10 +24,10 @@ config_path=$(ynh_app_setting_get --app=$app --key=config_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
# Remove a service from the admin panel, added by `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 if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service..." ynh_script_progression --message="Removing $app service..."
@ -53,12 +53,10 @@ ynh_remove_nodejs
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing $app main directory..." ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file=$final_path ynh_secure_remove --file="$final_path"
ynh_secure_remove --file=$config_path
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
@ -69,12 +67,13 @@ ynh_script_progression --message="Removing nginx web server configuration..."
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # SPECIFIC REMOVE
#================================================= #=================================================
ynh_script_progression --message="Removing logrotate configuration..." # REMOVE THE CONFIG FILE
#=================================================
ynh_script_progression --message="Removing the config file..."
# Remove the app-specific logrotate config ynh_secure_remove --file="$config_path"
ynh_remove_logrotate
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -90,4 +89,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression --message="Removal of $app completed"

View file

@ -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
@ -16,7 +17,6 @@ source /usr/share/yunohost/helpers
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -47,6 +47,7 @@ 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"
@ -55,7 +56,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path=$final_path ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
@ -65,6 +66,15 @@ ynh_script_progression --message="Recreating the dedicated system user..."
# 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
#=================================================
# RESTORE USER RIGHTS
#=================================================
ynh_script_progression --message="Restoring user rights..."
# Restore permissions to app files
chown -R $app: $final_path
chown -R $app: $config_path
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
@ -83,15 +93,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#================================================= #=================================================
ynh_script_progression --message="Restoring the config path..." ynh_script_progression --message="Restoring the config path..."
ynh_restore_file --origin_path=$config_path ynh_restore_file --origin_path="$config_path"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions to app files
chown -R $app: $final_path
chown -R $app: $config_path
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
@ -99,14 +101,14 @@ chown -R $app: $config_path
ynh_script_progression --message="Restoring the systemd configuration..." ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log "/var/log/$app/$app.log" yunohost service add $app --description "Self-hosted web IRC client" --log_path="systemd" --line_match="Available at http"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -115,12 +117,6 @@ ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Available at http" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Available at http"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -134,4 +130,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression --message="Restoration completed for $app"

View file

@ -26,6 +26,7 @@ port=$(ynh_app_setting_get --app=$app --key=port)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
@ -75,7 +76,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# Normalize the URL path syntax # Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path --path_url=$path_url)
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
@ -97,40 +98,7 @@ then
ynh_secure_remove --file=$final_path ynh_secure_remove --file=$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"
fi
#=================================================
# COPY A CONFIG FILE
#=================================================
# Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js"
cp -a ../conf/config.js "$config_path"
#=================================================
# UPGRADE NODEJS AND YARN
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# UPGRADE THE LOUNGE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
pushd $final_path
yarn install && ynh_exec_warn_less NODE_ENV=production yarn build
popd
fi fi
#================================================= #=================================================
@ -141,18 +109,55 @@ ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a system user # Create a dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username=$app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADE THE LOUNGE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading the lounge..."
pushd $final_path
yarn install && ynh_exec_warn_less NODE_ENV=production yarn build
popd
fi
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..."
ynh_backup_if_checksum_is_different --file="$config_path"
# Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js"
cp -a ../conf/config.js "$config_path"
ynh_store_file_checksum "$config_path/config.js"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." ynh_script_progression --message="Upgrading systemd configuration..."
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
@ -161,39 +166,32 @@ ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path
ynh_add_systemd_config ynh_add_systemd_config
yunohost service add $app --description "Self-hosted web IRC client" --log "/var/log/$app/$app.log"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different --file="$config_path/config.js"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$config_path/config.js"
cp -a ../conf/config.js "$config_path"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression --message="Securing files and directories..."
# Set right permissions for curl installation # Set permissions on app files
chown -R $app: $final_path chown -R $app: $final_path
chown -R $app: $config_path chown -R $app: $config_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..."
# Make app public if necessary or protect it
[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "Self-hosted web IRC client" --log_type "systemd"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
@ -212,4 +210,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed"