mirror of
https://github.com/YunoHost-Apps/forgejo_ynh.git
synced 2024-09-03 18:36:26 +02:00
127 lines
4.9 KiB
Bash
127 lines
4.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# Load common variables and helpers
|
|
source ./_common.sh
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
# Create a system user
|
|
ynh_system_user_create --username=$app --home_dir=$data_dir --groups ssh.app --use_shell
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Installing sources files..." --weight=10
|
|
|
|
ynh_setup_source --dest_dir=$install_dir --source_id=$YNH_ARCH
|
|
|
|
mkdir -p "$install_dir/custom/conf"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:$app "$install_dir"
|
|
chmod +x "$install_dir/forgejo"
|
|
|
|
#=================================================
|
|
# KEYS GENERATION
|
|
#=================================================
|
|
|
|
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
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# CREATE DATA DIRECTORY
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a data directory..." --weight=1
|
|
|
|
if [ -e "$data_dir" ]; then
|
|
old_data_dir_path="$data_dir$(date '+%Y%m%d.%H%M%S')"
|
|
ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
|
|
mv "$data_dir" "$old_data_dir_path"
|
|
fi
|
|
|
|
mkdir -p "$data_dir/.ssh"
|
|
chmod u=rwx,g=,o= "$data_dir/.ssh"
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|
|
|
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
|
|
ynh_add_config --template="app.ini" --destination="$install_dir/custom/conf/app.ini"
|
|
|
|
chmod 640 "$install_dir/custom/conf/app.ini"
|
|
chown $app:$app "$install_dir/custom/conf/app.ini"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
# Configure logrotate
|
|
ynh_use_logrotate --logfile "/var/log/$app/forgejo.log"
|
|
|
|
chown $app:$app /var/log/$app
|
|
chmod u=rwX,g=rX,o= "/var/log/$app"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
yunohost service add "$app" --description="Forgejo" --log="/var/log/$app/forgejo.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
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:"
|
|
|
|
#=================================================
|
|
# SETUP FAIL2BAN
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
|
|
|
|
ynh_add_fail2ban_config --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
|
|
|
|
#=================================================
|
|
# LDAP CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding LDAP configuration..." --weight=1
|
|
|
|
pushd "$install_dir"
|
|
ynh_exec_as $app ./forgejo admin auth add-ldap --security-protocol "Unencrypted" --name "YunoHost LDAP" --host "localhost" --port "389" --skip-tls-verify --user-search-base "ou=users,dc=yunohost,dc=org" --user-filter "(&(uid=%s)(objectClass=posixAccount)(permission=cn=$app.main,ou=permission,dc=yunohost,dc=org))" --firstname-attribute "givenName" --surname-attribute "sn" --email-attribute "mail" --admin-filter "(permission=cn=$app.admin,ou=permission,dc=yunohost,dc=org)"
|
|
popd
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|