diff --git a/README.md b/README.md index 1ec1940..ea83471 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ sudo yunohost app upgrade -f /home/admin/gogs_ynh gogs ## Todo +- Big comment +- Test multi instance - check migration - change-url diff --git a/check_process b/check_process index 8dc4ba1..4cf9936 100644 --- a/check_process +++ b/check_process @@ -12,8 +12,9 @@ setup_private=1 setup_public=1 upgrade=1 - # upgrade=1 from_commit=a62bce7dbc6bc0e1f1b4e872286ff124747ea009 - # upgrade=1 from_commit=f050f88fbfe7bad1bf74d4584ec62ffcf28248e7 + upgrade=1 from_commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab + upgrade=1 from_commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5 + upgrade=1 from_commit=5a706ed246392c1ce39c47a648cb93e2996e80d3 backup_restore=1 multi_instance=1 incorrect_path=0 @@ -32,7 +33,9 @@ Level 9=0 Level 10=0 ;;; Upgrade options -# ; commit=a62bce7dbc6bc0e1f1b4e872286ff124747ea009 -# name=Before multi_instance -# ; commit=f050f88fbfe7bad1bf74d4584ec62ffcf28248e7 -# name=Old version package + ; commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab + name=Before multi_instance and refactoring + ; commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5 + name=From V0.10.18 + ; commit=5a706ed246392c1ce39c47a648cb93e2996e80d3 + name=The oldest package diff --git a/conf/app.ini b/conf/app.ini index e255c37..2e4e3e8 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,6 +1,6 @@ ;https://github.com/gogits/gogs/blob/master/conf/app.ini APP_NAME = Gogs: Go Git Service -RUN_USER = gogs +RUN_USER = __APP__ RUN_MODE = prod [database] DB_TYPE = mysql @@ -44,7 +44,7 @@ PROVIDER = memory [log] MODE = file LEVEL = Warn -ROOT_PATH = /var/log/gogs +ROOT_PATH = /var/log/__APP__ [security] INSTALL_LOCK = true SECRET_KEY = __KEY__ diff --git a/conf/login_source.sql b/conf/login_source.sql index 401ab25..7454918 100644 --- a/conf/login_source.sql +++ b/conf/login_source.sql @@ -1,3 +1,3 @@ -INSERT INTO `gogs`.`login_source` (`id`, `type`, `name`, `is_actived`, `cfg`, `created_unix`, `updated_unix`) VALUES -('1', '2', 'Yunohost LDAP', '1', '{"Name":"Yunohost LDAP","Host":"localhost","Port":389,"UseSSL":false,"BindDN":"","BindPassword":"","UserBase":"ou=users,dc=yunohost,dc=org","AttributeName":"givenName","AttributeSurname":"sn","AttributeMail":"mail","Filter":"(uid=%s)","AdminFilter":"(uid=yuno_admin)","Enabled":true}', '1464014433', '1464015955') -ON DUPLICATE KEY UPDATE cfg='{"Name":"Yunohost LDAP","Host":"localhost","Port":389,"UseSSL":false,"BindDN":"","BindPassword":"","UserBase":"ou=users,dc=yunohost,dc=org","AttributeName":"givenName","AttributeSurname":"sn","AttributeMail":"mail","Filter":"(uid=%s)","AdminFilter":"(uid=yuno_admin)","Enabled":true}' +INSERT INTO `__APP__`.`login_source` (`id`, `type`, `name`, `is_actived`, `cfg`, `created_unix`, `updated_unix`) VALUES +('1', '2', 'Yunohost LDAP', '1', '{"Name":"Yunohost LDAP","Host":"localhost","Port":389,"UseSSL":false,"BindDN":"","BindPassword":"","UserBase":"ou=users,dc=yunohost,dc=org","AttributeName":"givenName","AttributeSurname":"sn","AttributeMail":"mail","Filter":"(uid=%s)","AdminFilter":"(uid=__ADMIN__)","Enabled":true}', '1464014433', '1464015955') +ON DUPLICATE KEY UPDATE cfg='{"Name":"Yunohost LDAP","Host":"localhost","Port":389,"UseSSL":false,"BindDN":"","BindPassword":"","UserBase":"ou=users,dc=yunohost,dc=org","AttributeName":"givenName","AttributeSurname":"sn","AttributeMail":"mail","Filter":"(uid=%s)","AdminFilter":"(uid=__ADMIN__)","Enabled":true}' diff --git a/conf/systemd.service b/conf/systemd.service index 1c3f0f6..e237439 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -13,12 +13,12 @@ After=slapd.service #LimitMEMLOCK=infinity #LimitNOFILE=65535 Type=simple -User=gogs -Group=gogs -WorkingDirectory=/home/gogs -ExecStart=/opt/gogs/gogs web +User=__APP__ +Group=__APP__ +WorkingDirectory=/home/__APP__ +ExecStart=/opt/__APP__/gogs web Restart=always -Environment=USER=gogs HOME=/home/gogs +Environment=USER=__APP__ HOME=/home/__APP__ [Install] WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index a96d342..328daf0 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "name": "tostaki", "email": "maxime@max.privy.place" }, - "multi_instance": false, + "multi_instance": true, "services": [ "nginx", "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index cbdc919..594991b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -2,9 +2,9 @@ # Common variables # app=$YNH_APP_INSTANCE_NAME -final_path="/opt/$app" dbname=$app dbuser=$app +final_path="/opt/$app" DATADIR="/home/$app" REPO_PATH="$DATADIR/repositories" DATA_PATH="$DATADIR/data" @@ -24,6 +24,7 @@ else fi create_dir() { + mkdir -p "$final_path/data" mkdir -p "$final_path/custom/conf" mkdir -p "$REPO_PATH" mkdir -p "$DATA_PATH/avatars" @@ -58,6 +59,7 @@ config_gogs() { ynh_replace_string "__KEY__" "$key" "$final_path/custom/conf/app.ini" ynh_replace_string "__DATA_PATH__" "$DATA_PATH" "$final_path/custom/conf/app.ini" ynh_replace_string "__PORT__" $port "$final_path/custom/conf/app.ini" + ynh_replace_string "__APP__" $app "$final_path/custom/conf/app.ini" ynh_store_file_checksum "$final_path/custom/conf/app.ini" } diff --git a/scripts/install b/scripts/install index eeac2d9..3656094 100644 --- a/scripts/install +++ b/scripts/install @@ -45,16 +45,9 @@ ynh_app_setting_set $app web_port $port # Add users ynh_system_user_create $app -# id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet -# id -u "$app" &>/dev/null || sudo adduser "$app" \ -# --ingroup "$app" --system --quiet --shell /bin/bash - # create needed directories create_dir -# Create uploads folder and permissions -mkdir /opt/$app/data - # Install Gogs ynh_setup_source $final_path $architecture @@ -80,11 +73,12 @@ do done # Add ldap config -ynh_replace_string "yuno_admin" "$admin" ../conf/login_source.sql +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 # Unprotect root from SSO if public -if [ ! "$is_public" ] +if [ "$is_public" = '1' ] then ynh_app_setting_set $app unprotected_uris "/" fi diff --git a/scripts/restore b/scripts/restore index e71df8b..12ed88f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,11 +10,6 @@ ynh_abort_if_errors source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh -# Set app specific variables -app=${APPNAME:-gogs} -dbname=$app -dbuser=$app - # Retrieve old app settings domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get "$app" path) diff --git a/scripts/upgrade b/scripts/upgrade index ed35d91..dc60399 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source ./_common.sh # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path) +path_url=$(ynh_normalize_url_path $(ynh_app_setting_get "$app" path)) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) admin=$(ynh_app_setting_get "$app" adminusername) key=$(ynh_app_setting_get "$app" secret_key) @@ -20,13 +20,10 @@ is_public=$(ynh_app_setting_get "$app" is_public) port=$(ynh_app_setting_get "$app" web_port) # Backup the current version of the app -if [[ $(ynh_app_setting_get $app disable_backup_before_upgrade) != '1' ]] -then - ynh_backup_before_upgrade - ynh_clean_setup () { - ynh_restore_upgradebackup - } -fi +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_restore_upgradebackup +} # Update settings is_public to new standard if [ "$is_public" = "Yes" ]; then @@ -78,7 +75,7 @@ ynh_add_systemd_config config_nginx # Unprotect root from SSO if public -if [ "$is_public" ] +if [ ! "$is_public" ] then ynh_app_setting_set $app unprotected_uris "/" fi