2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# 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
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Retrieve arguments
|
2017-04-05 21:06:22 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-05-19 20:21:44 +02:00
|
|
|
path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH)
|
2017-04-05 21:06:22 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2018-02-07 23:49:32 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# 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
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Check user parameter
|
|
|
|
ynh_user_exists "$admin" \
|
|
|
|
|| ynh_die "The chosen admin user does not exist."
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# Check Final Path availability
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Generate random password and key
|
|
|
|
dbpass=$(ynh_string_random)
|
|
|
|
key=$(ynh_string_random)
|
|
|
|
|
2018-02-08 00:09:28 +01:00
|
|
|
# Find available ports
|
|
|
|
port=$(ynh_find_port 6000)
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
# Store Settings
|
2016-08-15 15:38:50 +02:00
|
|
|
ynh_app_setting_set $app mysqlpwd $dbpass
|
|
|
|
ynh_app_setting_set $app adminusername $admin
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2018-02-08 17:25:54 +01:00
|
|
|
ynh_app_setting_set $app secret_key $key
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_app_setting_set $app web_port $port
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Initialize database and store mysql password for upgrade
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Add users
|
2018-03-04 16:48:08 +01:00
|
|
|
# We can't use the official helper because we need to set the shell for the login
|
|
|
|
test getent passwd "$app" &>/dev/null || \
|
|
|
|
useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \
|
|
|
|
ynh_die "Unable to create $app system account"
|
2018-02-07 00:31:25 +01:00
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# create needed directories
|
2018-02-07 00:31:25 +01:00
|
|
|
create_dir
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Install Gogs
|
2018-02-07 00:31:25 +01:00
|
|
|
ynh_setup_source $final_path $architecture
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Configure gogs with app.ini file
|
2018-02-07 00:31:25 +01:00
|
|
|
config_gogs
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Configure init script
|
2018-02-07 00:31:25 +01:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
config_nginx
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Start gogs for building mysql tables
|
2018-02-07 00:31:25 +01:00
|
|
|
systemctl start "$app".service
|
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
set_permission
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# 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
|
2018-02-08 11:42:15 +01:00
|
|
|
ynh_replace_string "__ADMIN__" "$admin" ../conf/login_source.sql
|
2018-02-08 10:11:36 +01:00
|
|
|
ynh_replace_string "__APP__" "$app" ../conf/login_source.sql
|
2016-08-15 15:38:50 +02:00
|
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Unprotect root from SSO if public
|
2018-04-25 10:52:42 +02:00
|
|
|
set_access_settings
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# 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"
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Reload services
|
2018-02-10 18:04:23 +01:00
|
|
|
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|