From a9632f93192fa82ed287f9c8646f0680d1536a20 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Tue, 11 Jan 2022 12:17:20 +0100 Subject: [PATCH] Update install --- scripts/install | 70 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/scripts/install b/scripts/install index 00c3c70..13f6cce 100644 --- a/scripts/install +++ b/scripts/install @@ -3,15 +3,26 @@ #================================================= # 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 -# Load common variables and helpers -source ./_common.sh +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN @@ -19,33 +30,49 @@ 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 +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." +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" +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 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 +port=$(ynh_find_port --port=6000) +ynh_app_setting_set --app=$app --key=web_port --value=$port #================================================= -# STANDARD MODIFICATIONS +# 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" @@ -59,8 +86,13 @@ test getent passwd "$app" &>/dev/null || \ # 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 $final_path $architecture +ynh_setup_source --dest_dir="$final_path" $architecture # Configure gogs with app.ini file config_gogs