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 is a self-hosted Git service written in Go. Alternative to Github.
|
||||||
- [Gogs website](http://gogs.io)
|
- [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
|
## Requirements
|
||||||
A functional instance of [YunoHost](https://yunohost.org)
|
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/)
|
Sources and issues of the old package can be found [here](https://github.com/YunoHost-Apps/gogs_ynh_old/)
|
||||||
|
|
||||||
## Info
|
## Info
|
||||||
Gogs v0.11
|
Gogs v0.11.33
|
||||||
|
|
||||||
- [YunoHost forum thread](https://forum.yunohost.org/t/gogs-package-an-awesome-github-alternative/1127)
|
- [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`.
|
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
|
## License
|
||||||
Gogs is published under the MIT License:
|
Gogs is published under the MIT License:
|
||||||
https://github.com/gogits/gogs/blob/master/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
|
;https://github.com/gogits/gogs/blob/master/conf/app.ini
|
||||||
APP_NAME = Gogs: Go Git Service
|
APP_NAME = Gogs: Go Git Service
|
||||||
RUN_USER = gogs
|
RUN_USER = __APP__
|
||||||
RUN_MODE = prod
|
RUN_MODE = prod
|
||||||
[database]
|
[database]
|
||||||
DB_TYPE = mysql
|
DB_TYPE = mysql
|
||||||
HOST = 127.0.0.1:3306
|
HOST = 127.0.0.1:3306
|
||||||
NAME = yuno_dbuser
|
NAME = __DB_USER__
|
||||||
USER = yuno_dbuser
|
USER = __DB_USER__
|
||||||
PASSWD = yuno_dbpdw
|
PASSWD = __DB_PASSWORD__
|
||||||
SSL_MODE = disable
|
SSL_MODE = disable
|
||||||
PATH = data/gogs.db
|
PATH = data/gogs.db
|
||||||
[repository]
|
[repository]
|
||||||
ROOT = yuno_repo_path
|
ROOT = __REPOS_PATH__
|
||||||
FORCE_PRIVATE = false
|
FORCE_PRIVATE = false
|
||||||
[server]
|
[server]
|
||||||
DOMAIN = yuno_domain
|
DOMAIN = __DOMAIN__
|
||||||
HTTP_PORT = 6000
|
HTTP_PORT = __PORT__
|
||||||
ROOT_URL = https://yuno_url/
|
ROOT_URL = https://__URL__/
|
||||||
DISABLE_SSH = false
|
DISABLE_SSH = false
|
||||||
SSH_PORT = 22
|
SSH_PORT = 22
|
||||||
OFFLINE_MODE = false
|
OFFLINE_MODE = false
|
||||||
APP_DATA_PATH = yuno_data_path
|
APP_DATA_PATH = __DATA_PATH__
|
||||||
LANDING_PAGE = explore
|
LANDING_PAGE = explore
|
||||||
[mailer]
|
[mailer]
|
||||||
ENABLED = true
|
ENABLED = true
|
||||||
HOST = 127.0.0.1:25
|
HOST = 127.0.0.1:25
|
||||||
FROM = "Gogs" <gogs-noreply@yuno_domain>
|
FROM = "Gogs" <gogs-noreply@__DOMAIN__>
|
||||||
SKIP_VERIFY = true
|
SKIP_VERIFY = true
|
||||||
[service]
|
[service]
|
||||||
REGISTER_EMAIL_CONFIRM = false
|
REGISTER_EMAIL_CONFIRM = false
|
||||||
|
@ -36,16 +36,16 @@ REQUIRE_SIGNIN_VIEW = false
|
||||||
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
||||||
ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = true
|
ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = true
|
||||||
[picture]
|
[picture]
|
||||||
AVATAR_UPLOAD_PATH = yuno_data_path/avatars
|
AVATAR_UPLOAD_PATH = __DATA_PATH__/avatars
|
||||||
[attachment]
|
[attachment]
|
||||||
PATH = yuno_data_path/attachments
|
PATH = __DATA_PATH__/attachments
|
||||||
[session]
|
[session]
|
||||||
PROVIDER = memory
|
PROVIDER = memory
|
||||||
[log]
|
[log]
|
||||||
MODE = file
|
MODE = file
|
||||||
LEVEL = Warn
|
LEVEL = Warn
|
||||||
ROOT_PATH = /var/log/gogs
|
ROOT_PATH = /var/log/__APP__
|
||||||
[security]
|
[security]
|
||||||
INSTALL_LOCK = true
|
INSTALL_LOCK = true
|
||||||
SECRET_KEY = yuno_key
|
SECRET_KEY = __KEY__
|
||||||
REVERSE_PROXY_AUTHENTICATION_USER = REMOTE_USER
|
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
|
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=yuno_admin)","Enabled":true}', '1464014433', '1464015955')
|
('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=yuno_admin)","Enabled":true}'
|
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/ {
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
|
location __PATH__/ {
|
||||||
proxy_pass http://localhost:6000/;
|
proxy_pass http://localhost:__PORT__/;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
client_max_body_size 50M;
|
client_max_body_size 50M;
|
||||||
|
|
||||||
|
# Force https
|
||||||
|
if ($scheme = http) {
|
||||||
|
rewrite ^ https://$server_name$request_uri? permanent;
|
||||||
|
}
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,12 @@ After=slapd.service
|
||||||
#LimitMEMLOCK=infinity
|
#LimitMEMLOCK=infinity
|
||||||
#LimitNOFILE=65535
|
#LimitNOFILE=65535
|
||||||
Type=simple
|
Type=simple
|
||||||
User=gogs
|
User=__APP__
|
||||||
Group=gogs
|
Group=__APP__
|
||||||
WorkingDirectory=/home/gogs
|
WorkingDirectory=/home/__APP__
|
||||||
ExecStart=/opt/gogs/gogs web
|
ExecStart=/opt/__APP__/gogs web
|
||||||
Restart=always
|
Restart=always
|
||||||
Environment=USER=gogs HOME=/home/gogs
|
Environment=USER=__APP__ HOME=/home/__APP__
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
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",
|
"url": "http://gogs.io",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.11",
|
"version": "0.11.33~ynh1",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "tostaki",
|
"name": "tostaki",
|
||||||
"email": "maxime@max.privy.place"
|
"email": "maxime@max.privy.place"
|
||||||
},
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": true,
|
||||||
"services": [
|
"services": [
|
||||||
"nginx",
|
"nginx",
|
||||||
"mysql"
|
"mysql"
|
||||||
|
@ -53,13 +53,13 @@
|
||||||
"example": "johndoe"
|
"example": "johndoe"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "public_site",
|
"name": "is_public",
|
||||||
|
"type": "boolean",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Is it a public site ?",
|
"en": "Is it a public site ?",
|
||||||
"fr": "Est-ce un site public ?"
|
"fr": "Est-ce un site public ?"
|
||||||
},
|
},
|
||||||
"choices": ["Yes", "No"],
|
"default": true
|
||||||
"default": "Yes"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,79 @@
|
||||||
#
|
#=================================================
|
||||||
# Common variables
|
# SET ALL CONSTANTS
|
||||||
#
|
#=================================================
|
||||||
|
|
||||||
APPNAME="gogs"
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
dbname=$app
|
||||||
# Gogs version
|
dbuser=$app
|
||||||
VERSION="0.11"
|
final_path="/opt/$app"
|
||||||
|
DATADIR="/home/$app"
|
||||||
|
REPO_PATH="$DATADIR/repositories"
|
||||||
|
DATA_PATH="$DATADIR/data"
|
||||||
|
|
||||||
# Detect the system architecture to download the right tarball
|
# Detect the system architecture to download the right tarball
|
||||||
# NOTE: `uname -m` is more accurate and universal than `arch`
|
# NOTE: `uname -m` is more accurate and universal than `arch`
|
||||||
# See https://en.wikipedia.org/wiki/Uname
|
# See https://en.wikipedia.org/wiki/Uname
|
||||||
if [ -n "$(uname -m | grep 64)" ]; then
|
if [ -n "$(uname -m | grep 64)" ]; then
|
||||||
ARCHITECTURE="linux_amd64"
|
architecture="x86-64"
|
||||||
elif [ -n "$(uname -m | grep 86)" ]; then
|
elif [ -n "$(uname -m | grep 86)" ]; then
|
||||||
ARCHITECTURE="linux_386"
|
architecture="i386"
|
||||||
elif [ -n "$(uname -m | grep arm)" ]; then
|
elif [ -n "$(uname -m | grep arm)" ]; then
|
||||||
ARCHITECTURE="raspi2_armv6"
|
architecture="arm"
|
||||||
else
|
else
|
||||||
ynh_die "Unable to detect your achitecture, please open a bug describing \
|
ynh_die "Unable to detect your achitecture, please open a bug describing \
|
||||||
your hardware and the result of the command \"uname -m\"." 1
|
your hardware and the result of the command \"uname -m\"." 1
|
||||||
fi
|
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
|
||||||
|
#=================================================
|
||||||
|
|
||||||
#
|
create_dir() {
|
||||||
# Common helpers
|
mkdir -p "$final_path/data"
|
||||||
#
|
mkdir -p "$final_path/custom/conf"
|
||||||
|
mkdir -p "$REPO_PATH"
|
||||||
# Download and extract Gogs binary to the given directory
|
mkdir -p "$DATA_PATH/avatars"
|
||||||
# usage: extract_gogs DESTDIR
|
mkdir -p "$DATA_PATH/attachments"
|
||||||
extract_gogs() {
|
mkdir -p "/var/log/$app"
|
||||||
local DESTDIR=$1
|
}
|
||||||
local TMPDIR=$(mktemp -d)
|
|
||||||
|
config_nginx() {
|
||||||
# retrieve and extract Gogs tarball
|
if [ "$path_url" != "/" ]
|
||||||
gogs_tarball="/tmp/gogs.zip"
|
then
|
||||||
rm -f "$gogs_tarball"
|
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
|
||||||
wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
|
fi
|
||||||
|| ynh_die "Unable to download Gogs tarball"
|
ynh_add_nginx_config
|
||||||
unzip -q "$gogs_tarball" -d "$TMPDIR" \
|
}
|
||||||
|| ynh_die "Unable to extract Gogs tarball"
|
|
||||||
sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR"
|
config_gogs() {
|
||||||
rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}"
|
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
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Set app specific variables
|
# IMPORT GENERIC HELPERS
|
||||||
app=${APPNAME:-gogs}
|
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
|
|
||||||
# Source app helpers
|
|
||||||
source /usr/share/yunohost/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
|
# Retrieve app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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
|
# Copy the app source files
|
||||||
DESTDIR="/opt/$app"
|
ynh_backup "$final_path"
|
||||||
ynh_backup "$DESTDIR" "www"
|
|
||||||
|
|
||||||
# Copy the data files
|
# Copy the data files
|
||||||
DATADIR="/home/$app"
|
ynh_backup "$DATADIR"
|
||||||
ynh_backup "$DATADIR" "data"
|
|
||||||
|
|
||||||
# Copy the conf files
|
# Copy the conf files
|
||||||
mkdir ./conf
|
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
|
ynh_backup "/etc/systemd/system/${app}.service"
|
||||||
ynh_backup "/etc/logrotate.d/${app}" "conf/logrotate"
|
|
||||||
ynh_backup "/etc/systemd/system/${app}.service" "conf/systemd.service"
|
# Backup logs
|
||||||
|
ynh_backup "/var/log/$app"
|
||||||
|
|
||||||
# Dump the database
|
# 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
|
#!/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
|
# Retrieve arguments
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
|
|
||||||
# Load common variables
|
# Check domain/path availability
|
||||||
source ./_common.sh
|
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
|
||||||
# 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 user parameter
|
# Check user parameter
|
||||||
ynh_user_exists "$admin" \
|
ynh_user_exists "$admin" \
|
||||||
|| ynh_die "The chosen admin user does not exist."
|
|| ynh_die "The chosen admin user does not exist."
|
||||||
|
|
||||||
# Check destination directory
|
# Check Final Path availability
|
||||||
DESTDIR="/opt/$app"
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
[[ -d $DESTDIR ]] && ynh_die \
|
|
||||||
"The destination directory '$DESTDIR' already exists.\
|
|
||||||
You should safely delete it before installing this app."
|
|
||||||
|
|
||||||
# Generate random password and key
|
# Generate random password and key
|
||||||
dbpass=$(ynh_string_random)
|
dbpass=$(ynh_string_random)
|
||||||
key=$(ynh_string_random)
|
key=$(ynh_string_random)
|
||||||
|
|
||||||
# Initialize database and store mysql password for upgrade
|
# Find available ports
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
port=$(ynh_find_port 6000)
|
||||||
|
|
||||||
|
# Store Settings
|
||||||
ynh_app_setting_set $app mysqlpwd $dbpass
|
ynh_app_setting_set $app mysqlpwd $dbpass
|
||||||
ynh_app_setting_set $app adminusername $admin
|
ynh_app_setting_set $app adminusername $admin
|
||||||
ynh_app_setting_set $app is_public $is_public
|
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
|
# Add users
|
||||||
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
|
ynh_system_user_create $app
|
||||||
id -u "$app" &>/dev/null || sudo adduser "$app" \
|
|
||||||
--ingroup "$app" --system --quiet --shell /bin/bash
|
|
||||||
|
|
||||||
# create needed directories
|
# create needed directories
|
||||||
REPO_PATH=/home/"$app"/repositories
|
create_dir
|
||||||
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"
|
|
||||||
|
|
||||||
# Install Gogs
|
# Install Gogs
|
||||||
extract_gogs $DESTDIR
|
ynh_setup_source $final_path $architecture
|
||||||
|
|
||||||
# Configure gogs with app.ini file
|
# Configure gogs with app.ini file
|
||||||
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
|
config_gogs
|
||||||
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"
|
|
||||||
|
|
||||||
# Configure init script
|
# Configure init script
|
||||||
sudo cp ../conf/gogs.service /etc/systemd/system/
|
ynh_add_systemd_config
|
||||||
sudo systemctl daemon-reload
|
|
||||||
sudo systemctl enable "$app".service
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
|
config_nginx
|
||||||
|
|
||||||
# Start gogs for building mysql tables
|
# 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
|
# Wait till login_source mysql table is created
|
||||||
while ! $(ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
|
while ! $(ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
|
||||||
|
@ -92,33 +83,25 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Add ldap config
|
# 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
|
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
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
# 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
|
|
||||||
|
|
||||||
# Unprotect root from SSO if public
|
# Unprotect root from SSO if public
|
||||||
if [ "$is_public" = "Yes" ]
|
if [ "$is_public" = '1' ]
|
||||||
then
|
then
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
fi
|
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
|
# Reload services
|
||||||
sudo systemctl restart rsyslog.service || true
|
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||||
sudo systemctl reload nginx.service || true
|
|
||||||
sudo systemctl restart "$app".service || true
|
|
||||||
|
|
|
@ -1,46 +1,46 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit and treat unset variables as an error
|
#=================================================
|
||||||
set -u
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Load common variables and helpers
|
# IMPORT GENERIC HELPERS
|
||||||
source ./_common.sh
|
|
||||||
|
|
||||||
# Set app specific variables
|
|
||||||
app=${APPNAME:-gogs}
|
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
|
|
||||||
# Source app helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
# Load common variables and helpers
|
||||||
|
source ./experimental_helper.sh
|
||||||
|
source ./_common.sh
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD REMOVE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Stop gogs
|
# Stop gogs
|
||||||
sudo systemctl stop "$app".service
|
systemctl stop "$app".service
|
||||||
|
|
||||||
# Drop MySQL database and user
|
# Drop MySQL database and user
|
||||||
ynh_mysql_drop_db "$dbname" 2>/dev/null || true
|
ynh_mysql_drop_db "$dbname" 2>/dev/null
|
||||||
ynh_mysql_drop_user "$dbuser" 2>/dev/null || true
|
ynh_mysql_drop_user "$dbuser" 2>/dev/null
|
||||||
|
|
||||||
# Retrieve domain from app settings
|
# Retrieve domain from app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
|
||||||
# Delete app directory and configurations
|
# Delete app directory and configurations
|
||||||
sudo rm -rf "/opt/${app}"
|
ynh_secure_remove "$final_path"
|
||||||
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_secure_remove "$DATADIR"
|
||||||
sudo rm -rf /var/log/"$app"
|
ynh_secure_remove "/var/log/$app"
|
||||||
sudo rm -f /etc/logrotate.d/"$app"
|
|
||||||
|
# Remove the app-specific logrotate config
|
||||||
|
ynh_remove_logrotate
|
||||||
|
|
||||||
|
# Remove nginx config
|
||||||
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
# Remove gogs user and data
|
# Remove gogs user and data
|
||||||
sudo userdel -r "$app"
|
ynh_system_user_delete $app
|
||||||
|
|
||||||
# Remove init script
|
# Remove init script
|
||||||
sudo systemctl disable "$app".service
|
ynh_remove_systemd_config
|
||||||
sudo rm -f /etc/systemd/system/"$app".service
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
|
|
||||||
# Remove monitor
|
# Remove monitor
|
||||||
sudo yunohost service remove "$app"
|
yunohost service remove "$app"
|
||||||
|
|
||||||
# Reload services
|
|
||||||
sudo systemctl restart rsyslog.service || true
|
|
||||||
sudo systemctl reload nginx.service || true
|
|
|
@ -1,72 +1,66 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Set app specific variables
|
# IMPORT GENERIC HELPERS
|
||||||
app=${APPNAME:-gogs}
|
|
||||||
dbname=$app
|
|
||||||
dbuser=$app
|
|
||||||
|
|
||||||
# Source app helpers
|
|
||||||
source /usr/share/yunohost/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
|
# Retrieve old app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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)
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
admin=$(ynh_app_setting_get "$app" adminusername)
|
admin=$(ynh_app_setting_get "$app" adminusername)
|
||||||
|
|
||||||
# TODO: Check domain/path availability with app helper
|
# Check domain/path availability with app helper
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
|
||||||
|| ynh_die "The path ${domain}${path} is not available for app installation."
|
|
||||||
|
|
||||||
# Check user parameter
|
# Check user parameter
|
||||||
ynh_user_exists "$admin" \
|
ynh_user_exists "$admin" \
|
||||||
|| ynh_die "The chosen admin user does not exist."
|
|| ynh_die "The chosen admin user does not exist."
|
||||||
|
|
||||||
# Check destination directory
|
# Check Final Path availability
|
||||||
DESTDIR="/opt/$app"
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
[[ -d $DESTDIR ]] && ynh_die \
|
|
||||||
"The destination directory '$DESTDIR' already exists.\
|
#=================================================
|
||||||
You should safely delete it before restoring this app."
|
# STANDARD RESTORATION STEPS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Add users
|
# Add users
|
||||||
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
|
ynh_system_user_create $app
|
||||||
id -u "$app" &>/dev/null || sudo adduser "$app" \
|
|
||||||
--ingroup "$app" --system --quiet --shell /bin/bash
|
|
||||||
|
|
||||||
# Check configuration files
|
# Restore all files
|
||||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_restore
|
||||||
[[ -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"
|
|
||||||
|
|
||||||
# Create and restore the database
|
# Create and restore the database
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
||||||
|
|
||||||
# Restore directories and permissions
|
# Restore systemd files
|
||||||
sudo mkdir -p /var/log/"$app"
|
systemctl daemon-reload
|
||||||
sudo chown -R root:root "$DESTDIR"
|
systemctl enable "$app".service
|
||||||
sudo chown -R "$app":"$app" "/home/gogs" "/var/log/$app"
|
|
||||||
|
|
||||||
# Restore configuration files
|
#=================================================
|
||||||
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
# GENERIC FINALIZATION
|
||||||
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app"
|
#=================================================
|
||||||
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
|
|
||||||
sudo systemctl daemon-reload
|
# Set permissions
|
||||||
sudo systemctl enable "$app".service
|
set_permission
|
||||||
|
|
||||||
|
# Configure logrotate
|
||||||
|
ynh_use_logrotate "/var/log/$app"
|
||||||
|
|
||||||
# Add Gogs to YunoHost's monitored services
|
# 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
|
# Reload services
|
||||||
sudo systemctl restart rsyslog.service || true
|
systemctl reload nginx.service
|
||||||
sudo systemctl reload nginx.service || true
|
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
||||||
sudo systemctl restart "$app".service || true
|
|
||||||
|
|
155
scripts/upgrade
155
scripts/upgrade
|
@ -1,33 +1,55 @@
|
||||||
#!/bin/bash
|
#!/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
|
# Load common variables and helpers
|
||||||
|
source ./experimental_helper.sh
|
||||||
source ./_common.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
|
# Retrieve app settings
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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)
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
admin=$(ynh_app_setting_get "$app" adminusername)
|
admin=$(ynh_app_setting_get "$app" adminusername)
|
||||||
key=$(ynh_app_setting_get "$app" secret_key)
|
key=$(ynh_app_setting_get "$app" secret_key)
|
||||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
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
|
# Stop service
|
||||||
sudo systemctl stop "$app".service
|
systemctl stop "$app".service
|
||||||
|
|
||||||
# set directories variables
|
#=================================================
|
||||||
DESTDIR="/opt/$app"
|
# MIGRATION FROM OLD VERSION
|
||||||
REPO_PATH=/home/"$app"/repositories
|
#=================================================
|
||||||
DATA_PATH=/home/"$app"/data
|
|
||||||
|
# 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
|
# handle upgrade from old package installation
|
||||||
# this test that /etc/gogs exist since this was used in the old package
|
# 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
|
# this code will be removed in the future
|
||||||
if [ -d "/etc/gogs" ]
|
if [ -d "/etc/gogs" ]
|
||||||
then
|
then
|
||||||
|
# create needed directories if not already created
|
||||||
|
create_dir
|
||||||
|
|
||||||
# move repositories to new dir
|
# move repositories to new dir
|
||||||
sudo mkdir -p "$REPO_PATH"
|
|
||||||
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
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
|
# cleanup old dir and conf
|
||||||
sudo unlink /opt/gogs
|
ynh_secure_remove /opt/gogs
|
||||||
sudo rm -rf /etc/gogs /opt/gogs_src
|
ynh_secure_remove /etc/gogs
|
||||||
|
ynh_secure_remove /opt/gogs_src
|
||||||
|
|
||||||
|
# create needed directories if not already created
|
||||||
|
create_dir
|
||||||
fi
|
fi
|
||||||
# end of old package upgrade
|
# 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.
|
# 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 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
|
then
|
||||||
sudo usermod -p '*' "$app"
|
usermod -p '*' "$app"
|
||||||
fi
|
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