1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gogs_ynh.git synced 2024-09-03 20:36:23 +02:00

Initial commit

This commit is contained in:
mbugeia 2016-08-15 15:38:50 +02:00
commit 706b3f1f5b
16 changed files with 701 additions and 0 deletions

17
.gitattributes vendored Normal file
View file

@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

50
.gitignore vendored Normal file
View file

@ -0,0 +1,50 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# From kateproject
.kateproject
.kateproject.d
.directory
*.tar.gz

22
LICENSE Normal file
View 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.

61
README.markdown Normal file
View file

@ -0,0 +1,61 @@
Gogs for Yunohost
=================
Gogs is a self-hosted Git service written in Go. Alternative to Github.
Official website: <http://gogs.io/>
Requirements
------------
Functionnal instance of [Yunohost](https://yunohost.org/#/)
Installation
------------
From command line:
`sudo yunohost app install -l Gogs https://github.com/YunoHost-Apps/gogs_ynh`
Upgrade
-------
From command line:
`sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/gogs_ynh gogs`
Infos
-----
Gogs v0.9.71
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 arch and fail if it can't find it.
License
-------
Gogs is published under MIT License
https://github.com/gogits/gogs/blob/master/LICENSE
This package is published under MIT License
TODO
----
- Backup and restore script need rework
Developper infos
----------------
Please do your pull request to the dev branch.
```
Test or upgrade to dev version:
```
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
```

51
conf/app.ini Normal file
View file

@ -0,0 +1,51 @@
;https://github.com/gogits/gogs/blob/master/conf/app.ini
APP_NAME = Gogs: Go Git Service
RUN_USER = gogs
RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306
NAME = yuno_dbuser
USER = yuno_dbuser
PASSWD = yuno_dbpdw
SSL_MODE = disable
PATH = data/gogs.db
[repository]
ROOT = yuno_repo_path
FORCE_PRIVATE = false
[server]
DOMAIN = yuno_domain
HTTP_PORT = 6000
ROOT_URL = https://yuno_url/
DISABLE_SSH = false
SSH_PORT = 22
OFFLINE_MODE = false
APP_DATA_PATH = yuno_data_path
LANDING_PAGE = explore
[mailer]
ENABLED = true
HOST = 127.0.0.1:25
FROM = "Gogs" <gogs-noreply@yuno_domain>
SKIP_VERIFY = true
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
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 = yuno_data_path/avatars
[attachment]
PATH = yuno_data_path/attachments
[session]
PROVIDER = memory
[log]
MODE = file
LEVEL = Warn
ROOT_PATH = /var/log/gogs
[security]
INSTALL_LOCK = true
SECRET_KEY = yuno_key
REVERSE_PROXY_AUTHENTICATION_USER = REMOTE_USER

24
conf/gogs.service Normal file
View file

@ -0,0 +1,24 @@
[Unit]
Description=Gogs (Go Git Service)
After=syslog.target
After=network.target
After=mysqld.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=gogs
Group=gogs
WorkingDirectory=/home/gogs
ExecStart=/opt/gogs/gogs web
Restart=always
Environment=USER=gogs HOME=/home/gogs
[Install]
WantedBy=multi-user.target

3
conf/login_source.sql Normal file
View file

@ -0,0 +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}'

10
conf/logrotate Normal file
View file

@ -0,0 +1,10 @@
# gogs logs:
/var/log/gogs/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
}

11
conf/nginx.conf Normal file
View file

@ -0,0 +1,11 @@
location PATHTOCHANGE/ {
COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
proxy_pass http://localhost:6000/;
proxy_set_header Host $host;
proxy_buffering off;
fastcgi_param REMOTE_USER $remote_user;
client_max_body_size 50M;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

56
manifest.json Normal file
View file

@ -0,0 +1,56 @@
{
"name": "Gogs",
"id": "gogs",
"description": {
"en": "A self-hosted Git service written in Go",
"fr": "A self-hosted Git service written in Go"
},
"url": "http://gogs.io/",
"maintainer": {
"name": "mbugeia",
"email": "maxime@max.privy.place"
},
"multi_instance": "false",
"services": [
"nginx",
"mysql"
],
"arguments": {
"install" : [
{
"name": "domain",
"ask": {
"en": "Choose a domain for Gogs",
"fr": "Choisissez un domaine pour Gogs"
},
"example": "domain.org"
},
{
"name": "path",
"ask": {
"en": "Choose a path for Gogs",
"fr": "Choisissez un chemin pour Gogs"
},
"example": "/gogs",
"default": "/gogs"
},
{
"name": "admin",
"ask": {
"en": "Choose the admin user for Gogs (must be an existing yunohost user)",
"fr": "Choisissez l'administrateur de Gogs (doit être un utilisateur yunohost existant)"
},
"example": "johndoe"
},
{
"name": "public_site",
"ask": {
"en": "Is it a public site ?",
"fr": "Est-ce un site public ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
}
]
}
}

42
scripts/_common.sh Normal file
View file

@ -0,0 +1,42 @@
#
# Common variables
#
APPNAME="gogs"
# Gogs version
VERSION="0.9.71"
# Detect the system architecture to download the right tarball
case $(arch) in
x86_64) ARCHITECTURE="amd64"
;;
i386) ARCHITECTURE="386"
;;
armhf|armel) ARCHITECTURE="arm"
;;
*) echo "Unable to detect your achitecture" && exit 1
;;
esac
# Remote URL to fetch Gogs tarball
GOGS_BINARY_URL="https://github.com/gogits/gogs/releases/download/v${VERSION}/linux_${ARCHITECTURE}.tar.gz"
#
# Common helpers
#
# Download and extract Gogs binary to the given directory
# usage: extract_gogs DESTDIR
extract_gogs() {
local DESTDIR=$1
# retrieve and extract Gogs tarball
gogs_tarball="/tmp/gogs.tar.gz"
rm -f "$gogs_tarball"
wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
|| ynh_die "Unable to download Gogs tarball"
sudo tar xf "$gogs_tarball" -C "$DESTDIR" --strip-components 1 \
|| ynh_die "Unable to extract Gogs tarball"
rm -f "$gogs_tarball"
}

33
scripts/backup Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
set -eu
# Set app specific variables
app="gogs"
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# 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)
# Copy the app source files
DESTDIR="/opt/$app"
ynh_backup "$DESTDIR" "www"
# Copy the data files
DATADIR="/home/$app"
ynh_backup "$DATADIR" "data"
# 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"
# Dump the database
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql

120
scripts/install Normal file
View file

@ -0,0 +1,120 @@
#!/bin/bash
set -eu
# Retrieve arguments
domain=$1
path=$2
admin=$3
is_public=$4
# Load common variables
source ./_common.sh
# Set app specific variables
app=$APPNAME
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
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."
# 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"
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
# Add users
id -g gogs &>/dev/null || sudo addgroup gogs --system --quiet
id -u gogs &>/dev/null || sudo adduser gogs --disabled-login \
--ingroup gogs --system --quiet --shell /bin/bash
# create needed directories
REPO_PATH=/home/gogs/repositories
DATA_PATH=/home/gogs/data
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/gogs
sudo chown -R gogs:gogs /home/gogs /var/log/gogs
# 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 logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/gogs
# Configure init script
sudo cp ../conf/gogs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable gogs.service
# Start gogs for building mysql tables
sudo systemctl start gogs.service
# 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
sudo sed -i "s@yuno_admin@$admin@g" ../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 gogs --log /var/log/gogs.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
# Unprotect root from SSO if public
if [ "$is_public" = "Yes" ]
then
ynh_app_setting_set $app unprotected_uris "/"
fi
# Reload services
sudo service rsyslog restart || true
sudo service nginx reload || true
sudo service gogs restart || true

43
scripts/remove Normal file
View file

@ -0,0 +1,43 @@
#!/bin/bash
# Load common variables and helpers
source ./_common.sh
# Set app specific variables
app=$APPNAME
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Stop gogs
sudo systemctl stop gogs.service
# Drop MySQL database and user
ynh_mysql_drop_db "$dbname" 2>/dev/null || true
ynh_mysql_drop_user "$dbuser" 2>/dev/null || true
# 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/gogs
sudo rm -f /etc/logrotate.d/gogs
# Remove gogs user and data
sudo userdel -r gogs
# Remove init script
sudo systemctl disable gogs.service
sudo rm -f /etc/systemd/system/gogs.service
sudo systemctl daemon-reload
# Remove monitor
sudo yunohost service remove gogs
# Reload services
sudo service nginx reload || true
sudo service rsyslog restart || true

71
scripts/restore Normal file
View file

@ -0,0 +1,71 @@
#!/bin/bash
set -eu
# Set app specific variables
app="gogs"
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(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 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."
# Add users
id -g gogs &>/dev/null || sudo addgroup gogs --system --quiet
id -u gogs &>/dev/null || sudo adduser gogs --disabled-login --ingroup gogs --system --quiet --shell /bin/bash
# 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"
# 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/gogs
sudo chown -R root:root "$DESTDIR"
sudo chown -R gogs:gogs "/home/gogs" "/var/log/gogs"
# Restore configuration files
sudo cp -a ./conf/nginx.conf "$nginx_conf"
sudo cp -a ./conf/logrotate /etc/logrotate.d/gogs
sudo cp -a ./conf/systemd.service /etc/systemd/system/gogs.service
sudo systemctl daemon-reload
sudo systemctl enable gogs.service
# Add Gogs to YunoHost's monitored services
sudo yunohost service add gogs --log /var/log/gogs.log
# Reload services
sudo service nginx reload || true
sudo service rsyslog restart || true
sudo service gogs start || true

87
scripts/upgrade Normal file
View file

@ -0,0 +1,87 @@
#!/bin/bash
set -eu
# Load common variables and helpers
source ./_common.sh
# Set app specific variables
app=$APPNAME
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)
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)
repo_path=$(ynh_app_setting_get "$app" repopath)
# Stop service
sudo systemctl stop gogs.service
DESTDIR="/opt/$app"
# create needed directories
REPO_PATH=/home/gogs/repositories
DATA_PATH=/home/gogs/data
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/gogs
sudo chown -R gogs:gogs /home/gogs /var/log/gogs
# 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 gogs.service
# Configure logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/gogs
# 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
# 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 service rsyslog restart || true
sudo service nginx reload || true
sudo service gogs start || true