mirror of
https://framagit.org/YunoHost-Apps/gitea_ynh.git
synced 2024-12-03 16:26:53 +01:00
Init
This commit is contained in:
commit
d474571ed8
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 mbugeia
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
69
README.md
Normal file
69
README.md
Normal file
@ -0,0 +1,69 @@
|
||||
# Gitea package for YunoHost
|
||||
|
||||
Gitea is a fork of Gogs a self-hosted Git service written in Go. Alternative to Github.
|
||||
- [Gitea website](http://gitea.io)
|
||||
|
||||
[![Integration level](https://dash.yunohost.org/integration/gitea.svg)](https://ci-apps.yunohost.org/jenkins/job/gitea%20%28Community%29/lastBuild/consoleFull)
|
||||
|
||||
[![Install Gitea with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=gitea)
|
||||
|
||||
## Requirements
|
||||
A functional instance of [YunoHost](https://yunohost.org)
|
||||
|
||||
## Installation
|
||||
From the command-line:
|
||||
|
||||
`sudo yunohost app install https://github.com/YunoHost-Apps/gitea_ynh`
|
||||
|
||||
## Upgrade
|
||||
From the command-line:
|
||||
|
||||
`sudo yunohost app upgrade Gitea -u https://github.com/YunoHost-Apps/gogs_ynh gogs`
|
||||
|
||||
## Notes on SSH usage
|
||||
If you want to use Gitea with ssh and be able to pull/push with you ssh key, your ssh daemon must be properly configured to use private/public keys. Here is a sample configuration of `/etc/ssh/sshd_config` that works with Gitea:
|
||||
|
||||
```bash
|
||||
PubkeyAuthentication yes
|
||||
AuthorizedKeysFile %h/.ssh/authorized_keys
|
||||
ChallengeResponseAuthentication no
|
||||
PasswordAuthentication no
|
||||
UsePAM no
|
||||
```
|
||||
|
||||
You also need to add your public key to your Gitea profile.
|
||||
|
||||
If you use ssh on another port than 22, you need to add theses lines to your ssh config in `~/.ssh/config`:
|
||||
|
||||
```bash
|
||||
Host domain.tld
|
||||
port 2222 # change this with the port you use
|
||||
```
|
||||
|
||||
|
||||
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
|
||||
Gitea is published under the MIT License:
|
||||
https://github.com/go-gitea/gitea/blob/master/LICENSE
|
||||
|
||||
This package is published under the MIT License.
|
||||
|
||||
|
||||
## Developper info
|
||||
Please do your pull requests to the `dev` branch.
|
||||
|
||||
Test or upgrade to dev version:
|
||||
```bash
|
||||
sudo su - admin
|
||||
git clone -b dev https://github.com/YunoHost-Apps/gogs_ynh
|
||||
# to install
|
||||
sudo yunohost app install -l Gogs /home/admin/gogs_ynh
|
||||
# to upgrade
|
||||
sudo yunohost app upgrade -f /home/admin/gogs_ynh gogs
|
||||
|
||||
```
|
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/gitea_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
|
51
conf/app.ini
Normal file
51
conf/app.ini
Normal file
@ -0,0 +1,51 @@
|
||||
;https://github.com/gogits/gogs/blob/master/conf/app.ini
|
||||
APP_NAME = Gitea
|
||||
RUN_USER = __APP__
|
||||
RUN_MODE = prod
|
||||
[database]
|
||||
DB_TYPE = mysql
|
||||
HOST = 127.0.0.1:3306
|
||||
NAME = __DB_USER__
|
||||
USER = __DB_USER__
|
||||
PASSWD = __DB_PASSWORD__
|
||||
SSL_MODE = disable
|
||||
PATH = data/gitea.db
|
||||
[repository]
|
||||
ROOT = __REPOS_PATH__
|
||||
FORCE_PRIVATE = false
|
||||
[server]
|
||||
DOMAIN = __DOMAIN__
|
||||
HTTP_PORT = __PORT__
|
||||
ROOT_URL = https://__URL__/
|
||||
DISABLE_SSH = false
|
||||
SSH_PORT = 22
|
||||
OFFLINE_MODE = false
|
||||
APP_DATA_PATH = __DATA_PATH__
|
||||
LANDING_PAGE = explore
|
||||
[mailer]
|
||||
ENABLED = true
|
||||
HOST = 127.0.0.1:25
|
||||
FROM = "Gitea" <gitea-noreply@__DOMAIN__>
|
||||
SKIP_VERIFY = true
|
||||
[service]
|
||||
REGISTER_EMAIL_CONFIRM = false
|
||||
ENABLE_NOTIFY_MAIL = true
|
||||
DISABLE_REGISTRATION = true
|
||||
ENABLE_CAPTCHA = false
|
||||
REQUIRE_SIGNIN_VIEW = false
|
||||
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
||||
ENABLE_REVERSE_PROXY_AUTO_REGISTERATION = true
|
||||
[picture]
|
||||
AVATAR_UPLOAD_PATH = __DATA_PATH__/avatars
|
||||
[attachment]
|
||||
PATH = __DATA_PATH__/attachments
|
||||
[session]
|
||||
PROVIDER = memory
|
||||
[log]
|
||||
MODE = file
|
||||
LEVEL = Warn
|
||||
ROOT_PATH = /var/log/__APP__
|
||||
[security]
|
||||
INSTALL_LOCK = true
|
||||
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/go-gitea/gitea/releases/download/v1.3.3/gitea-1.3.3-linux-386
|
||||
SOURCE_SUM=1b746cccffca446876ccc71efe328699f002622dab1d438e2142c8d7c23a22d7
|
||||
# (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
|
3
conf/login_source.sql
Normal file
3
conf/login_source.sql
Normal file
@ -0,0 +1,3 @@
|
||||
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}'
|
16
conf/nginx.conf
Normal file
16
conf/nginx.conf
Normal file
@ -0,0 +1,16 @@
|
||||
#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;
|
||||
}
|
24
conf/systemd.service
Normal file
24
conf/systemd.service
Normal file
@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=Gitea
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
After=mysql.service
|
||||
After=slapd.service
|
||||
|
||||
[Service]
|
||||
# Modify these two values and uncomment them if you have
|
||||
# repos with lots of files and get an HTTP error 500 because
|
||||
# of that
|
||||
###
|
||||
#LimitMEMLOCK=infinity
|
||||
#LimitNOFILE=65535
|
||||
Type=simple
|
||||
User=__APP__
|
||||
Group=__APP__
|
||||
WorkingDirectory=/home/__APP__
|
||||
ExecStart=/opt/__APP__/gogs web
|
||||
Restart=always
|
||||
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
|
66
manifest.json
Normal file
66
manifest.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"package_format": 1,
|
||||
"name": "Gitea",
|
||||
"id": "gitea",
|
||||
"packaging_format": 1,
|
||||
"description": {
|
||||
"en": "Lightweight git forge",
|
||||
"fr": "Forge git légère"
|
||||
},
|
||||
"url": "http://gogs.io",
|
||||
"license": "MIT",
|
||||
"version": "0.11.33~ynh1",
|
||||
"maintainer": {
|
||||
"name": "",
|
||||
"email": ""
|
||||
},
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx",
|
||||
"mysql"
|
||||
],
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.7.9"
|
||||
},
|
||||
"arguments": {
|
||||
"install" : [
|
||||
{
|
||||
"name": "domain",
|
||||
"type": "domain",
|
||||
"ask": {
|
||||
"en": "Choose a domain for Gitea",
|
||||
"fr": "Choisissez un domaine pour Gitea"
|
||||
},
|
||||
"example": "domain.org"
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"type": "path",
|
||||
"ask": {
|
||||
"en": "Choose a path for Gitea",
|
||||
"fr": "Choisissez un chemin pour Gitea"
|
||||
},
|
||||
"example": "/gitea",
|
||||
"default": "/gitea"
|
||||
},
|
||||
{
|
||||
"name": "admin",
|
||||
"type": "user",
|
||||
"ask": {
|
||||
"en": "Choose the Gitea administrator (must be an existing YunoHost user)",
|
||||
"fr": "Choisissez l'administrateur de Gitea (doit être un utilisateur YunoHost existant)"
|
||||
},
|
||||
"example": "johndoe"
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Is it a public site ?",
|
||||
"fr": "Est-ce un site public ?"
|
||||
},
|
||||
"default": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
79
scripts/_common.sh
Normal file
79
scripts/_common.sh
Normal file
@ -0,0 +1,79 @@
|
||||
#=================================================
|
||||
# SET ALL CONSTANTS
|
||||
#=================================================
|
||||
|
||||
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="x86-64"
|
||||
elif [ -n "$(uname -m | grep 86)" ]; then
|
||||
architecture="i386"
|
||||
elif [ -n "$(uname -m | grep arm)" ]; then
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# DEFINE ALL COMMON FONCTIONS
|
||||
#=================================================
|
||||
|
||||
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"
|
||||
}
|
38
scripts/backup
Normal file
38
scripts/backup
Normal file
@ -0,0 +1,38 @@
|
||||
#!/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
|
||||
|
||||
# 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)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
|
||||
# Copy the app source files
|
||||
ynh_backup "$final_path"
|
||||
|
||||
# Copy the data files
|
||||
ynh_backup "$DATADIR"
|
||||
|
||||
# Copy the conf files
|
||||
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
|
||||
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
|
||||
}
|
107
scripts/install
Normal file
107
scripts/install
Normal file
@ -0,0 +1,107 @@
|
||||
#!/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
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
|
||||
# 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 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)
|
||||
|
||||
# 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 $key
|
||||
ynh_app_setting_set $app web_port $port
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
|
||||
# Initialize database and store mysql password for upgrade
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
|
||||
# Add users
|
||||
ynh_system_user_create $app
|
||||
|
||||
# create needed directories
|
||||
create_dir
|
||||
|
||||
# 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
|
||||
|
||||
# Start gogs for building mysql tables
|
||||
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)
|
||||
do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Add ldap config
|
||||
ynh_replace_string "__ADMIN__" "$admin" ../conf/login_source.sql
|
||||
ynh_replace_string "__APP__" "$app" ../conf/login_source.sql
|
||||
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
||||
# Unprotect root from SSO if public
|
||||
if [ "$is_public" = '1' ]
|
||||
then
|
||||
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
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
46
scripts/remove
Normal file
46
scripts/remove
Normal file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
|
||||
# IMPORT GENERIC HELPERS
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
|
||||
# Stop gogs
|
||||
systemctl stop "$app".service
|
||||
|
||||
# Drop MySQL database and user
|
||||
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
|
||||
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
|
||||
ynh_system_user_delete $app
|
||||
|
||||
# Remove init script
|
||||
ynh_remove_systemd_config
|
||||
|
||||
# Remove monitor
|
||||
yunohost service remove "$app"
|
66
scripts/restore
Normal file
66
scripts/restore
Normal file
@ -0,0 +1,66 @@
|
||||
#!/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
|
||||
|
||||
# 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_url=$(ynh_app_setting_get "$app" path)
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
admin=$(ynh_app_setting_get "$app" adminusername)
|
||||
|
||||
# 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 Final Path availability
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
|
||||
# Add users
|
||||
ynh_system_user_create $app
|
||||
|
||||
# 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 systemd files
|
||||
systemctl daemon-reload
|
||||
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
|
||||
yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
||||
|
||||
# Reload services
|
||||
systemctl reload nginx.service
|
||||
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|
110
scripts/upgrade
Normal file
110
scripts/upgrade
Normal file
@ -0,0 +1,110 @@
|
||||
#!/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
|
||||
|
||||
# Load common variables and helpers
|
||||
source ./experimental_helper.sh
|
||||
source ./_common.sh
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
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
|
||||
systemctl stop "$app".service
|
||||
|
||||
#=================================================
|
||||
# MIGRATION FROM OLD VERSION
|
||||
#=================================================
|
||||
|
||||
# Update settings is_public to new standard
|
||||
if [ "$is_public" = "Yes" ]; then
|
||||
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
|
||||
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
|
||||
# but not in the new
|
||||
# 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
|
||||
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
||||
mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH" || true # Avoid if the directory is empty
|
||||
# cleanup old dir and conf
|
||||
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
|
||||
|
||||
# test if user gogs is locked because of an old installation of the package.
|
||||
# if it's blocked, unlock it to allow ssh usage with git
|
||||
if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
|
||||
then
|
||||
usermod -p '*' "$app"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
|
||||
# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
|
||||
ynh_secure_remove "/opt/gogs/templates"
|
||||
|
||||
# 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 New Issue
Block a user