From 9e31857051cae3eba58f74c32297e586f39cf45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 15 Aug 2023 17:19:52 +0200 Subject: [PATCH] cleaning --- scripts/_common.sh | 20 -------------- scripts/install | 66 +++++----------------------------------------- scripts/remove | 32 ---------------------- scripts/restore | 42 +++-------------------------- scripts/upgrade | 56 +++++++-------------------------------- tests.toml | 7 +++++ 6 files changed, 25 insertions(+), 198 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 7661ed3..ebb9161 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,26 +8,6 @@ # PERSONAL HELPERS #================================================= -# custom function to detect armv6 and armv7 -# ($YNH_ARCH returns armhf for both...) -detect_arch(){ - local architecture - if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then - architecture="arm64" - elif [ -n "$(uname -m | grep 64)" ]; then - architecture="x86-64" - elif [ -n "$(uname -m | grep 86)" ]; then - architecture="i386" - elif [ -n "$(uname -m | grep armv6)" ]; then - architecture="armv6" - elif [ -n "$(uname -m | grep armv7)" ]; then - architecture="armv7" - else - architecture="unknown" - fi - echo $architecture -} - # custom function to change bash bool 0/1 to false/true convert_bool(){ (("$1")) && echo "true" || echo "false" diff --git a/scripts/install b/scripts/install index e9fd918..ed86b8d 100644 --- a/scripts/install +++ b/scripts/install @@ -148,23 +148,9 @@ ynh_app_setting_set --app="$app" --key=advanced_rate_limit_requests --value="$ad #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - -# detect_arch comes from _common.sh / personnal helpers -architecture=$(detect_arch) - # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --source_id="$architecture" +ynh_setup_source --dest_dir="$install_dir" -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder _ -# this will be treated as a security issue. -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" @@ -176,25 +162,13 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config for the main domain ynh_add_nginx_config -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." --weight=1 +# Create a dedicated systemd config +ynh_add_systemd_config -#REMOVEME? data_dir=/home/yunohost.app/$app -#REMOVEME? ynh_app_setting_set --app="$app" --key=data_dir --value="$data_dir" +# Use logrotate to manage application logfile(s) +ynh_use_logrotate -mkdir -p "$data_dir" - -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$data_dir" -chmod -R o-rwx "$data_dir" -chown -R "$app:www-data" "$data_dir" +yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" #================================================= # ADD A CONFIGURATION @@ -203,37 +177,9 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" -# FIXME: this should be handled by the core in the future -# You may need to use chmod 600 instead of 400, -# for example if the app is expected to be able to modify its own config chmod 400 "$install_dir/config.yaml" chown "$app:$app" "$install_dir/config.yaml" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" - #================================================= # CREATE ADMIN USER #================================================= diff --git a/scripts/remove b/scripts/remove index 93193fe..434361b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -22,47 +22,15 @@ then yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - # Remove the dedicated NGINX config of the main domain ynh_remove_nginx_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." --weight=1 - ynh_exec_warn_less yunohost firewall disallow TCP "$port" -fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." --weight=1 - # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index fe634a1..722059f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,15 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -26,13 +17,6 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" @@ -43,25 +27,13 @@ ynh_script_progression --message="Restoring the data directory..." --weight=5 ynh_restore_file --origin_path="$data_dir" --not_mandatory -mkdir -p "$data_dir" - -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$data_dir" -chmod -R o-rwx "$data_dir" chown -R "$app:www-data" "$data_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -#REMOVEME? #REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 -#REMOVEME? #REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? #REMOVEME? ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" @@ -72,21 +44,13 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" # RESTORE VARIOUS FILES #================================================= -mkdir -p "/var/log/$app" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +mkdir -p "/var/log/$app" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3d4adc4..2bfa99c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,12 +13,6 @@ source /usr/share/yunohost/helpers # CHECK VERSION #================================================= -### This helper will compare the version of the currently installed app and the version of the upstream package. -### $upgrade_type can have 2 different values -### - UPGRADE_APP if the upstream app version has changed -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### ynh_check_app_version_changed will stop the upgrade if the app is up to date. -### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -228,16 +222,9 @@ then architecture=$(detect_arch) # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --source_id="$architecture" --keep="config.yaml" + ynh_setup_source --dest_dir="$install_dir" --keep="config.yaml" fi -# FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" @@ -249,49 +236,24 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." # Create a dedicated NGINX config for the main domain ynh_add_nginx_config +# Create a dedicated systemd config +ynh_add_systemd_config + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" + #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." -### Same as during install -### -### The file will automatically be backed-up if it's found to be manually modified (because -### ynh_add_config keeps track of the file's checksum) - ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" -# FIXME: this should be handled by the core in the future -# You may need to use chmod 600 instead of 400, -# for example if the app is expected to be able to modify its own config chmod 400 "$install_dir/config.yaml" chown "$app:$app" "$install_dir/config.yaml" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/tests.toml b/tests.toml index e69de29..91daf17 100644 --- a/tests.toml +++ b/tests.toml @@ -0,0 +1,7 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ \ No newline at end of file