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

Use new helpers and remove sudo in each command and factorise code

This commit is contained in:
Josué Tille 2018-02-07 00:31:25 +01:00
parent 9a54f33238
commit 6bc53fd637
14 changed files with 258 additions and 246 deletions

View file

@ -3,6 +3,10 @@
Gogs is a self-hosted Git service written in Go. Alternative to Github.
- [Gogs website](http://gogs.io)
[![Integration level](https://dash.yunohost.org/integration/gogs.svg)](https://ci-apps.yunohost.org/jenkins/job/gogs%20%28Community%29/lastBuild/consoleFull)
[![Install Gogs with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=gogs)
## Requirements
A functional instance of [YunoHost](https://yunohost.org)
@ -44,12 +48,16 @@ Also, in some cases, Gogs will not restart properly during the update. If so, yo
Sources and issues of the old package can be found [here](https://github.com/YunoHost-Apps/gogs_ynh_old/)
## Info
Gogs v0.11.19
Gogs v0.11.34
- [YunoHost forum thread](https://forum.yunohost.org/t/gogs-package-an-awesome-github-alternative/1127)
Architecture: this package is compatible with amd64, i386 and arm. The package will try to detect it with the command uname -m and fail if it can't detect the architecture. If that happens please open an issue describing your hardware and the result of the command `uname -m`.
## Issue
Any issue is welcome here : https://github.com/YunoHost-Apps/gogs_ynh/issues
## License
Gogs is published under the MIT License:
https://github.com/gogits/gogs/blob/master/LICENSE

11
conf/arm.src Normal file
View 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
View 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

View file

@ -1,5 +1,5 @@
location PATHTOCHANGE/ {
COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
proxy_pass http://localhost:6000/;
proxy_set_header Host $host;
proxy_buffering off;

11
conf/x86-64.src Normal file
View 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

View file

@ -9,7 +9,7 @@
},
"url": "http://gogs.io",
"license": "MIT",
"version": "0.11.19",
"version": "0.11.34~ynh1",
"maintainer": {
"name": "tostaki",
"email": "maxime@max.privy.place"
@ -54,12 +54,12 @@
},
{
"name": "public_site",
"type": "boolean",
"ask": {
"en": "Is it a public site ?",
"fr": "Est-ce un site public ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
"default": true
}
]
}

View file

@ -1,46 +1,89 @@
#
# Common variables
#
APPNAME="gogs"
# Gogs version
VERSION="0.11.19"
app=$YNH_APP_INSTANCE_NAME
final_path="/opt/$app"
dbname=$app
dbuser=$app
REPO_PATH="/home/$app/repositories"
DATA_PATH="/home/$app/data"
# Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
if [ -n "$(uname -m | grep 64)" ]; then
ARCHITECTURE="linux_amd64"
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
ARCHITECTURE="linux_386"
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
ARCHITECTURE="raspi2_armv6"
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi
create_dir() {
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() {
cp ../conf/app.ini "$final_path"/custom/conf
ynh_replace_string "yuno_repo_path" "$REPO_PATH" "$final_path"/custom/conf/app.ini
if [ "$path_url" = "/" ]
then
ynh_replace_string "yuno_url" "$domain" "$final_path"/custom/conf/app.ini
else
ynh_replace_string "yuno_url" "$domain${path_url%/}" "$final_path"/custom/conf/app.ini
fi
ynh_replace_string "yuno_dbpdw" "$dbpass" "$final_path"/custom/conf/app.ini
ynh_replace_string "yuno_dbuser" "$dbuser" "$final_path"/custom/conf/app.ini
ynh_replace_string "yuno_domain" "$domain" "$final_path"/custom/conf/app.ini
ynh_replace_string "yuno_key" "$key" "$final_path"/custom/conf/app.ini
ynh_replace_string "yuno_data_path" "$DATA_PATH" "$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"
}
# Remote URL to fetch Gogs tarball
GOGS_BINARY_URL="https://github.com/gogits/gogs/releases/download/v${VERSION}/${ARCHITECTURE}.zip"
# GOGS_BINARY_URL="https://github.com/gogits/gogs/releases/download/v${VERSION}/${architecture}.zip"
#
# Common helpers
#
# Download and extract Gogs binary to the given directory
# usage: extract_gogs DESTDIR
extract_gogs() {
local DESTDIR=$1
local TMPDIR=$(mktemp -d)
# retrieve and extract Gogs tarball
gogs_tarball="/tmp/gogs.zip"
rm -f "$gogs_tarball"
wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
|| ynh_die "Unable to download Gogs tarball"
unzip -q "$gogs_tarball" -d "$TMPDIR" \
|| ynh_die "Unable to extract Gogs tarball"
sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR"
rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}"
}
# # usage: extract_gogs DESTDIR
# extract_gogs() {
# # local DESTDIR=$1
# # local TMPDIR=$(mktemp -d)
# #
# # # retrieve and extract Gogs tarball
# # gogs_tarball="/tmp/gogs.zip"
# # rm -f "$gogs_tarball"
# # wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
# # || ynh_die "Unable to download Gogs tarball"
# # unzip -q "$gogs_tarball" -d "$TMPDIR" \
# # || ynh_die "Unable to extract Gogs tarball"
# # sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR"
# # rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}"
#
# }

View file

@ -1,33 +1,28 @@
#!/bin/bash
set -euo pipefail
# Set app specific variables
app=${APPNAME:-gogs}
dbname=$app
dbuser=$app
# Source app helpers
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
repo_path=$(ynh_app_setting_get "$app" repopath)
# Copy the app source files
DESTDIR="/opt/$app"
ynh_backup "$DESTDIR" "www"
ynh_backup "$DESTDIR"
# Copy the data files
DATADIR="/home/$app"
ynh_backup "$DATADIR" "data"
ynh_backup "$DATADIR"
# Copy the conf files
mkdir ./conf
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
ynh_backup "/etc/logrotate.d/${app}" "conf/logrotate"
ynh_backup "/etc/systemd/system/${app}.service" "conf/systemd.service"
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf"
ynh_backup "/etc/systemd/system/${app}.service"
# Dump the database
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql
ynh_mysql_dump_db "$dbname" > ./db.sql

View file

@ -0,0 +1 @@

View file

@ -1,37 +1,31 @@
#!/bin/bash
set -euo pipefail
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_PUBLIC_SITE
# Load common variables
source ./_common.sh
# Set app specific variables
app=${APPNAME:-gogs}
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "The path ${domain}${path} is not available for app installation."
# Check domain/path availability
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
ynh_webpath_register $app $domain $path_url
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
# Check destination directory
DESTDIR="/opt/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app."
# Check Final Path availability
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Generate random password and key
dbpass=$(ynh_string_random)
@ -45,45 +39,35 @@ ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app secret_key $is_public
# Add users
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
id -u "$app" &>/dev/null || sudo adduser "$app" \
--ingroup "$app" --system --quiet --shell /bin/bash
ynh_system_user_create $app
# id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
# id -u "$app" &>/dev/null || sudo adduser "$app" \
# --ingroup "$app" --system --quiet --shell /bin/bash
# create needed directories
REPO_PATH=/home/"$app"/repositories
DATA_PATH=/home/"$app"/data
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app"
sudo chown -R "$app":"$app" /home/"$app" /var/log/"$app"
create_dir
# Create uploads folder and permissions
mkdir /opt/$app/data
# Install Gogs
extract_gogs $DESTDIR
ynh_setup_source $final_path $architecture
# Configure gogs with app.ini file
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
sudo sed -i "s@yuno_repo_path@"$REPO_PATH"@g" "$DESTDIR"/custom/conf/app.ini
if [ "$path" = "/" ]
then
sudo sed -i "s@yuno_url@$domain@g" "$DESTDIR"/custom/conf/app.ini
else
sudo sed -i "s@yuno_url@$domain${path%/}@g" "$DESTDIR"/custom/conf/app.ini
fi
sudo sed -i "s@yuno_dbpdw@$dbpass@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_dbuser@$dbuser@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_domain@$domain@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_key@$key@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_data_path@$DATA_PATH@g" "$DESTDIR"/custom/conf/app.ini
# Configure logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/"$app"
config_gogs
# Configure init script
sudo cp ../conf/gogs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable "$app".service
ynh_add_systemd_config
# Modify Nginx configuration file and copy it to Nginx conf directory
config_nginx
# Start gogs for building mysql tables
sudo systemctl start "$app".service
systemctl start "$app".service
# Set permissions
set_permission
# Wait till login_source mysql table is created
while ! $(ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
@ -92,33 +76,20 @@ do
done
# Add ldap config
sudo sed -i "s@yuno_admin@$admin@g" ../conf/login_source.sql
ynh_replace_string "yuno_admin" "$admin" ../conf/login_source.sql
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
# Add Gogs to YunoHost's monitored services
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf
if [ "$path" = "/" ]
then
sed -i "s@COMMENT_IF_ROOT@#@g" ../conf/nginx.conf
else
sed -i "s@COMMENT_IF_ROOT@@g" ../conf/nginx.conf
fi
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf
# Create uploads folder and permissions
sudo mkdir /opt/gogs/data
sudo chown -R gogs /opt/gogs/data
# Unprotect root from SSO if public
if [ "$is_public" = "Yes" ]
then
ynh_app_setting_set $app unprotected_uris "/"
fi
# Add Gogs to YunoHost's monitored services
yunohost service add "$app" --log "/var/log/$app/$app.log"
# Configure logrotate
ynh_use_logrotate "/var/log/$app"
# Reload services
sudo systemctl restart rsyslog.service || true
sudo systemctl reload nginx.service || true
sudo systemctl restart "$app".service || true
systemctl restart "$app".service

View file

@ -1,46 +1,42 @@
#!/bin/bash
# Exit and treat unset variables as an error
set -u
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
# Set app specific variables
app=${APPNAME:-gogs}
app=$YNH_APP_INSTANCE_NAME
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Stop gogs
sudo systemctl stop "$app".service
systemctl stop "$app".service
# Drop MySQL database and user
ynh_mysql_drop_db "$dbname" 2>/dev/null || true
ynh_mysql_drop_user "$dbuser" 2>/dev/null || true
ynh_mysql_drop_db "$dbname" 2>/dev/null
ynh_mysql_drop_user "$dbuser" 2>/dev/null
# Retrieve domain from app settings
domain=$(ynh_app_setting_get "$app" domain)
# Delete app directory and configurations
sudo rm -rf "/opt/${app}"
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
sudo rm -rf /var/log/"$app"
sudo rm -f /etc/logrotate.d/"$app"
ynh_secure_remove "/opt/${app}"
ynh_secure_remove "/var/log/$app"
# Remove the app-specific logrotate config
ynh_remove_logrotate
# Remove nginx config
ynh_remove_nginx_config
# Remove gogs user and data
sudo userdel -r "$app"
ynh_system_user_delete $app
# Remove init script
sudo systemctl disable "$app".service
sudo rm -f /etc/systemd/system/"$app".service
sudo systemctl daemon-reload
ynh_remove_systemd_config
# Remove monitor
sudo yunohost service remove "$app"
# Reload services
sudo systemctl restart rsyslog.service || true
sudo systemctl reload nginx.service || true
yunohost service remove "$app"

View file

@ -1,72 +1,56 @@
#!/bin/bash
set -euo pipefail
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
# Set app specific variables
app=${APPNAME:-gogs}
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path_url=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
admin=$(ynh_app_setting_get "$app" adminusername)
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "The path ${domain}${path} is not available for app installation."
# Check domain/path availability with app helper
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
# Check destination directory
DESTDIR="/opt/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app."
# Check Final Path availability
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Add users
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
id -u "$app" &>/dev/null || sudo adduser "$app" \
--ingroup "$app" --system --quiet --shell /bin/bash
ynh_system_user_create $app
# Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $nginx_conf ]] && ynh_die \
"The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
# Restore the app files
sudo cp -a ./www "$DESTDIR"
# Restore the data
sudo cp -a ./data/. "/home/gogs"
# Restore all files
ynh_restore
# Create and restore the database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
# Restore directories and permissions
sudo mkdir -p /var/log/"$app"
sudo chown -R root:root "$DESTDIR"
sudo chown -R "$app":"$app" "/home/gogs" "/var/log/$app"
# Restore configuration files
sudo cp -a ./conf/nginx.conf "$nginx_conf"
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app"
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
sudo systemctl daemon-reload
sudo systemctl enable "$app".service
systemctl daemon-reload
systemctl enable "$app".service
# Configure logrotate
ynh_use_logrotate "/var/log/$app"
# Add Gogs to YunoHost's monitored services
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
yunohost service add "$app" --log /var/log/"$app"/"$app".log
# Reload services
sudo systemctl restart rsyslog.service || true
sudo systemctl reload nginx.service || true
sudo systemctl restart "$app".service || true
systemctl reload nginx.service
systemctl restart "$app".service

View file

@ -1,33 +1,46 @@
#!/bin/bash
set -euo pipefail
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
# Set app specific variables
app=${APPNAME:-gogs}
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
path_url=$(ynh_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)
# Stop service
sudo systemctl stop "$app".service
# Backup the current version of the app
if [[ $(ynh_app_setting_get $app disable_backup_before_upgrade) != '1' ]]
then
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_restore_upgradebackup
}
fi
# set directories variables
DESTDIR="/opt/$app"
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
# Stop service
systemctl stop "$app".service
# create needed directories if not already created
create_dir
# handle upgrade from old package installation
# this test that /etc/gogs exist since this was used in the old package
@ -36,74 +49,42 @@ DATA_PATH=/home/"$app"/data
if [ -d "/etc/gogs" ]
then
# move repositories to new dir
sudo mkdir -p "$REPO_PATH"
old_repo_path=$(ynh_app_setting_get "$app" repopath)
sudo mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH"
mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH"
# cleanup old dir and conf
sudo unlink /opt/gogs
sudo rm -rf /etc/gogs /opt/gogs_src
unlink /opt/gogs
ynh_secure_remove /etc/gogs
ynh_secure_remove /opt/gogs_src
fi
# end of old package upgrade
# create needed directories and give correct acl
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app"
sudo chown -R "$app":"$app" /home/"$app" /var/log/"$app"
# Install Gogs
extract_gogs $DESTDIR
ynh_setup_source $final_path $architecture
# Configure gogs with app.ini file
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
sudo sed -i "s@yuno_repo_path@"$REPO_PATH"@g" "$DESTDIR"/custom/conf/app.ini
if [ "$path" = "/" ]
then
sudo sed -i "s@yuno_url@$domain@g" "$DESTDIR"/custom/conf/app.ini
else
sudo sed -i "s@yuno_url@$domain${path%/}@g" "$DESTDIR"/custom/conf/app.ini
fi
sudo sed -i "s@yuno_dbpdw@$dbpass@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_dbuser@$dbuser@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_domain@$domain@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_key@$key@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_data_path@$DATA_PATH@g" "$DESTDIR"/custom/conf/app.ini
config_gogs
# 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"
ynh_add_systemd_config
# 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
config_nginx
# Unprotect root from SSO if public
if [ "$is_public" = "Yes" ]
if [ "$is_public" ]
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
# Set permissions
set_permission
# test if user gogs is locked because of an old installation of the package.
# if it's blocked, unlock it to allow ssh usage with git
if [[ $(sudo grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
then
sudo usermod -p '*' "$app"
usermod -p '*' "$app"
fi
# Reload services
systemctl restart "$app".service