mirror of
https://github.com/YunoHost-Apps/gogs_ynh.git
synced 2024-09-03 20:36:23 +02:00
Refactoring
- Use new helpers - Fix upgrade from old version - Add change_url script - Add multi-instance support - Add checkprocess - Add title for each part of code - Use ynh_check_starting to wait until the service is started - Remove sudo in all command
This commit is contained in:
commit
36a8e2b30e
19 changed files with 545 additions and 314 deletions
10
README.md
10
README.md
|
@ -3,6 +3,10 @@
|
|||
Gogs is a self-hosted Git service written in Go. Alternative to Github.
|
||||
- [Gogs website](http://gogs.io)
|
||||
|
||||
[![Integration level](https://dash.yunohost.org/integration/gogs.svg)](https://ci-apps.yunohost.org/jenkins/job/gogs%20%28Community%29/lastBuild/consoleFull)
|
||||
|
||||
[![Install Gogs with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=gogs)
|
||||
|
||||
## Requirements
|
||||
A functional instance of [YunoHost](https://yunohost.org)
|
||||
|
||||
|
@ -44,12 +48,16 @@ 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
|
||||
Gogs v0.11.33
|
||||
|
||||
- [YunoHost forum thread](https://forum.yunohost.org/t/gogs-package-an-awesome-github-alternative/1127)
|
||||
|
||||
Architecture: this package is compatible with amd64, i386 and arm. The package will try to detect it with the command uname -m and fail if it can't detect the architecture. If that happens please open an issue describing your hardware and the result of the command `uname -m`.
|
||||
|
||||
## Issue
|
||||
|
||||
Any issue is welcome here : https://github.com/YunoHost-Apps/gogs_ynh/issues
|
||||
|
||||
## License
|
||||
Gogs is published under the MIT License:
|
||||
https://github.com/gogits/gogs/blob/master/LICENSE
|
||||
|
|
41
check_process
Normal file
41
check_process
Normal file
|
@ -0,0 +1,41 @@
|
|||
;; General
|
||||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
path="/path" (PATH)
|
||||
admin="john" (USER)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
setup_root=1
|
||||
setup_nourl=0
|
||||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
upgrade=1 from_commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab
|
||||
upgrade=1 from_commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5
|
||||
upgrade=1 from_commit=5a706ed246392c1ce39c47a648cb93e2996e80d3
|
||||
backup_restore=1
|
||||
multi_instance=1
|
||||
incorrect_path=0
|
||||
port_already_use=1 (6000)
|
||||
change_url=1
|
||||
;;; Levels
|
||||
Level 1=auto
|
||||
Level 2=auto
|
||||
Level 3=auto
|
||||
# https://github.com/YunoHost-Apps/gogs_ynh/blob/master/conf/login_source.sql
|
||||
Level 4=1
|
||||
Level 5=auto
|
||||
Level 6=auto
|
||||
Level 7=auto
|
||||
Level 8=0
|
||||
Level 9=0
|
||||
Level 10=0
|
||||
;;; Upgrade options
|
||||
; commit=aa075b2051ffad7b0b6fef3a9c767376d5bdbfab
|
||||
name=Before multi_instance and refactoring
|
||||
; commit=1cbec051e1171de5a8ed1e850eb4fb3506114da5
|
||||
name=From V0.10.18
|
||||
; commit=5a706ed246392c1ce39c47a648cb93e2996e80d3
|
||||
name=The oldest package
|
28
conf/app.ini
28
conf/app.ini
|
@ -1,31 +1,31 @@
|
|||
;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
|
||||
HOST = 127.0.0.1:3306
|
||||
NAME = yuno_dbuser
|
||||
USER = yuno_dbuser
|
||||
PASSWD = yuno_dbpdw
|
||||
NAME = __DB_USER__
|
||||
USER = __DB_USER__
|
||||
PASSWD = __DB_PASSWORD__
|
||||
SSL_MODE = disable
|
||||
PATH = data/gogs.db
|
||||
[repository]
|
||||
ROOT = yuno_repo_path
|
||||
ROOT = __REPOS_PATH__
|
||||
FORCE_PRIVATE = false
|
||||
[server]
|
||||
DOMAIN = yuno_domain
|
||||
HTTP_PORT = 6000
|
||||
ROOT_URL = https://yuno_url/
|
||||
DOMAIN = __DOMAIN__
|
||||
HTTP_PORT = __PORT__
|
||||
ROOT_URL = https://__URL__/
|
||||
DISABLE_SSH = false
|
||||
SSH_PORT = 22
|
||||
OFFLINE_MODE = false
|
||||
APP_DATA_PATH = yuno_data_path
|
||||
APP_DATA_PATH = __DATA_PATH__
|
||||
LANDING_PAGE = explore
|
||||
[mailer]
|
||||
ENABLED = true
|
||||
HOST = 127.0.0.1:25
|
||||
FROM = "Gogs" <gogs-noreply@yuno_domain>
|
||||
FROM = "Gogs" <gogs-noreply@__DOMAIN__>
|
||||
SKIP_VERIFY = true
|
||||
[service]
|
||||
REGISTER_EMAIL_CONFIRM = false
|
||||
|
@ -36,16 +36,16 @@ REQUIRE_SIGNIN_VIEW = false
|
|||
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
||||
ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = true
|
||||
[picture]
|
||||
AVATAR_UPLOAD_PATH = yuno_data_path/avatars
|
||||
AVATAR_UPLOAD_PATH = __DATA_PATH__/avatars
|
||||
[attachment]
|
||||
PATH = yuno_data_path/attachments
|
||||
PATH = __DATA_PATH__/attachments
|
||||
[session]
|
||||
PROVIDER = memory
|
||||
[log]
|
||||
MODE = file
|
||||
LEVEL = Warn
|
||||
ROOT_PATH = /var/log/gogs
|
||||
ROOT_PATH = /var/log/__APP__
|
||||
[security]
|
||||
INSTALL_LOCK = true
|
||||
SECRET_KEY = yuno_key
|
||||
SECRET_KEY = __KEY__
|
||||
REVERSE_PROXY_AUTHENTICATION_USER = REMOTE_USER
|
||||
|
|
11
conf/arm.src
Normal file
11
conf/arm.src
Normal file
|
@ -0,0 +1,11 @@
|
|||
SOURCE_URL=https://github.com/gogits/gogs/releases/download/v0.11.33/raspi2_armv6.zip
|
||||
SOURCE_SUM=334bb5a053f3335f8a8c3c85728ff0d0b376d3a0b5b6470a0334b9172441a1af
|
||||
# (Optional) Program to check the integrity (sha256sum, md5sum...)
|
||||
# default: sha256
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
# (Optional) Archive format
|
||||
# default: tar.gz
|
||||
SOURCE_FORMAT=zip
|
||||
# (Optional) Put false if sources are directly in the archive root
|
||||
# default: true
|
||||
SOURCE_IN_SUBDIR=true
|
11
conf/i386.src
Normal file
11
conf/i386.src
Normal file
|
@ -0,0 +1,11 @@
|
|||
SOURCE_URL=https://github.com/gogits/gogs/releases/download/v0.11.33/linux_386.zip
|
||||
SOURCE_SUM=d2223d36a9579497258e1b8a168a178da497c7f87ef481891464c0ded4455cb0
|
||||
# (Optional) Program to check the integrity (sha256sum, md5sum...)
|
||||
# default: sha256
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
# (Optional) Archive format
|
||||
# default: tar.gz
|
||||
SOURCE_FORMAT=zip
|
||||
# (Optional) Put false if sources are directly in the archive root
|
||||
# default: true
|
||||
SOURCE_IN_SUBDIR=true
|
|
@ -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}'
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# gogs logs:
|
||||
/var/log/gogs/*.log {
|
||||
daily
|
||||
missingok
|
||||
rotate 14
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
|
@ -1,11 +1,16 @@
|
|||
location PATHTOCHANGE/ {
|
||||
COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
|
||||
proxy_pass http://localhost:6000/;
|
||||
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||
location __PATH__/ {
|
||||
proxy_pass http://localhost:__PORT__/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_buffering off;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
client_max_body_size 50M;
|
||||
|
||||
# Force https
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
}
|
|
@ -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
|
11
conf/x86-64.src
Normal file
11
conf/x86-64.src
Normal file
|
@ -0,0 +1,11 @@
|
|||
SOURCE_URL=https://github.com/gogits/gogs/releases/download/v0.11.33/linux_amd64.zip
|
||||
SOURCE_SUM=7f0841a0451174349bf058e3827a0f46b8a827de0303827a6ff6d20fd03db3ff
|
||||
# (Optional) Program to check the integrity (sha256sum, md5sum...)
|
||||
# default: sha256
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
# (Optional) Archive format
|
||||
# default: tar.gz
|
||||
SOURCE_FORMAT=zip
|
||||
# (Optional) Put false if sources are directly in the archive root
|
||||
# default: true
|
||||
SOURCE_IN_SUBDIR=true
|
|
@ -9,12 +9,12 @@
|
|||
},
|
||||
"url": "http://gogs.io",
|
||||
"license": "MIT",
|
||||
"version": "0.11",
|
||||
"version": "0.11.33~ynh1",
|
||||
"maintainer": {
|
||||
"name": "tostaki",
|
||||
"email": "maxime@max.privy.place"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx",
|
||||
"mysql"
|
||||
|
@ -53,13 +53,13 @@
|
|||
"example": "johndoe"
|
||||
},
|
||||
{
|
||||
"name": "public_site",
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Is it a public site ?",
|
||||
"fr": "Est-ce un site public ?"
|
||||
},
|
||||
"choices": ["Yes", "No"],
|
||||
"default": "Yes"
|
||||
"default": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,46 +1,79 @@
|
|||
#
|
||||
# Common variables
|
||||
#
|
||||
#=================================================
|
||||
# SET ALL CONSTANTS
|
||||
#=================================================
|
||||
|
||||
APPNAME="gogs"
|
||||
|
||||
# Gogs version
|
||||
VERSION="0.11"
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
final_path="/opt/$app"
|
||||
DATADIR="/home/$app"
|
||||
REPO_PATH="$DATADIR/repositories"
|
||||
DATA_PATH="$DATADIR/data"
|
||||
|
||||
# Detect the system architecture to download the right tarball
|
||||
# NOTE: `uname -m` is more accurate and universal than `arch`
|
||||
# See https://en.wikipedia.org/wiki/Uname
|
||||
if [ -n "$(uname -m | grep 64)" ]; then
|
||||
ARCHITECTURE="linux_amd64"
|
||||
architecture="x86-64"
|
||||
elif [ -n "$(uname -m | grep 86)" ]; then
|
||||
ARCHITECTURE="linux_386"
|
||||
architecture="i386"
|
||||
elif [ -n "$(uname -m | grep arm)" ]; then
|
||||
ARCHITECTURE="raspi2_armv6"
|
||||
architecture="arm"
|
||||
else
|
||||
ynh_die "Unable to detect your achitecture, please open a bug describing \
|
||||
your hardware and the result of the command \"uname -m\"." 1
|
||||
fi
|
||||
|
||||
# Remote URL to fetch Gogs tarball
|
||||
GOGS_BINARY_URL="https://github.com/gogits/gogs/releases/download/v${VERSION}/${ARCHITECTURE}.zip"
|
||||
#=================================================
|
||||
# DEFINE ALL COMMON FONCTIONS
|
||||
#=================================================
|
||||
|
||||
#
|
||||
# Common helpers
|
||||
#
|
||||
|
||||
# Download and extract Gogs binary to the given directory
|
||||
# usage: extract_gogs DESTDIR
|
||||
extract_gogs() {
|
||||
local DESTDIR=$1
|
||||
local TMPDIR=$(mktemp -d)
|
||||
|
||||
# retrieve and extract Gogs tarball
|
||||
gogs_tarball="/tmp/gogs.zip"
|
||||
rm -f "$gogs_tarball"
|
||||
wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
|
||||
|| ynh_die "Unable to download Gogs tarball"
|
||||
unzip -q "$gogs_tarball" -d "$TMPDIR" \
|
||||
|| ynh_die "Unable to extract Gogs tarball"
|
||||
sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR"
|
||||
rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}"
|
||||
create_dir() {
|
||||
mkdir -p "$final_path/data"
|
||||
mkdir -p "$final_path/custom/conf"
|
||||
mkdir -p "$REPO_PATH"
|
||||
mkdir -p "$DATA_PATH/avatars"
|
||||
mkdir -p "$DATA_PATH/attachments"
|
||||
mkdir -p "/var/log/$app"
|
||||
}
|
||||
|
||||
config_nginx() {
|
||||
if [ "$path_url" != "/" ]
|
||||
then
|
||||
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
|
||||
fi
|
||||
ynh_add_nginx_config
|
||||
}
|
||||
|
||||
config_gogs() {
|
||||
ynh_backup_if_checksum_is_different "$final_path/custom/conf/app.ini"
|
||||
|
||||
cp ../conf/app.ini "$final_path/custom/conf"
|
||||
|
||||
if [ "$path_url" = "/" ]
|
||||
then
|
||||
ynh_replace_string "__URL__" "$domain" "$final_path/custom/conf/app.ini"
|
||||
else
|
||||
ynh_replace_string "__URL__" "$domain${path_url%/}" "$final_path/custom/conf/app.ini"
|
||||
fi
|
||||
|
||||
ynh_replace_string "__REPOS_PATH__" "$REPO_PATH" "$final_path/custom/conf/app.ini"
|
||||
ynh_replace_string "__DB_PASSWORD__" "$dbpass" "$final_path/custom/conf/app.ini"
|
||||
ynh_replace_string "__DB_USER__" "$dbuser" "$final_path/custom/conf/app.ini"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/custom/conf/app.ini"
|
||||
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"
|
||||
}
|
||||
|
||||
set_permission() {
|
||||
chown -R $app:$app "$final_path"
|
||||
chown -R $app:$app "/home/$app"
|
||||
chown -R $app:$app "/var/log/$app"
|
||||
chmod u=rwX,g=rX,o= "$final_path"
|
||||
chmod u=rwX,g=rX,o= "/home/$app"
|
||||
chmod u=rwX,g=rX,o= "/var/log/$app"
|
||||
}
|
||||
|
|
|
@ -1,33 +1,38 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# Set app specific variables
|
||||
app=${APPNAME:-gogs}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Source app helpers
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Load common variables and helpers
|
||||
source ../settings/scripts/experimental_helper.sh
|
||||
source ../settings/scripts/_common.sh
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
repo_path=$(ynh_app_setting_get "$app" repopath)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
|
||||
# Copy the app source files
|
||||
DESTDIR="/opt/$app"
|
||||
ynh_backup "$DESTDIR" "www"
|
||||
ynh_backup "$final_path"
|
||||
|
||||
# Copy the data files
|
||||
DATADIR="/home/$app"
|
||||
ynh_backup "$DATADIR" "data"
|
||||
ynh_backup "$DATADIR"
|
||||
|
||||
# Copy the conf files
|
||||
mkdir ./conf
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
|
||||
ynh_backup "/etc/logrotate.d/${app}" "conf/logrotate"
|
||||
ynh_backup "/etc/systemd/system/${app}.service" "conf/systemd.service"
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
ynh_backup "/etc/systemd/system/${app}.service"
|
||||
|
||||
# Backup logs
|
||||
ynh_backup "/var/log/$app"
|
||||
|
||||
# Dump the database
|
||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql
|
||||
ynh_mysql_dump_db "$dbname" > ./db.sql
|
77
scripts/change_url
Normal file
77
scripts/change_url
Normal file
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Import common cmd
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
cp -r /etc/yunohost/apps/${app}/conf ../ # Quick hack for https://github.com/YunoHost/yunohost/pull/427
|
||||
|
||||
# RETRIEVE ARGUMENTS
|
||||
old_domain=$YNH_APP_OLD_DOMAIN
|
||||
old_path=$YNH_APP_OLD_PATH
|
||||
new_domain=$YNH_APP_NEW_DOMAIN
|
||||
new_path=$YNH_APP_NEW_PATH
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
admin=$(ynh_app_setting_get "$app" adminusername)
|
||||
key=$(ynh_app_setting_get "$app" secret_key)
|
||||
port=$(ynh_app_setting_get "$app" web_port)
|
||||
|
||||
# CHECK THE SYNTAX OF THE PATHS
|
||||
test -n "$old_path" || old_path="/"
|
||||
test -n "$new_path" || new_path="/"
|
||||
new_path=$(ynh_normalize_url_path $new_path)
|
||||
old_path=$(ynh_normalize_url_path $old_path)
|
||||
|
||||
domain="$new_domain"
|
||||
path_url="$new_path"
|
||||
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
change_domain=0
|
||||
if [ "$old_domain" != "$new_domain" ]
|
||||
then
|
||||
change_domain=1
|
||||
fi
|
||||
|
||||
change_path=0
|
||||
if [ "$old_path" != "$new_path" ]
|
||||
then
|
||||
change_path=1
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
|
||||
# MODIFY URL IN NGINX CONF
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the domain for nginx
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum "$nginx_conf_path"
|
||||
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
|
||||
|
||||
config_nginx
|
||||
|
||||
# Update gogs config
|
||||
config_gogs
|
||||
|
||||
# RELOAD services
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||
sleep 1
|
61
scripts/experimental_helper.sh
Normal file
61
scripts/experimental_helper.sh
Normal file
|
@ -0,0 +1,61 @@
|
|||
# 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
|
||||
}
|
||||
|
||||
# Start or restart a service and follow its booting
|
||||
#
|
||||
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
|
||||
#
|
||||
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
|
||||
# | arg: Log file - The log file to watch
|
||||
# | arg: Service name
|
||||
# /var/log/$app/$app.log will be used if no other log is defined.
|
||||
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
|
||||
ynh_check_starting () {
|
||||
local line_to_match="$1"
|
||||
local service_name="${4:-$app}"
|
||||
local app_log="${2:-/var/log/$service_name/$service_name.log}"
|
||||
local timeout=${3:-300}
|
||||
|
||||
ynh_clean_check_starting () {
|
||||
# Stop the execution of tail.
|
||||
kill -s 15 $pid_tail 2>&1
|
||||
ynh_secure_remove "$templog" 2>&1
|
||||
}
|
||||
|
||||
echo "Starting of $service_name" >&2
|
||||
systemctl stop $service_name
|
||||
local templog="$(mktemp)"
|
||||
# Following the starting of the app in its log
|
||||
tail -F -n0 "$app_log" > "$templog" &
|
||||
# Get the PID of the tail command
|
||||
local pid_tail=$!
|
||||
systemctl start $service_name
|
||||
|
||||
local i=0
|
||||
for i in `seq 1 $timeout`
|
||||
do
|
||||
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
|
||||
if grep --quiet "$line_to_match" "$templog"
|
||||
then
|
||||
echo "The service $service_name has correctly started." >&2
|
||||
break
|
||||
fi
|
||||
echo -n "." >&2
|
||||
sleep 1
|
||||
done
|
||||
if [ $i -eq $timeout ]
|
||||
then
|
||||
echo "The service $service_name didn't fully started before the timeout." >&2
|
||||
fi
|
||||
|
||||
echo ""
|
||||
ynh_clean_check_starting
|
||||
}
|
133
scripts/install
133
scripts/install
|
@ -1,89 +1,80 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
|
||||
# Load common variables
|
||||
source ./_common.sh
|
||||
|
||||
# Set app specific variables
|
||||
app=${APPNAME:-gogs}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# TODO: Check domain/path availability with app helper
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "The path ${domain}${path} is not available for app installation."
|
||||
# Check domain/path availability
|
||||
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
|
||||
# Check user parameter
|
||||
ynh_user_exists "$admin" \
|
||||
|| ynh_die "The chosen admin user does not exist."
|
||||
|
||||
# Check destination directory
|
||||
DESTDIR="/opt/$app"
|
||||
[[ -d $DESTDIR ]] && ynh_die \
|
||||
"The destination directory '$DESTDIR' already exists.\
|
||||
You should safely delete it before installing this app."
|
||||
# Check Final Path availability
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
# Generate random password and key
|
||||
dbpass=$(ynh_string_random)
|
||||
key=$(ynh_string_random)
|
||||
|
||||
# Initialize database and store mysql password for upgrade
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
# Find available ports
|
||||
port=$(ynh_find_port 6000)
|
||||
|
||||
# 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
|
||||
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
|
||||
ynh_system_user_create $app
|
||||
|
||||
# create needed directories
|
||||
REPO_PATH=/home/"$app"/repositories
|
||||
DATA_PATH=/home/"$app"/data
|
||||
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
|
||||
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app"
|
||||
sudo chown -R "$app":"$app" /home/"$app" /var/log/"$app"
|
||||
create_dir
|
||||
|
||||
# Install Gogs
|
||||
extract_gogs $DESTDIR
|
||||
ynh_setup_source $final_path $architecture
|
||||
|
||||
# Configure gogs with app.ini file
|
||||
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
|
||||
sudo sed -i "s@yuno_repo_path@"$REPO_PATH"@g" "$DESTDIR"/custom/conf/app.ini
|
||||
if [ "$path" = "/" ]
|
||||
then
|
||||
sudo sed -i "s@yuno_url@$domain@g" "$DESTDIR"/custom/conf/app.ini
|
||||
else
|
||||
sudo sed -i "s@yuno_url@$domain${path%/}@g" "$DESTDIR"/custom/conf/app.ini
|
||||
fi
|
||||
sudo sed -i "s@yuno_dbpdw@$dbpass@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_dbuser@$dbuser@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_domain@$domain@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_key@$key@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_data_path@$DATA_PATH@g" "$DESTDIR"/custom/conf/app.ini
|
||||
|
||||
# Configure logrotate
|
||||
sudo cp ../conf/logrotate /etc/logrotate.d/"$app"
|
||||
config_gogs
|
||||
|
||||
# Configure init script
|
||||
sudo cp ../conf/gogs.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$app".service
|
||||
ynh_add_systemd_config
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
config_nginx
|
||||
|
||||
# Start gogs for building mysql tables
|
||||
sudo systemctl start "$app".service
|
||||
systemctl start "$app".service
|
||||
|
||||
# Set permissions
|
||||
set_permission
|
||||
|
||||
# Wait till login_source mysql table is created
|
||||
while ! $(ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
|
||||
|
@ -92,33 +83,25 @@ do
|
|||
done
|
||||
|
||||
# Add ldap config
|
||||
sudo sed -i "s@yuno_admin@$admin@g" ../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
|
||||
|
||||
# Add Gogs to YunoHost's monitored services
|
||||
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf
|
||||
if [ "$path" = "/" ]
|
||||
then
|
||||
sed -i "s@COMMENT_IF_ROOT@#@g" ../conf/nginx.conf
|
||||
else
|
||||
sed -i "s@COMMENT_IF_ROOT@@g" ../conf/nginx.conf
|
||||
fi
|
||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf
|
||||
|
||||
# Create uploads folder and permissions
|
||||
sudo mkdir /opt/gogs/data
|
||||
sudo chown -R gogs /opt/gogs/data
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
# Unprotect root from SSO if public
|
||||
if [ "$is_public" = "Yes" ]
|
||||
if [ "$is_public" = '1' ]
|
||||
then
|
||||
ynh_app_setting_set $app unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Add Gogs to YunoHost's monitored services
|
||||
yunohost service add "$app" --log "/var/log/$app/$app.log"
|
||||
|
||||
# Configure logrotate
|
||||
ynh_use_logrotate "/var/log/$app"
|
||||
|
||||
# Reload services
|
||||
sudo systemctl restart rsyslog.service || true
|
||||
sudo systemctl reload nginx.service || true
|
||||
sudo systemctl restart "$app".service || true
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit and treat unset variables as an error
|
||||
set -u
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./_common.sh
|
||||
|
||||
# Set app specific variables
|
||||
app=${APPNAME:-gogs}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Source app helpers
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
|
||||
# Stop gogs
|
||||
sudo systemctl stop "$app".service
|
||||
systemctl stop "$app".service
|
||||
|
||||
# Drop MySQL database and user
|
||||
ynh_mysql_drop_db "$dbname" 2>/dev/null || true
|
||||
ynh_mysql_drop_user "$dbuser" 2>/dev/null || true
|
||||
ynh_mysql_drop_db "$dbname" 2>/dev/null
|
||||
ynh_mysql_drop_user "$dbuser" 2>/dev/null
|
||||
|
||||
# Retrieve domain from app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
# Delete app directory and configurations
|
||||
sudo rm -rf "/opt/${app}"
|
||||
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
sudo rm -rf /var/log/"$app"
|
||||
sudo rm -f /etc/logrotate.d/"$app"
|
||||
ynh_secure_remove "$final_path"
|
||||
ynh_secure_remove "$DATADIR"
|
||||
ynh_secure_remove "/var/log/$app"
|
||||
|
||||
# Remove the app-specific logrotate config
|
||||
ynh_remove_logrotate
|
||||
|
||||
# Remove nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
# Remove gogs user and data
|
||||
sudo userdel -r "$app"
|
||||
ynh_system_user_delete $app
|
||||
|
||||
# Remove init script
|
||||
sudo systemctl disable "$app".service
|
||||
sudo rm -f /etc/systemd/system/"$app".service
|
||||
sudo systemctl daemon-reload
|
||||
ynh_remove_systemd_config
|
||||
|
||||
# Remove monitor
|
||||
sudo yunohost service remove "$app"
|
||||
|
||||
# Reload services
|
||||
sudo systemctl restart rsyslog.service || true
|
||||
sudo systemctl reload nginx.service || true
|
||||
yunohost service remove "$app"
|
|
@ -1,72 +1,66 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# Set app specific variables
|
||||
app=${APPNAME:-gogs}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Source app helpers
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Load common variables and helpers
|
||||
source ../settings/scripts/experimental_helper.sh
|
||||
source ../settings/scripts/_common.sh
|
||||
|
||||
# Retrieve old app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
admin=$(ynh_app_setting_get "$app" adminusername)
|
||||
|
||||
# TODO: Check domain/path availability with app helper
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "The path ${domain}${path} is not available for app installation."
|
||||
# Check domain/path availability with app helper
|
||||
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
|
||||
|
||||
# Check user parameter
|
||||
ynh_user_exists "$admin" \
|
||||
|| ynh_die "The chosen admin user does not exist."
|
||||
|
||||
# Check destination directory
|
||||
DESTDIR="/opt/$app"
|
||||
[[ -d $DESTDIR ]] && ynh_die \
|
||||
"The destination directory '$DESTDIR' already exists.\
|
||||
You should safely delete it before restoring this app."
|
||||
# Check Final Path availability
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
|
||||
# Add users
|
||||
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
|
||||
ynh_system_user_create $app
|
||||
|
||||
# Check configuration files
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
[[ -f $nginx_conf ]] && ynh_die \
|
||||
"The NGINX configuration already exists at '${nginx_conf}'.
|
||||
You should safely delete it before restoring this app."
|
||||
|
||||
# Restore the app files
|
||||
sudo cp -a ./www "$DESTDIR"
|
||||
|
||||
# Restore the data
|
||||
sudo cp -a ./data/. "/home/gogs"
|
||||
# Restore all files
|
||||
ynh_restore
|
||||
|
||||
# Create and restore the database
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
||||
|
||||
# Restore directories and permissions
|
||||
sudo mkdir -p /var/log/"$app"
|
||||
sudo chown -R root:root "$DESTDIR"
|
||||
sudo chown -R "$app":"$app" "/home/gogs" "/var/log/$app"
|
||||
# Restore systemd files
|
||||
systemctl daemon-reload
|
||||
systemctl enable "$app".service
|
||||
|
||||
# Restore configuration files
|
||||
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
||||
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app"
|
||||
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$app".service
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
# Set permissions
|
||||
set_permission
|
||||
|
||||
# Configure logrotate
|
||||
ynh_use_logrotate "/var/log/$app"
|
||||
|
||||
# Add Gogs to YunoHost's monitored services
|
||||
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
||||
yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
||||
|
||||
# Reload services
|
||||
sudo systemctl restart rsyslog.service || true
|
||||
sudo systemctl reload nginx.service || true
|
||||
sudo systemctl restart "$app".service || true
|
||||
systemctl reload nginx.service
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||
|
|
155
scripts/upgrade
155
scripts/upgrade
|
@ -1,33 +1,55 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
# Set app specific variables
|
||||
app=${APPNAME:-gogs}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(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)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
port=$(ynh_app_setting_get "$app" web_port)
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
|
||||
# Stop service
|
||||
sudo systemctl stop "$app".service
|
||||
systemctl stop "$app".service
|
||||
|
||||
# set directories variables
|
||||
DESTDIR="/opt/$app"
|
||||
REPO_PATH=/home/"$app"/repositories
|
||||
DATA_PATH=/home/"$app"/data
|
||||
#=================================================
|
||||
# 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
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set $app is_public 0
|
||||
is_public=0
|
||||
fi
|
||||
|
||||
if [[ $port == "" ]]
|
||||
then
|
||||
port=$(ynh_find_port 6000)
|
||||
ynh_app_setting_set $app web_port $port
|
||||
fi
|
||||
|
||||
# handle upgrade from old package installation
|
||||
# this test that /etc/gogs exist since this was used in the old package
|
||||
|
@ -35,75 +57,54 @@ DATA_PATH=/home/"$app"/data
|
|||
# this code will be removed in the future
|
||||
if [ -d "/etc/gogs" ]
|
||||
then
|
||||
# create needed directories if not already created
|
||||
create_dir
|
||||
|
||||
# move repositories to new dir
|
||||
sudo mkdir -p "$REPO_PATH"
|
||||
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
||||
sudo mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH"
|
||||
mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH" || true # Avoid if the directory is empty
|
||||
# cleanup old dir and conf
|
||||
sudo unlink /opt/gogs
|
||||
sudo rm -rf /etc/gogs /opt/gogs_src
|
||||
ynh_secure_remove /opt/gogs
|
||||
ynh_secure_remove /etc/gogs
|
||||
ynh_secure_remove /opt/gogs_src
|
||||
|
||||
# create needed directories if not already created
|
||||
create_dir
|
||||
fi
|
||||
# end of old package upgrade
|
||||
|
||||
# create needed directories and give correct acl
|
||||
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
|
||||
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app"
|
||||
sudo chown -R "$app":"$app" /home/"$app" /var/log/"$app"
|
||||
|
||||
# Install Gogs
|
||||
extract_gogs $DESTDIR
|
||||
|
||||
# Configure gogs with app.ini file
|
||||
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
|
||||
sudo sed -i "s@yuno_repo_path@"$REPO_PATH"@g" "$DESTDIR"/custom/conf/app.ini
|
||||
if [ "$path" = "/" ]
|
||||
then
|
||||
sudo sed -i "s@yuno_url@$domain@g" "$DESTDIR"/custom/conf/app.ini
|
||||
else
|
||||
sudo sed -i "s@yuno_url@$domain${path%/}@g" "$DESTDIR"/custom/conf/app.ini
|
||||
fi
|
||||
sudo sed -i "s@yuno_dbpdw@$dbpass@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_dbuser@$dbuser@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_domain@$domain@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_key@$key@g" "$DESTDIR"/custom/conf/app.ini
|
||||
sudo sed -i "s@yuno_data_path@$DATA_PATH@g" "$DESTDIR"/custom/conf/app.ini
|
||||
|
||||
# Configure init script
|
||||
sudo cp ../conf/gogs.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$app".service
|
||||
|
||||
# Configure logrotate
|
||||
sudo cp ../conf/logrotate /etc/logrotate.d/"$app"
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf
|
||||
if [ "$path" = "/" ]
|
||||
then
|
||||
sed -i "s@COMMENT_IF_ROOT@#@g" ../conf/nginx.conf
|
||||
else
|
||||
sed -i "s@COMMENT_IF_ROOT@@g" ../conf/nginx.conf
|
||||
fi
|
||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
|
||||
# Unprotect root from SSO if public
|
||||
if [ "$is_public" = "Yes" ]
|
||||
then
|
||||
ynh_app_setting_set $app unprotected_uris "/"
|
||||
fi
|
||||
|
||||
# Reload services
|
||||
sudo systemctl restart rsyslog.service || true
|
||||
sudo systemctl reload nginx.service || true
|
||||
sudo systemctl restart "$app".service || true
|
||||
|
||||
# Restore ldap config
|
||||
sudo sed -i "s@yuno_admin@$admin@g" ../conf/login_source.sql
|
||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
|
||||
|
||||
# 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 [[ $(sudo grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
|
||||
if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
|
||||
then
|
||||
sudo usermod -p '*' "$app"
|
||||
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"
|
||||
|
||||
# Install Gogs
|
||||
ynh_setup_source $final_path $architecture
|
||||
|
||||
# Configure gogs with app.ini file
|
||||
config_gogs
|
||||
|
||||
# Configure init script
|
||||
ynh_add_systemd_config
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
config_nginx
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
# Set permissions
|
||||
set_permission
|
||||
|
||||
# Reload services
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||
|
|
Loading…
Reference in a new issue