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 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.19 Gogs v0.11.34
- [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

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/ { #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
COMMENT_IF_ROOTrewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent; location __PATH__/ {
proxy_pass http://localhost:6000/; proxy_pass http://localhost:6000/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_buffering off; 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", "url": "http://gogs.io",
"license": "MIT", "license": "MIT",
"version": "0.11.19", "version": "0.11.34~ynh1",
"maintainer": { "maintainer": {
"name": "tostaki", "name": "tostaki",
"email": "maxime@max.privy.place" "email": "maxime@max.privy.place"
@ -54,12 +54,12 @@
}, },
{ {
"name": "public_site", "name": "public_site",
"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"
} }
] ]
} }

View file

@ -1,46 +1,89 @@
# #
# Common variables # Common variables
# #
app=$YNH_APP_INSTANCE_NAME
APPNAME="gogs" final_path="/opt/$app"
dbname=$app
# Gogs version dbuser=$app
VERSION="0.11.19" REPO_PATH="/home/$app/repositories"
DATA_PATH="/home/$app/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
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 # 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 # Common helpers
# #
# Download and extract Gogs binary to the given directory # Download and extract Gogs binary to the given directory
# usage: extract_gogs DESTDIR # # usage: extract_gogs DESTDIR
extract_gogs() { # extract_gogs() {
local DESTDIR=$1 # # local DESTDIR=$1
local TMPDIR=$(mktemp -d) # # local TMPDIR=$(mktemp -d)
# #
# retrieve and extract Gogs tarball # # # retrieve and extract Gogs tarball
gogs_tarball="/tmp/gogs.zip" # # gogs_tarball="/tmp/gogs.zip"
rm -f "$gogs_tarball" # # rm -f "$gogs_tarball"
wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \ # # wget -q -O "$gogs_tarball" "$GOGS_BINARY_URL" \
|| ynh_die "Unable to download Gogs tarball" # # || ynh_die "Unable to download Gogs tarball"
unzip -q "$gogs_tarball" -d "$TMPDIR" \ # # unzip -q "$gogs_tarball" -d "$TMPDIR" \
|| ynh_die "Unable to extract Gogs tarball" # # || ynh_die "Unable to extract Gogs tarball"
sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR" # # sudo rsync -a "$TMPDIR"/gogs/* "$DESTDIR"
rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}" # # rm -rf "$gogs_tarball" "${TMPDIR:-/tmp/fakefile}"
} #
# }

View file

@ -1,33 +1,28 @@
#!/bin/bash #!/bin/bash
set -euo pipefail # IMPORT GENERIC HELPERS
# Set app specific variables
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 ./experimental_helper.sh
source ./_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)
# Copy the app source files # Copy the app source files
DESTDIR="/opt/$app" ynh_backup "$DESTDIR"
ynh_backup "$DESTDIR" "www"
# Copy the data files # Copy the data files
DATADIR="/home/$app" DATADIR="/home/$app"
ynh_backup "$DATADIR" "data" ynh_backup "$DATADIR"
# 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"
# Dump the database # 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 #!/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 # 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_PUBLIC_SITE
# 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)
@ -45,45 +39,35 @@ 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 $is_public
# 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 # 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 # 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 \ # Create uploads folder and permissions
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app" mkdir /opt/$app/data
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 +76,20 @@ do
done done
# Add ldap config # 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 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 # Unprotect root from SSO if public
if [ "$is_public" = "Yes" ] if [ "$is_public" = "Yes" ]
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 systemctl restart "$app".service
sudo systemctl reload nginx.service || true
sudo systemctl restart "$app".service || true

View file

@ -1,46 +1,42 @@
#!/bin/bash #!/bin/bash
# Exit and treat unset variables as an error # IMPORT GENERIC HELPERS
set -u source /usr/share/yunohost/helpers
# Load common variables and helpers # Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Set app specific variables # Set app specific variables
app=${APPNAME:-gogs} app=$YNH_APP_INSTANCE_NAME
dbname=$app dbname=$app
dbuser=$app dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# 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 "/opt/${app}"
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" ynh_secure_remove "/var/log/$app"
sudo rm -rf /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

View file

@ -1,72 +1,56 @@
#!/bin/bash #!/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 # Set app specific variables
app=${APPNAME:-gogs} app=${APPNAME:-gogs}
dbname=$app dbname=$app
dbuser=$app dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# 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."
# 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
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 # Restore configuration files
sudo cp -a ./conf/nginx.conf "$nginx_conf" systemctl daemon-reload
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app" systemctl enable "$app".service
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
sudo systemctl daemon-reload # Configure logrotate
sudo systemctl enable "$app".service 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 systemctl restart "$app".service
sudo systemctl restart "$app".service || true

View file

@ -1,33 +1,46 @@
#!/bin/bash #!/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 # 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_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)
# Stop service # Backup the current version of the app
sudo systemctl stop "$app".service 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 # Update settings is_public to new standard
DESTDIR="/opt/$app" if [ "$is_public" = "Yes" ]; then
REPO_PATH=/home/"$app"/repositories ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
DATA_PATH=/home/"$app"/data 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 # 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
@ -36,74 +49,42 @@ DATA_PATH=/home/"$app"/data
if [ -d "/etc/gogs" ] if [ -d "/etc/gogs" ]
then then
# 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"
# cleanup old dir and conf # cleanup old dir and conf
sudo unlink /opt/gogs unlink /opt/gogs
sudo rm -rf /etc/gogs /opt/gogs_src ynh_secure_remove /etc/gogs
ynh_secure_remove /opt/gogs_src
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 # 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 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
# Configure logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/"$app"
# Modify Nginx configuration file and copy it to Nginx conf directory # Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf config_nginx
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 # Unprotect root from SSO if public
if [ "$is_public" = "Yes" ] if [ "$is_public" ]
then then
ynh_app_setting_set $app unprotected_uris "/" ynh_app_setting_set $app unprotected_uris "/"
fi fi
# Reload services # Set permissions
sudo systemctl restart rsyslog.service || true set_permission
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
# Reload services
systemctl restart "$app".service