#!/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 ./_common.sh # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC # Check domain/path availability ynh_webpath_register $app $domain $path_url # Check user parameter ynh_user_exists "$admin" \ || ynh_die "The chosen admin user does not exist." # Check Final Path availability test ! -e "$final_path" || ynh_die "This path already contains a folder" # Generate random password and key dbpass=$(ynh_string_random) key=$(ynh_string_random) # Find available ports port=$(ynh_find_port 6000) # Store Settings ynh_app_setting_set $app mysqlpwd $dbpass ynh_app_setting_set $app adminusername $admin ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app secret_key $key ynh_app_setting_set $app web_port $port #================================================= # STANDARD MODIFICATIONS #================================================= # Initialize database and store mysql password for upgrade ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" # Add users # We can't use the official helper because we need to set the shell for the login test getent passwd "$app" &>/dev/null || \ useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \ ynh_die "Unable to create $app system account" # create needed directories create_dir # Install Gogs ynh_setup_source $final_path $architecture # Configure gogs with app.ini file config_gogs #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Configure init script ynh_add_systemd_config #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # GENERIC FINALIZATION #================================================= # Set permissions set_permission # Unprotect root from SSO if public set_access_settings # Configure logrotate ynh_use_logrotate "/var/log/$app" # Reload services #ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last