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
|
|
|
|
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
2018-02-25 21:45:24 +01:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2019-10-01 21:34:41 +02:00
|
|
|
path_url=$(ynh_normalize_url_path --path_url $YNH_APP_ARG_PATH)
|
2018-02-25 21:45:24 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2019-08-01 15:32:59 +02:00
|
|
|
upstream_version=$(ynh_app_upstream_version)
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2019-08-01 14:01:59 +02:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app $app --domain $domain --path_url $path_url
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Check user parameter
|
|
|
|
ynh_user_exists "$admin" \
|
2019-08-01 14:01:59 +02:00
|
|
|
|| ynh_die --message "The chosen admin user does not exist."
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Check Final Path availability
|
2019-08-01 14:01:59 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Generate random password and key
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Defining db password and key..."
|
2018-02-25 21:45:24 +01:00
|
|
|
dbpass=$(ynh_string_random)
|
|
|
|
key=$(ynh_string_random)
|
|
|
|
|
|
|
|
# Find available ports
|
2019-10-01 21:34:41 +02:00
|
|
|
port=$(ynh_find_port --port 6000)
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Store Settings
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2019-06-09 21:05:14 +02:00
|
|
|
ynh_app_setting_set --app $app --key mysqlpwd --value $dbpass
|
|
|
|
ynh_app_setting_set --app $app --key adminusername --value $admin
|
|
|
|
ynh_app_setting_set --app $app --key is_public --value $is_public
|
|
|
|
ynh_app_setting_set --app $app --key secret_key --value $key
|
|
|
|
ynh_app_setting_set --app $app --key web_port --value $port
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Initialize database and store mysql password for upgrade
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring MySQL database..."
|
2018-02-25 21:45:24 +01:00
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
|
|
|
|
# Add users
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2020-03-19 17:51:48 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir=/home/$app --use_shell
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# create needed directories
|
|
|
|
create_dir
|
|
|
|
|
2018-04-30 15:56:19 +02:00
|
|
|
# Configure init script
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
2018-04-30 15:56:19 +02:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx..." --weight=1
|
2018-04-30 15:56:19 +02:00
|
|
|
config_nginx
|
|
|
|
|
2018-05-10 16:31:54 +02:00
|
|
|
# Configure gitea with app.ini file
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring application, step 1/2..."
|
2018-05-10 16:31:54 +02:00
|
|
|
config_gitea
|
|
|
|
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Installing sources files..." --weight=10
|
|
|
|
|
2018-05-09 17:59:23 +02:00
|
|
|
# Install gitea
|
2019-02-15 11:33:29 +01:00
|
|
|
ynh_setup_source $final_path source/$architecture
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Set permissions
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Protecting directory"
|
2018-02-25 21:45:24 +01:00
|
|
|
set_permission
|
|
|
|
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring application, step 2/2..."
|
|
|
|
|
2018-05-15 10:59:56 +02:00
|
|
|
# Start gitea for building mysql tables
|
|
|
|
systemctl start "$app".service
|
|
|
|
|
2020-03-25 16:33:19 +01:00
|
|
|
# Wait untill login_source mysql table is created
|
2018-02-25 21:45:24 +01:00
|
|
|
while ! $(ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
|
|
|
|
do
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
|
|
|
# Add ldap config
|
2019-09-10 21:26:06 +02:00
|
|
|
ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_file ../conf/login_source.sql
|
2018-02-25 21:45:24 +01:00
|
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql
|
|
|
|
|
2019-02-03 15:05:38 +01:00
|
|
|
# SETUP FAIL2BAN
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring fail2ban..."
|
2019-09-07 11:05:06 +02:00
|
|
|
ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
|
2019-02-03 15:05:38 +01:00
|
|
|
|
2018-02-25 21:45:24 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Unprotect root from SSO if public
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Protecting directory"
|
2019-02-14 09:51:19 +01:00
|
|
|
set_access_settings
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2020-03-25 16:33:19 +01:00
|
|
|
# Create permission
|
|
|
|
ynh_script_progression --message="Configuring permissions"
|
|
|
|
ynh_permission_create --permission="admin" --allowed=$admin
|
|
|
|
|
2018-05-09 17:59:23 +02:00
|
|
|
# Add gitea to YunoHost's monitored services
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Register gitea service..."
|
2019-09-07 11:02:15 +02:00
|
|
|
yunohost service add "$app" --log "/var/log/$app/gitea.log"
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Configure logrotate
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2019-10-01 21:34:41 +02:00
|
|
|
ynh_use_logrotate --logfile "/var/log/$app"
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2019-02-15 11:33:29 +01:00
|
|
|
# Save Version
|
2019-06-09 21:05:14 +02:00
|
|
|
ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version)
|
2019-02-15 11:33:29 +01:00
|
|
|
|
2018-02-25 21:45:24 +01:00
|
|
|
# Reload services
|
2019-09-10 22:43:45 +02:00
|
|
|
ynh_script_progression --message="Starting gitea services..." --weight=3
|
2020-03-27 13:55:02 +01:00
|
|
|
ynh_systemd_action -l "Starting new server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10
|
2019-02-16 13:43:04 +01:00
|
|
|
sleep 1
|
2019-02-16 12:59:32 +01:00
|
|
|
|
|
|
|
# Store the checksum with the 'INTERNAL_TOKEN' value.
|
|
|
|
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
|
2019-06-09 21:05:14 +02:00
|
|
|
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
|
2019-10-27 14:54:35 +01:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|