From 639f95aa633eff762a90bc42ec247874d7bb1ecc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Wed, 4 Oct 2017 15:22:54 +0200 Subject: [PATCH] Code cleanup --- conf/{cron_weblate => cron} | 0 scripts/_common.sh | 4 ++-- scripts/backup | 7 +++---- scripts/install | 6 ++---- scripts/remove | 8 +++----- scripts/restore | 9 ++++----- scripts/upgrade | 31 ++++++++++++++----------------- 7 files changed, 28 insertions(+), 37 deletions(-) rename conf/{cron_weblate => cron} (100%) diff --git a/conf/cron_weblate b/conf/cron similarity index 100% rename from conf/cron_weblate rename to conf/cron diff --git a/scripts/_common.sh b/scripts/_common.sh index 12b903f..88b232f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,7 +10,7 @@ ynh_psql_test_if_first_run() { systemctl start postgresql su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres # we can't use peer since YunoHost create users with nologin - sed -i '/local\s*all\s*all\s*peer/i \ + sed -i '/local\s*all\s*all\s*peer/i local all all password' /etc/postgresql/9.4/main/pg_hba.conf systemctl enable postgresql systemctl reload postgresql @@ -51,7 +51,7 @@ ynh_psql_execute_as_root () { ynh_psql_execute_file_as_root() { file="$1" db="$2" - su -c "psql $db" postgres < $file + su -c "psql $db" postgres < "$file" } # Create a database, an user and its password. Then store the password in the app's config diff --git a/scripts/backup b/scripts/backup index 8336b50..4a235ff 100755 --- a/scripts/backup +++ b/scripts/backup @@ -27,10 +27,9 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app pgsqlpwd) +final_path=$(ynh_app_setting_get "$app" final_path) +domain=$(ynh_app_setting_get "$app" domain) +db_name=$(ynh_app_setting_get "$app" db_name) #================================================= # STANDARD BACKUP STEPS diff --git a/scripts/install b/scripts/install index f3badc0..6264ff3 100755 --- a/scripts/install +++ b/scripts/install @@ -107,7 +107,6 @@ ynh_add_nginx_config #================================================= # Hub needs a home directory with a config file -smtp_pwd=$(ynh_string_random) ynh_system_user_create "$app" "$final_path" # Allow bash for our user, so he can use Hub chsh --shell /bin/bash "$app" @@ -139,7 +138,7 @@ case "$arch" in ;; esac -[[ $(sha256sum "$file_bin" | cut -d' ' -f1) = $sha256sum ]] || ynh_die "Hub's sha256sum failed (arch: ${arch})" +[[ $(sha256sum "$file_bin" | cut -d' ' -f1) = "$sha256sum" ]] || ynh_die "Hub's sha256sum failed (arch: ${arch})" tar --extract --file "$file_bin" "$version/bin/hub" mkdir "$final_path/bin/" @@ -207,7 +206,6 @@ ynh_replace_string "__DOMAIN__" "$domain" "$final_path/venv/lib/python2.7 ynh_replace_string "__KEY__" "$key" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__PATHURL__" "$path_url" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" -ynh_replace_string "__SMTPPWD__" "$smtp_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__MEMCPORT__" "$memc_port" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__GITHUBUSER__" "$github_account" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" @@ -233,7 +231,7 @@ ynh_replace_string "__GITHUBUSER__" "$github_account" "$final_path/venv/lib/pyth #================================================= # SETUP CRON #================================================= -cp ../conf/cron_weblate "/etc/cron.d/$app" +cp ../conf/cron "/etc/cron.d/$app" ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app" #================================================= diff --git a/scripts/remove b/scripts/remove index 21d9f2a..0b246a4 100755 --- a/scripts/remove +++ b/scripts/remove @@ -5,7 +5,7 @@ #================================================= # IMPORT GENERIC HELPERS #================================================= -set -eu +set -u source _common.sh source /usr/share/yunohost/helpers @@ -15,9 +15,7 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) +db_name=$(ynh_app_setting_get "$app" db_name) #================================================= # REMOVE SERVICE FROM ADMIN PANEL @@ -87,4 +85,4 @@ ynh_secure_remove "/etc/systemd/system/$app.service" #================================================= # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete "$app" diff --git a/scripts/restore b/scripts/restore index e25c093..f0909a6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -27,12 +27,11 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get "$app" domain) +path_url=$(ynh_app_setting_get "$app" path) +final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_app_setting_get "$app" db_name) db_pwd=$(ynh_app_setting_get "$app" psqlpwd) -smtp_pwd=$(ynh_app_setting_get $app smtppwd) #================================================= # CHECK IF THE APP CAN BE RESTORED diff --git a/scripts/upgrade b/scripts/upgrade index 4cebee9..72ec4db 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,30 +15,27 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) -smtp_pwd=$(ynh_app_setting_get $app smtppwd) +path_url=$(ynh_app_setting_get "$app" path) +is_public=$(ynh_app_setting_get "$app" is_public) +final_path=$(ynh_app_setting_get "$app" final_path) +db_name=$(ynh_app_setting_get "$app" db_name) +domain=$(ynh_app_setting_get "$app" domain) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value + ynh_app_setting_set "$app" is_public 1 # Fix is_public as a boolean value is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set "$app" is_public 0 is_public=0 fi -if [ -z $db_name ]; then # If db_name doesn't exist, create it - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name +if [ -z "$db_name" ]; then # If db_name doesn't exist, create it + db_name=$(ynh_sanitize_dbid "$app") + ynh_app_setting_set "$app" db_name "$db_name" fi #================================================= @@ -46,7 +43,7 @@ fi #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path "$path_url") #================================================= # STANDARD UPGRADE STEPS @@ -92,7 +89,7 @@ chsh --shell /bin/bash "$app" set +eu source ${final_path}/venv/bin/activate export DJANGO_SETTINGS_MODULE="weblate.settings" - cd ${final_path} + cd "${final_path}" weblate migrate --noinput ) @@ -118,13 +115,13 @@ ynh_use_logrotate if [ $is_public -eq 0 ] then # Remove the public access - ynh_app_setting_delete $app skipped_uris + ynh_app_setting_delete "$app" skipped_uris fi # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set "$app" unprotected_uris "/" fi #=================================================