From 5251631f03ab1a56aac6a4d54da89c5c7d1355bb Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Fri, 20 Nov 2020 09:20:50 +0100 Subject: [PATCH] fix --- scripts/_common.sh | 5 +-- scripts/install | 86 +++++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index ae6de87..89ea043 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -2,10 +2,7 @@ # SET ALL CONSTANTS #================================================= -app=$YNH_APP_INSTANCE_NAME -dbname=$app -dbuser=$app -final_path="/opt/$app" + DATADIR="/home/$app" REPO_PATH="$DATADIR/repositories" DATA_PATH="$DATADIR/data" diff --git a/scripts/install b/scripts/install index 89da145..d679a9e 100644 --- a/scripts/install +++ b/scripts/install @@ -25,44 +25,68 @@ ynh_abort_if_errors # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) +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 -# Check domain/path availability -ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain." -ynh_webpath_register $app $domain $path_url +final_path=/opt/$app +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 -# 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 + +#================================================= +# 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 +ynh_app_setting_set --app=$app --key=web_port --value=$port #================================================= # STANDARD MODIFICATIONS #================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Configuring firewall..." --weight=1 -# Initialize database and store mysql password for upgrade -ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" +# Find an available port +port=$(ynh_find_port --port=6000) +ynh_app_setting_set --app=$app --key=port --value=$port + +#================================================= +# CREATE A MYSQL DATABASE +#================================================= +ynh_script_progression --message="Creating a MySQL database..." --weight=1 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + + +dbpass=$(ynh_string_random) #to be changed +#================================================= +# STANDARD MODIFICATIONS +#================================================= # Add users # We can't use the official helper because we need to set the shell for the login @@ -130,14 +154,12 @@ ynh_store_file_checksum --file="$final_path/custom/conf/auth.d/ldap.conf" ynh_add_systemd_config #================================================= -# CONFIGURE NGINX +# NGINX CONFIGURATION #================================================= -# Modify Nginx configuration file and copy it to Nginx conf directory -if [ "$path_url" != "/" ] -then - ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf" -fi - ynh_add_nginx_config +ynh_script_progression --message="Configuring nginx web server..." --weight=1 + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= # GENERIC FINALIZATION @@ -175,7 +197,15 @@ ynh_use_logrotate "/var/log/$app" #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log" +# 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..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT