yunohost-gitea_ynh/scripts/install

152 lines
5.0 KiB
Plaintext
Raw Normal View History

2018-02-25 21:45:24 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2020-11-17 23:33:50 +01:00
# Load common variables and helpers
source ./experimental_helper.sh
source ./_common.sh
2018-02-25 21:45:24 +01:00
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
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
2020-12-08 22:06:19 +01:00
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
2022-04-23 19:40:27 +02:00
if [ -e "$datadir" ]; then
old_data_dir_path="$datadir$(date '+%Y%m%d.%H%M%S')"
2020-12-07 17:04:52 +01:00
ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
2022-04-23 19:40:27 +02:00
mv "$datadir" "$old_data_dir_path"
2020-12-07 17:04:52 +01:00
fi
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..."
2022-04-23 19:40:27 +02:00
db_password=$(ynh_string_random)
2018-02-25 21:45:24 +01:00
key=$(ynh_string_random)
2022-07-19 23:42:47 +02:00
lfs_key=$(ynh_string_random)
2018-02-25 21:45:24 +01:00
# 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..."
2022-04-23 19:40:27 +02:00
ynh_app_setting_set --app $app --key mysqlpwd --value $db_password
2019-06-09 21:05:14 +02:00
ynh_app_setting_set --app $app --key adminusername --value $admin
ynh_app_setting_set --app $app --key secret_key --value $key
2022-07-19 23:42:47 +02:00
ynh_app_setting_set --app $app --key lfs_key --value $lfs_key
2019-06-09 21:05:14 +02:00
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..."
2022-04-23 19:40:27 +02:00
ynh_mysql_create_db "$dbname" "$db_user" "$db_password"
2018-02-25 21:45:24 +01:00
# Add users
2019-09-10 22:43:45 +02:00
ynh_script_progression --message="Configuring system user..."
2022-04-23 19:40:27 +02:00
ynh_system_user_create --username=$app --home_dir=$datadir --use_shell
# Add ssh permission for gitea user
adduser $app ssh.app
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..."
# 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
2022-04-23 19:40:27 +02:00
while ! $(ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null)
2018-02-25 21:45:24 +01:00
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
2022-04-23 19:40:27 +02:00
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ../conf/login_source.sql
2018-02-25 21:45:24 +01:00
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
2022-04-23 19:40:27 +02:00
ynh_script_progression --message="Configuring permissions..."
2022-04-01 22:54:46 +02:00
if [ "$is_public" == '1' ];
then
ynh_permission_update --permission "main" --add "visitors"
fi
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
2022-07-24 17:38:28 +02:00
ynh_script_progression --message="Register Gitea service..."
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
2022-07-24 13:45:53 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/gitea.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
# 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