1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gogs_ynh.git synced 2024-09-03 20:36:23 +02:00
gogs_ynh/scripts/install
2018-02-10 17:15:09 +01:00

95 lines
2.4 KiB
Bash

#!/bin/bash
# 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)
# 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
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
create_dir
# Create uploads folder and permissions
mkdir /opt/$app/data
# 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 "yuno_admin" "$admin" ../conf/login_source.sql
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
# 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
systemctl restart "$app".service