From 9765472e1ac1df198324575806303d120133cbf5 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 10 Apr 2020 23:13:33 +0200 Subject: [PATCH] Testing (#21) * Upgrade to upstream version 2020-02-26 * Cleaning of the package, use more modern practices * More tweaks to make package linter happier Co-authored-by: Jimmy Monin --- manifest.json | 4 ++-- scripts/_common.sh | 37 +++---------------------------------- scripts/backup | 7 +------ scripts/change_url | 4 ++-- scripts/install | 24 +++++++++++++----------- scripts/remove | 6 ++---- scripts/restore | 25 +++++++++++-------------- scripts/upgrade | 16 ++++++++-------- 8 files changed, 42 insertions(+), 81 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..0b96083 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -31,7 +31,7 @@ exec_as() { eval $@ else # use sudo twice to be root and be allowed to use another user - sudo sudo -u "$USER" "$@" + sudo -u "$USER" "$@" fi } @@ -63,14 +63,10 @@ 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) - free_space=$(sudo df --output=avail "/home/yunohost.backup" | sed 1d) + backup_size=$(du --summarize "$file_to_analyse" | cut -f1) + free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d) if [ $free_space -le $backup_size ] then @@ -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..76fd1be 100644 --- a/scripts/backup +++ b/scripts/backup @@ -4,12 +4,7 @@ # IMPORT GENERIC HELPERS #================================================= -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 -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/change_url b/scripts/change_url index 7499f2b..452bbdb 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -79,7 +79,7 @@ fi if [ $change_domain -eq 1 ] then ynh_delete_file_checksum "$nginx_conf_path" - sudo 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 ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi @@ -90,4 +90,4 @@ fi # RELOAD NGINX #================================================= -sudo systemctl reload nginx +systemctl reload nginx 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/remove b/scripts/remove index 4f370d4..a996d89 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,7 +19,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) -domain=$(ynh_app_setting_get "$app" domain) #================================================= # STANDARD REMOVE @@ -34,10 +33,9 @@ ynh_secure_remove "/var/www/$app" #================================================= # REMOVE NGINX AND PHP-FPM CONFIGURATION #================================================= -# Delete app directory and configurations -ynh_secure_remove --file="/var/www/${app}" + ynh_secure_remove --file="/etc/php5/fpm/pool.d/${app}.conf" -[[ -n $domain ]] && sudo ynh_secure_remove --file="/etc/nginx/conf.d/${domain}.d/${app}.conf" +ynh_secure_remove --file="/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services systemctl restart php5-fpm diff --git a/scripts/restore b/scripts/restore index b7baa5c..fb9dda4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -4,12 +4,7 @@ # IMPORT GENERIC HELPERS #================================================= -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 -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -35,8 +30,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 +41,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 +59,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 +73,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