1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/forgejo_ynh.git synced 2024-09-03 18:36:26 +02:00
forgejo_ynh/scripts/install

107 lines
3.9 KiB
Text
Raw Normal View History

2023-01-05 14:48:22 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Load common variables and helpers
source ./_common.sh
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
#=================================================
2023-05-27 17:52:29 +02:00
# Create install and data subdirs
#=================================================
2023-05-27 17:52:29 +02:00
ynh_setup_source --dest_dir="$install_dir"
xz -d "$install_dir/forgejo.xz"
chmod +x "$install_dir/forgejo"
2023-01-05 14:48:22 +01:00
2023-03-10 17:13:54 +01:00
mkdir -p "$install_dir/custom/conf"
2023-05-27 17:52:29 +02:00
chmod -R o-rwx "$install_dir/custom"
chown -R $app:$app "$install_dir/custom"
#=================================================
# KEYS GENERATION
#=================================================
2023-03-10 17:22:52 +01:00
2023-03-10 17:13:54 +01:00
secret_key=$($install_dir/forgejo generate secret SECRET_KEY)
lfs_jwt_secret=$($install_dir/forgejo generate secret JWT_SECRET)
internal_token=$($install_dir/forgejo generate secret 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
ynh_app_setting_set --app=$app --key=internal_token --value=$internal_token
2023-01-05 14:48:22 +01:00
#=================================================
# ADD A CONFIGURATION
2023-01-05 14:48:22 +01:00
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
2023-01-05 14:48:22 +01:00
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
2023-03-10 17:13:54 +01:00
ynh_add_config --template="app.ini" --destination="$install_dir/custom/conf/app.ini"
2023-01-05 14:48:22 +01:00
2023-03-10 17:13:54 +01:00
chmod 640 "$install_dir/custom/conf/app.ini"
chown $app:$app "$install_dir/custom/conf/app.ini"
2023-01-05 14:48:22 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2023-05-27 17:52:29 +02:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2023-01-05 14:48:22 +01:00
ynh_add_systemd_config
2023-05-27 17:52:29 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
ynh_add_nginx_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
2023-01-05 14:48:22 +01:00
2023-05-27 17:52:29 +02:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile "/var/log/$app" --nonappend
2023-01-11 19:46:20 +01:00
2023-05-27 17:52:29 +02:00
chown -R $app:$app "/var/log/$app"
2023-01-11 19:46:20 +01:00
chmod u=rwX,g=rX,o= "/var/log/$app"
2023-01-05 14:48:22 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2023-05-27 17:52:29 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
2023-01-05 14:48:22 +01:00
2023-05-27 17:52:29 +02:00
yunohost service add $app --description="Forgejo" --log="/var/log/$app/forgejo.log"
2023-01-05 14:48:22 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
2023-01-05 14:48:22 +01:00
2023-05-27 17:52:29 +02:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/forgejo.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
2023-01-05 14:48:22 +01:00
#=================================================
2023-01-05 14:48:22 +01:00
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
2023-01-06 12:17:27 +01:00
ynh_add_fail2ban_config --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
2023-01-05 14:48:22 +01:00
#=================================================
# LDAP CONFIGURATION
#=================================================
ynh_script_progression --message="Adding LDAP configuration..." --weight=1
set_forgejo_login_source
2023-01-05 14:48:22 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2023-01-05 14:48:22 +01:00
ynh_script_progression --message="Installation of $app completed" --last