2018-02-25 21:45:24 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# Find available ports
|
|
|
|
port=$(ynh_find_port 6000)
|
|
|
|
|
|
|
|
# Store Settings
|
|
|
|
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 $key
|
|
|
|
ynh_app_setting_set $app web_port $port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2018-05-03 12:36:32 +02:00
|
|
|
|
|
|
|
# Configure init script
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
config_nginx
|
|
|
|
|
2018-02-25 21:45:24 +01:00
|
|
|
# Initialize database and store mysql password for upgrade
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
|
|
|
# Add users
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
# create needed directories
|
|
|
|
create_dir
|
|
|
|
|
2018-04-30 15:56:19 +02:00
|
|
|
# Configure init script
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
config_nginx
|
|
|
|
|
2018-05-10 16:31:54 +02:00
|
|
|
# Configure gitea with app.ini file
|
2018-05-15 10:57:25 +02:00
|
|
|
cp -a ../conf/app.ini $final_path
|
2018-05-10 16:31:54 +02:00
|
|
|
config_gitea
|
|
|
|
|
2018-05-09 17:59:23 +02:00
|
|
|
# Install gitea
|
2018-02-26 10:55:19 +01:00
|
|
|
cd $final_path
|
2018-04-27 09:26:40 +02:00
|
|
|
wget https://github.com/go-gitea/gitea/releases/download/v1.3.3/gitea-1.3.3-linux-amd64
|
2018-04-24 16:41:03 +02:00
|
|
|
mv gitea-1.3.3-linux-amd64 gitea
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2018-05-09 17:59:23 +02:00
|
|
|
# Start gitea for building mysql tables
|
2018-02-25 21:45:24 +01:00
|
|
|
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 "__ADMIN__" "$admin" ../conf/login_source.sql
|
|
|
|
ynh_replace_string "__APP__" "$app" ../conf/login_source.sql
|
|
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Unprotect root from SSO if public
|
|
|
|
if [ "$is_public" = '1' ]
|
|
|
|
then
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
2018-05-09 17:59:23 +02:00
|
|
|
# Add gitea to YunoHost's monitored services
|
2018-02-25 21:45:24 +01:00
|
|
|
yunohost service add "$app" --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
# Configure logrotate
|
|
|
|
ynh_use_logrotate "/var/log/$app"
|
|
|
|
|
|
|
|
# Reload services
|
2018-05-09 17:59:23 +02:00
|
|
|
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gitea.log"
|