From bdd2a98b53962f6ae2c3e65f6bbe6be401689e77 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 31 Mar 2020 05:07:19 +0200 Subject: [PATCH] Cleaning of the package, use more modern practices --- manifest.json | 4 ++-- scripts/_common.sh | 31 ------------------------------- scripts/backup | 4 ++-- scripts/install | 24 +++++++++++++----------- scripts/restore | 22 ++++++++++++---------- scripts/upgrade | 16 ++++++++-------- 6 files changed, 37 insertions(+), 64 deletions(-) diff --git a/manifest.json b/manifest.json index f985be0..36a9d44 100644 --- a/manifest.json +++ b/manifest.json @@ -8,14 +8,14 @@ }, "url": "https://github.com/RSS-Bridge/rss-bridge", "license": "Unlicense", - "version": "2020-02-26~ynh1", + "version": "2020-02-26~ynh2", "maintainer": { "name": "JimboJoe", "email": "jimmy@monin.net" }, "multi_instance": true, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.7" }, "services": [ "nginx", diff --git a/scripts/_common.sh b/scripts/_common.sh index d706d3d..c2656dd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -63,10 +63,6 @@ WARNING () { # Print on error output $@ >&2 } -QUIET () { # redirect standard output to /dev/null - $@ > /dev/null -} - CHECK_SIZE () { # Check if enough disk space available on backup storage file_to_analyse=$1 backup_size=$(sudo du --summarize "$file_to_analyse" | cut -f1) @@ -80,32 +76,5 @@ CHECK_SIZE () { # Check if enough disk space available on backup storage fi } -CHECK_USER () { # Check user validity -# $1 = User - ynh_user_exists "$1" || ynh_die "Wrong user" -} -CHECK_DOMAINPATH () { # Check domain/path availability - sudo yunohost app checkurl $domain$path_url -a $app -} -CHECK_FINALPATH () { # Check if destination directory already exists - final_path="/var/www/$app" - test ! -e "$final_path" || ynh_die "This path already contains a folder" -} - -#================================================= -# FUTURE YUNOHOST HELPERS - TO BE REMOVED LATER -#================================================= - -# Normalize the url path syntax -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} diff --git a/scripts/backup b/scripts/backup index 02b2865..272454e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,8 +6,8 @@ if [ ! -e _common.sh ]; then # Fetch helpers file if not in current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers diff --git a/scripts/install b/scripts/install index f06a1f6..a9dc8b5 100644 --- a/scripts/install +++ b/scripts/install @@ -30,9 +30,11 @@ path_url=$YNH_APP_ARG_PATH # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path -CHECK_DOMAINPATH # Check domain and path availability -CHECK_FINALPATH # Check if destination directory is not already in use +final_path=/var/www/$app +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 @@ -65,16 +67,16 @@ ynh_system_user_create $app # Create a dedicated system user #================================================= # Install files and set permissions -sudo mv "$TMPDIR" "$final_path" +mv "$TMPDIR" "$final_path" # Set rights on directory -sudo chown -R root: $final_path -sudo chown -R $app: $final_path/cache -sudo chmod 755 $final_path +chown -R root: $final_path +chown -R $app: $final_path/cache +chmod 755 $final_path # Enable every bridge for i in $final_path/bridges/*.php ; do - echo $(basename $i) | sed "s|Bridge.php$||g" | sudo tee -a $final_path/whitelist.txt + echo $(basename $i) | sed "s|Bridge.php$||g" | tee -a $final_path/whitelist.txt done #================================================= @@ -89,7 +91,7 @@ phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" ynh_replace_string "{POOLNAME}" "${app}" "$PKGDIR/conf/php-fpm.conf" ynh_replace_string "{DESTDIR}" "${final_path}" "$PKGDIR/conf/php-fpm.conf" ynh_replace_string "{USER}" "${app}" "$PKGDIR/conf/php-fpm.conf" -sudo cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf" +cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf" # Set SSOwat rules ynh_app_setting_set "$app" skipped_uris "/" @@ -97,5 +99,5 @@ ynh_app_setting_set "$app" skipped_uris "/" #================================================= # RELOAD NGINX #================================================= -sudo systemctl restart php5-fpm -sudo systemctl reload nginx +systemctl restart php5-fpm +systemctl reload nginx diff --git a/scripts/restore b/scripts/restore index b7baa5c..839c269 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,8 +6,8 @@ if [ ! -e _common.sh ]; then # Fetch helpers file if not in current directory - sudo cp ../settings/scripts/_common.sh ./_common.sh - sudo chmod a+rx _common.sh + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh fi source _common.sh source /usr/share/yunohost/helpers @@ -35,8 +35,10 @@ db_name=$(ynh_app_setting_get $app db_name) # CHECK IF THE APP CAN BE RESTORED #================================================= -CHECK_DOMAINPATH # Check domain and path availability -CHECK_FINALPATH # Check if destination directory is not already in use +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORE STEPS @@ -44,13 +46,13 @@ CHECK_FINALPATH # Check if destination directory is not already in use # RESTORE NGINX CONFIGURATION #================================================= -sudo cp -a ./nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +cp -a ./nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf #================================================= # RESTORE APP MAIN DIR #================================================= -sudo cp -a ./sources/. $final_path +cp -a ./sources/. $final_path #================================================= # RECREATE OF THE DEDICATED USER @@ -62,13 +64,13 @@ ynh_system_user_create $app # Recreate the dedicated user, if not existing # RESTORE USER RIGHTS #================================================= -sudo chown -R $app: $final_path +chown -R $app: $final_path #================================================= # RESTORE PHP-FPM CONFIGURATION #================================================= -sudo cp -a ./php-fpm.conf /etc/php5/fpm/pool.d/$app.conf +cp -a ./php-fpm.conf /etc/php5/fpm/pool.d/$app.conf #================================================= # GENERIC FINALIZATION @@ -76,5 +78,5 @@ sudo cp -a ./php-fpm.conf /etc/php5/fpm/pool.d/$app.conf # RELOAD NGINX AND PHP-FPM #================================================= -sudo systemctl reload php5-fpm -sudo systemctl reload nginx +systemctl reload php5-fpm +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index 09b04e4..5f4b986 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -62,16 +62,16 @@ ynh_system_user_create $app # Create dedicated user if not existing ynh_secure_remove "$final_path" # Install files and set permissions -sudo mv "$TMPDIR" "$final_path" +mv "$TMPDIR" "$final_path" # Set rights on directory -sudo chown -R root: $final_path -sudo chown -R $app: $final_path/cache -sudo chmod 755 $final_path +chown -R root: $final_path +chown -R $app: $final_path/cache +chmod 755 $final_path # Enable every bridge for i in $final_path/bridges/*.php ; do - echo $(basename $i) | sed "s|Bridge.php$||g" | sudo tee -a $final_path/whitelist.txt + echo $(basename $i) | sed "s|Bridge.php$||g" | tee -a $final_path/whitelist.txt done #================================================= @@ -86,7 +86,7 @@ phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" ynh_replace_string "{POOLNAME}" "${app}" "$PKGDIR/conf/php-fpm.conf" ynh_replace_string "{DESTDIR}" "${final_path}" "$PKGDIR/conf/php-fpm.conf" ynh_replace_string "{USER}" "${app}" "$PKGDIR/conf/php-fpm.conf" -sudo cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf" +cp $PKGDIR/conf/php-fpm.conf "$phpfpm_conf" # Set SSOwat rules @@ -95,5 +95,5 @@ ynh_app_setting_set "$app" skipped_uris "/" #================================================= # RELOAD NGINX #================================================= -sudo systemctl restart php5-fpm -sudo systemctl reload nginx \ No newline at end of file +systemctl restart php5-fpm +systemctl reload nginx