From ed03f31812f13c0b5e916b0e6ab55660839ac328 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 16 May 2021 18:15:51 +0200 Subject: [PATCH] Apply last example_ynh --- check_process | 11 ++-- scripts/_common.sh | 5 +- scripts/backup | 18 +++---- scripts/install | 103 +++++++++++++++++++------------------ scripts/remove | 34 ++++++++----- scripts/restore | 66 ++++++++++++------------ scripts/upgrade | 124 +++++++++++++++++++++++---------------------- 7 files changed, 189 insertions(+), 172 deletions(-) diff --git a/check_process b/check_process index d4f8799..9184984 100644 --- a/check_process +++ b/check_process @@ -1,19 +1,14 @@ -# 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 minetest_game ; Manifest - domain="domain.tld" (DOMAIN) + domain="domain.tld" pvp=1 servername="packagecheck" game="minetest_game" creative=0 damage=1 - is_public=0 (PUBLIC|public=1|private=0) + is_public=0 password="pass" - port="30000" (PORT) + port="30000" ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/scripts/_common.sh b/scripts/_common.sh index eba6ffc..30c621b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,4 +1,3 @@ - #!/bin/bash #================================================= @@ -8,6 +7,10 @@ # dependencies used by the app pkg_dependencies="build-essential libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev libluajit-5.1-dev" +#================================================= +# PERSONAL HELPERS +#================================================= + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index a211def..d65b5ee 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,9 +15,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action + ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -42,12 +41,6 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" -#================================================= -# BACKUP THE HOME DIR -#================================================= - -ynh_backup --src_path="$home_path" - #================================================= # SPECIFIC BACKUP #================================================= @@ -62,7 +55,14 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# BACKUP THE HOME DIR +#================================================= + +ynh_backup --src_path="$home_path" --is_big + #================================================= # END OF SCRIPT #================================================= + ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 397b246..acd0eb2 100755 --- a/scripts/install +++ b/scripts/install @@ -14,9 +14,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action + ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -25,6 +24,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN +path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC game=$YNH_APP_ARG_GAME pvp=$YNH_APP_ARG_PVP @@ -33,7 +33,6 @@ damage=$YNH_APP_ARG_DAMAGE servername=$YNH_APP_ARG_SERVERNAME app=$YNH_APP_INSTANCE_NAME -path_url="/" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -41,7 +40,10 @@ path_url="/" ynh_script_progression --message="Validating installation parameters..." final_path=/opt/yunohost/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +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 @@ -51,7 +53,6 @@ ynh_script_progression --message="Storing installation settings..." 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=game --value=$game -ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=pvp --value=$pvp ynh_app_setting_set --app=$app --key=creative --value=$creative ynh_app_setting_set --app=$app --key=damage --value=$damage @@ -64,11 +65,12 @@ ynh_app_setting_set --app=$app --key=servername --value=$servername #================================================= ynh_script_progression --message="Finding an available port..." -# Find a free port +# Find an available port port=$(ynh_find_port 30000) -# Open this port -ynh_exec_warn_less yunohost firewall allow --no-upnp UDP $port ynh_app_setting_set --app=$app --key=port --value=$port +# Open the port +ynh_script_progression --message="Configuring firewall..." +ynh_exec_warn_less yunohost firewall allow --no-upnp UDP $port #================================================= # INSTALL DEPENDENCIES @@ -77,15 +79,6 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_script_progression --message="Setting up source files..." - -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" - #================================================= # CREATE DEDICATED USER #================================================= @@ -97,9 +90,30 @@ ynh_app_setting_set --app=$app --key=home_path --value=$home_path # Create a system user ynh_system_user_create --username=$app --home_dir=$home_path --use_shell +mkdir -p "$home_path" +chmod 750 "$home_path" +chmod -R o-rwx "$home_path" +chown -R $app:$app "$home_path" + #================================================= -# COPY CONFIG FILE +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." + +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" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# SPECIFIC SETUP +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." mkdir -p $home_path/.minetest/worlds/ cp -a ../conf/minetest.conf $home_path/.minetest/ @@ -113,28 +127,31 @@ ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config #================================================= -# SPECIFIC SETUP +# BUILDING #================================================= +ynh_script_progression --message="Building Minetest..." + # Compile Minetest pushd /opt/yunohost/$app -# Install the game -if [ $game = "capturetheflag" ]; then -git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag -else -# Download Minetest Game -ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game -fi + # Install the game + if [ $game = "capturetheflag" ]; then + git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag + else + # Download Minetest Game + ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game + fi -cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE + cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE -make -j$(nproc) + make -j$(nproc) popd #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_script_progression --message="Adding a configuration file..." ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) @@ -143,37 +160,23 @@ popd if [ $is_public -eq 1 ]; then announce="true" else - announce="fase" + announce="false" fi ynh_add_config --template="../conf/minetest.conf" --destination="$home_path/.minetest/minetest.conf" #================================================= -# CREATE WORLD +# CREATE LOG DIRECTORY #================================================= +ynh_script_progression --message="Creating log directory..." mkdir -p /var/log/$app # Set permissions on logs chown -R $app:$app /var/log/$app -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$home_path/.minetest/minetest.conf" - #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R root: $final_path -chown -R $app: $home_path - #================================================= # SETUP LOGROTATE #================================================= @@ -183,20 +186,22 @@ ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= -# RELOAD MINETEST +# START SYSTEMD SERVICE #================================================= -ynh_print_info --message="Reloading Minetest..." +ynh_script_progression --message="Starting a systemd service..." +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/minetest.log" --line_match="listening on" #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index f67f958..a4dfeb7 100755 --- a/scripts/remove +++ b/scripts/remove @@ -23,20 +23,20 @@ home_path=$(ynh_app_setting_get --app=$app --key=home_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status $app >/dev/null 2>&1 +# 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 - ynh_script_progression --message="Removing $app service" + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service" +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config @@ -44,7 +44,7 @@ ynh_remove_systemd_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies" +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -52,19 +52,15 @@ ynh_remove_app_dependencies #================================================= # 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 ynh_secure_remove --file="$final_path" -ynh_secure_remove --file="$home_path" - -# Remove the log files -ynh_secure_remove "/var/log/$app" #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration" +ynh_script_progression --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate @@ -79,12 +75,24 @@ then ynh_exec_warn_less yunohost firewall disallow UDP $port fi +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." + +ynh_secure_remove --file="$home_path" + +# Remove the log files +ynh_secure_remove --file="/var/log/$app" + #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user" +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app diff --git a/scripts/restore b/scripts/restore index 686b6b4..90c086d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,16 +15,15 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action + ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -35,13 +34,6 @@ port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." - -ynh_restore_file --origin_path="$final_path" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -50,16 +42,16 @@ ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$home_path --use_shell -# Restore home_path -ynh_restore_file --origin_path="$home_path" - #================================================= -# RESTORE USER RIGHTS +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." -# Restore permissions on app files -chown -R root: $final_path -chown -R $app: $home_path +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" #================================================= # SPECIFIC RESTORATION @@ -71,6 +63,22 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# RESTORE VARIOUS FILES +#================================================= +ynh_script_progression --message="Restoring various files..." + +# Restore home_path +ynh_restore_file --origin_path="$home_path" --not_mandatory + +mkdir -p "$home_path" +chmod 750 "$home_path" +chmod -R o-rwx "$home_path" +chown -R $app:$app "$home_path" + +mkdir /var/log/$app -p +chown -R $app: /var/log/$app + #================================================= # RESTORE SYSTEMD #================================================= @@ -79,13 +87,6 @@ ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -mkdir /var/log/$app -p -chown -R $app: /var/log/$app - #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -93,21 +94,22 @@ ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/minetest.log" --line_match="listening on" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION -#================================================= -# RELOAD MINETEST -#================================================= -ynh_script_progression --message="Reloading minetest..." - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="listening on" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index bba5fe3..4eb9921 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,14 +25,39 @@ pvp=$(ynh_app_setting_get --app=$app --key=pvp) creative=$(ynh_app_setting_get --app=$app --key=creative) damage=$(ynh_app_setting_get --app=$app --key=damage) servername=$(ynh_app_setting_get --app=$app --key=servername) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_clean_check_starting + + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action="stop" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -66,23 +91,13 @@ if ynh_legacy_permissions_exists; then fi #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Making sure dedicated system user exists..." -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting # Need for the param line_match of ynh_systemd_action +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$home_path --use_shell - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -99,6 +114,10 @@ then ynh_setup_source --dest_dir="$final_path" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -106,22 +125,6 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$home_path --use_shell - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config -ynh_add_systemd_config - #================================================= # COPY CONFIG FILE #================================================= @@ -139,29 +142,29 @@ fi #================================================= # Compile Minetest pushd /opt/yunohost/$app -# Install the game -if [ $game = "capturetheflag" ]; then -# Download Capture The Flag + # Install the game + if [ $game = "capturetheflag" ]; then + # Download Capture The Flag -# To avoid mess remove this first -ynh_secure_remove games/capturetheflag/ -# Then clone the latest version from git -git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag -else -# Download Minetest Game -ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game -fi + # To avoid mess remove this first + ynh_secure_remove games/capturetheflag/ + # Then clone the latest version from git + git clone --recursive https://github.com/MT-CTF/capturetheflag.git games/capturetheflag + else + # Download Minetest Game + ynh_setup_source --dest_dir=/opt/yunohost/$app/games/minetest_game --source_id=minetest_game + fi -cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE + cmake . -DRUN_IN_PLACE=TRUE -DENABLE_LUAJIT=TRUE -DBUILD_CLIENT=FALSE -DBUILD_SERVER=TRUE -make -j$(nproc) + make -j$(nproc) popd #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= - +ynh_script_progression --message="Updating a configuration file..." if [ $is_public -eq 1 ]; then announce="true" else @@ -170,6 +173,16 @@ fi ynh_add_config --template="../conf/minetest.conf" --destination="$home_path/.minetest/minetest.conf" +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configuration..." + +# Create a dedicated systemd config +ynh_add_systemd_config + +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= @@ -179,27 +192,18 @@ ynh_script_progression --message="Upgrading logrotate configuration..." ynh_use_logrotate --non-append #================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions on app files -chown -R root: $final_path -chown -R $app: $home_path - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description="Voxel game engine and game" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port" #================================================= -# RELOAD MINETEST +# START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Restarting Minetest..." +ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/$app/$app.log" --line_match="listening on" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="listening on" #================================================= # END OF SCRIPT