From 80b0c62d3d533b469f6a9f9cf283ec5f06f7fdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 8 Feb 2018 17:25:54 +0100 Subject: [PATCH] Add title for each part of code --- README.md | 9 +-------- scripts/_common.sh | 11 ++++++++--- scripts/backup | 10 +++++++++- scripts/change_url | 9 ++++++++- scripts/install | 20 +++++++++++++++++--- scripts/remove | 13 ++++++++----- scripts/restore | 14 +++++++++++++- scripts/upgrade | 40 +++++++++++++++++++++++++--------------- 8 files changed, 89 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 814a390..df5d3a5 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Also, in some cases, Gogs will not restart properly during the update. If so, yo Sources and issues of the old package can be found [here](https://github.com/YunoHost-Apps/gogs_ynh_old/) ## Info -Gogs v0.11.34 +Gogs v0.11.33 - [YunoHost forum thread](https://forum.yunohost.org/t/gogs-package-an-awesome-github-alternative/1127) @@ -78,10 +78,3 @@ sudo yunohost app install -l Gogs /home/admin/gogs_ynh sudo yunohost app upgrade -f /home/admin/gogs_ynh gogs ``` - -## Todo - -- Big comment -- Test multi instance - - diff --git a/scripts/_common.sh b/scripts/_common.sh index 5fac095..c860ea6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,6 +1,7 @@ -# -# Common variables -# +#================================================= +# SET ALL CONSTANTS +#================================================= + app=$YNH_APP_INSTANCE_NAME dbname=$app dbuser=$app @@ -23,6 +24,10 @@ else your hardware and the result of the command \"uname -m\"." 1 fi +#================================================= +# DEFINE ALL COMMON FONCTIONS +#================================================= + create_dir() { mkdir -p "$final_path/data" mkdir -p "$final_path/custom/conf" diff --git a/scripts/backup b/scripts/backup index 98949e6..772fae0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -13,6 +17,10 @@ source ../settings/scripts/_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) +#================================================= +# STANDARD BACKUP STEPS +#================================================= + # Copy the app source files ynh_backup "$final_path" @@ -27,4 +35,4 @@ ynh_backup "/etc/systemd/system/${app}.service" ynh_backup "/var/log/$app" # Dump the database -ynh_mysql_dump_db "$dbname" > ./db.sql +ynh_mysql_dump_db "$dbname" > ./db.sql \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url index d73089c..4e5ff47 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -46,6 +50,10 @@ then change_path=1 fi +#================================================= +# STANDARD MODIFICATIONS +#================================================= + # MODIFY URL IN NGINX CONF nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -65,5 +73,4 @@ config_nginx config_gogs # RELOAD services -systemctl reload nginx systemctl restart "$app".service diff --git a/scripts/install b/scripts/install index c576b67..1578c52 100644 --- a/scripts/install +++ b/scripts/install @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -34,14 +38,20 @@ key=$(ynh_string_random) # Find available ports port=$(ynh_find_port 6000) -# Initialize database and store mysql password for upgrade -ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" +# Store Settings ynh_app_setting_set $app mysqlpwd $dbpass ynh_app_setting_set $app adminusername $admin ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app secret_key $is_public +ynh_app_setting_set $app secret_key $key ynh_app_setting_set $app web_port $port +#================================================= +# STANDARD MODIFICATIONS +#================================================= + +# Initialize database and store mysql password for upgrade +ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" + # Add users ynh_system_user_create $app @@ -77,6 +87,10 @@ ynh_replace_string "__ADMIN__" "$admin" ../conf/login_source.sql ynh_replace_string "__APP__" "$app" ../conf/login_source.sql ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql +#================================================= +# GENERIC FINALIZATION +#================================================= + # Unprotect root from SSO if public if [ "$is_public" = '1' ] then diff --git a/scripts/remove b/scripts/remove index 8265751..681dd01 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -7,10 +11,9 @@ source /usr/share/yunohost/helpers source ./experimental_helper.sh source ./_common.sh -# Set app specific variables -app=$YNH_APP_INSTANCE_NAME -dbname=$app -dbuser=$app +#================================================= +# STANDARD REMOVE +#================================================= # Stop gogs systemctl stop "$app".service @@ -40,4 +43,4 @@ ynh_system_user_delete $app ynh_remove_systemd_config # Remove monitor -yunohost service remove "$app" +yunohost service remove "$app" \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index b4e1b72..6912b66 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -26,6 +30,10 @@ ynh_user_exists "$admin" \ # Check Final Path availability test ! -e "$final_path" || ynh_die "This path already contains a folder" +#================================================= +# STANDARD RESTORATION STEPS +#================================================= + # Add users ynh_system_user_create $app @@ -36,10 +44,14 @@ ynh_restore ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql -# Restore configuration files +# Restore systemd files systemctl daemon-reload systemctl enable "$app".service +#================================================= +# GENERIC FINALIZATION +#================================================= + # Set permissions set_permission diff --git a/scripts/upgrade b/scripts/upgrade index 0b184a6..4e55ace 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,9 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= + # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers @@ -25,6 +29,13 @@ ynh_clean_setup () { ynh_restore_upgradebackup } +# Stop service +systemctl stop "$app".service + +#================================================= +# MIGRATION FROM OLD VERSION +#================================================= + # Update settings is_public to new standard if [ "$is_public" = "Yes" ]; then ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen @@ -34,9 +45,6 @@ elif [ "$is_public" = "No" ]; then is_public=0 fi -# Stop service -systemctl stop "$app".service - if [[ $port == "" ]] then port=$(ynh_find_port 6000) @@ -65,6 +73,17 @@ then fi # end of old package upgrade +# test if user gogs is locked because of an old installation of the package. +# if it's blocked, unlock it to allow ssh usage with git +if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]] +then + usermod -p '*' "$app" +fi + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= + # Clean template to fix issue : https://github.com/gogits/gogs/issues/4585 ynh_secure_remove "/opt/gogs/templates" @@ -80,22 +99,13 @@ ynh_add_systemd_config # Modify Nginx configuration file and copy it to Nginx conf directory config_nginx -# Unprotect root from SSO if public -if [ ! "$is_public" ] -then - ynh_app_setting_set $app unprotected_uris "/" -fi +#================================================= +# GENERIC FINALIZATION +#================================================= # Set permissions set_permission -# test if user gogs is locked because of an old installation of the package. -# if it's blocked, unlock it to allow ssh usage with git -if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]] -then - usermod -p '*' "$app" -fi - # Reload services ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log" sleep 1 \ No newline at end of file