2018-02-25 21:45:24 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
2023-09-09 11:17:52 +02:00
|
|
|
#=================================================
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
#=================================================
|
|
|
|
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_script_progression --message='Creating base directory...'
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
if [ -n "$(ls -A $data_dir)" ]; then
|
|
|
|
old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')"
|
|
|
|
ynh_print_warn "Data directory was not empty. Data was moved to $old_data_dir_path"
|
|
|
|
mkdir -p $old_data_dir_path
|
|
|
|
mv -t "$old_data_dir_path" "$data_dir"/*
|
|
|
|
fi
|
|
|
|
|
|
|
|
# base directories
|
|
|
|
mkdir -p "$install_dir/data"
|
|
|
|
mkdir -p "$install_dir/custom/conf"
|
|
|
|
mkdir -p "/var/log/$app"
|
2020-12-07 17:04:52 +01:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
mkdir -p "$data_dir/.ssh"
|
|
|
|
mkdir -p "$data_dir/repositories"
|
|
|
|
mkdir -p "$data_dir/data/avatars"
|
|
|
|
mkdir -p "$data_dir/data/attachments"
|
|
|
|
|
|
|
|
ynh_script_progression --message='Installing sources files and data directories...' --weight=10
|
|
|
|
|
|
|
|
# Setup source
|
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
|
|
_set_permissions
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
ynh_script_progression --message="Configuring application, step 1/2..."
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
internal_token=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret INTERNAL_TOKEN)
|
|
|
|
secret_key=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret SECRET_KEY)
|
|
|
|
lfs_jwt_secret=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret JWT_SECRET)
|
2023-12-13 10:38:10 +01:00
|
|
|
jwt_secret=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret JWT_SECRET)
|
2023-11-29 10:58:11 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set --app="$app" --key=internal_token --value="$internal_token"
|
|
|
|
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
|
|
|
|
ynh_app_setting_set --app="$app" --key=lfs_jwt_secret --value="$lfs_jwt_secret"
|
2023-12-13 10:38:10 +01:00
|
|
|
ynh_app_setting_set --app "$app" --key jwt_secret --value="$jwt_secret"
|
2023-11-29 10:58:11 +01:00
|
|
|
|
|
|
|
ynh_add_config --template='app.ini' --destination="$install_dir/custom/conf/app.ini"
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-09-09 11:17:52 +02:00
|
|
|
# SYSTEM CONFIGURATION
|
2018-02-25 21:45:24 +01:00
|
|
|
#=================================================
|
2023-09-09 11:17:52 +02:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Create a dedicated NGINX config using the conf/nginx.conf template
|
|
|
|
ynh_add_nginx_config
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Create a dedicated systemd config
|
2018-04-30 15:56:19 +02:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Add gitea to YunoHost's monitored services
|
|
|
|
yunohost service add "$app" --log="/var/log/$app/gitea.log"
|
2018-05-10 16:31:54 +02:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Configure logrotate
|
|
|
|
ynh_use_logrotate --logfile "/var/log/$app"
|
2019-09-10 22:43:45 +02:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Create a dedicated Fail2Ban config
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_add_fail2ban_config --logpath="/var/log/$app/gitea.log" --failregex='.*Failed authentication attempt for .* from <HOST>' --max_retry=5
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
#=================================================
|
|
|
|
# APP INITIAL CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_script_progression --message='Configuring application, step 2/2...'
|
|
|
|
_set_permissions
|
2019-09-10 22:43:45 +02:00
|
|
|
|
2018-05-15 10:59:56 +02:00
|
|
|
# Start gitea for building mysql tables
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=start --log_path="/var/log/$app/gitea.log" --line_match="$systemd_match_start_line"
|
2018-02-25 21:45:24 +01:00
|
|
|
|
|
|
|
# Add ldap config
|
2024-02-05 19:12:10 +01:00
|
|
|
ynh_replace_string --match_string=__APP__ --replace_string="$app" --target_file=./login_source.sql
|
2024-02-05 22:45:24 +01:00
|
|
|
ynh_replace_string --match_string=__GROUP_TEAM_MAP__ --replace_string='""' --target_file=./login_source.sql
|
2024-02-05 19:12:10 +01:00
|
|
|
ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./login_source.sql
|
2018-02-25 21:45:24 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
# Stop the service to restart it just afterwards
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action='stop' --log_path="/var/log/$app/gitea.log"
|
2019-02-03 15:05:38 +01:00
|
|
|
|
2018-02-25 21:45:24 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2023-09-09 11:17:52 +02:00
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_script_progression --message='Starting gitea services...' --weight=3
|
2022-07-24 13:45:53 +02:00
|
|
|
|
2023-11-29 10:58:11 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action=start --log_path="/var/log/$app/gitea.log" --line_match="$systemd_match_start_line"
|
2019-10-27 14:54:35 +01:00
|
|
|
|
2023-09-09 11:17:52 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-10-27 14:54:35 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|