#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= # 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 app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path="/opt/$app" # Check user parameter ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist." test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url # Generate random password and key dbpass=$(ynh_string_random) key=$(ynh_string_random) #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=mysqlpwd --value=$dbpass ynh_app_setting_set --app=$app --key=adminusername --value=$admin ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=secret_key --value=$key #================================================= # FIND AND OPEN A PORT #================================================= ynh_script_progression --message="Finding an available port..." --weight=1 # Find available ports port=$(ynh_find_port --port=6000) ynh_app_setting_set --app=$app --key=web_port --value=$port #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Creating a MySQL database..." --weight=1 # 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 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Install Gogs ynh_setup_source --dest_dir="$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 chown -R $app:$app "$final_path" chown -R $app:$app "/home/$app" chown -R $app:$app "/var/log/$app" chmod u=rwX,g=rX,o= "$final_path" chmod u=rwX,g=rX,o= "/home/$app" chmod u=rwX,g=rX,o= "/var/log/$app" # Unprotect root from SSO if public set_access_settings # Configure logrotate ynh_use_logrotate "/var/log/$app" #================================================= # 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