From 339e50d9d2808ee2a28738106e29e0d8342855eb Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Fri, 4 Jun 2021 09:15:08 +0200 Subject: [PATCH] Cleaning up --- check_process | 12 ++++------- conf/.env | 32 ++++++++++++++--------------- manifest.json | 20 ++---------------- scripts/install | 54 ++++++++++++------------------------------------- scripts/upgrade | 50 ++++++++++++--------------------------------- 5 files changed, 48 insertions(+), 120 deletions(-) diff --git a/check_process b/check_process index 189ba42..fec9a17 100644 --- a/check_process +++ b/check_process @@ -1,12 +1,9 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - admin="john" (USER) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" + path="/path" + admin="john" + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=1 @@ -18,7 +15,6 @@ upgrade=1 from_commit=5ee628f58c4f9ea6b6fd48d843453c47ed3d34e4 backup_restore=1 multi_instance=1 - port_already_use=0 change_url=0 ;;; Options Email=anmol@datamol.org diff --git a/conf/.env b/conf/.env index f7e5d5b..23d51b3 100644 --- a/conf/.env +++ b/conf/.env @@ -12,7 +12,7 @@ SITE_OWNER=mail@example.com # The encryption key for your sessions. Keep this very secure. # Change it to a string of exactly 32 chars or use something like `php artisan key:generate` to generate it. # If you use Docker or similar, you can set this variable from a file by using APP_KEY_FILE -APP_KEY=SomeRandomStringOf32CharsExactly +APP_KEY=__RANDOM_KEY__ # Firefly III will launch using this language (for new users and unauthenticated visitors) # For a list of available languages: https://github.com/firefly-iii/firefly-iii/tree/main/resources/lang @@ -59,11 +59,11 @@ APP_LOG_LEVEL=notice # Use "mysql" for MySQL and MariaDB. # Use "sqlite" for SQLite. DB_CONNECTION=mysql -DB_HOST=fireflyiiidb +DB_HOST=127.0.0.1 DB_PORT=3306 -DB_DATABASE=firefly -DB_USERNAME=firefly -DB_PASSWORD=secret_firefly_password +DB_DATABASE=__DB_NAME__ +DB_USERNAME=__DB_NAME__ +DB_PASSWORD=__DB_PWD__ # MySQL supports SSL. You can configure it here. # If you use Docker or similar, you can set these variables from a file by appending them with _FILE @@ -117,10 +117,10 @@ COOKIE_SECURE=false # If you want Firefly III to mail you, update these settings # For instructions, see: https://docs.firefly-iii.org/advanced-installation/email # If you use Docker or similar, you can set these variables from a file by appending them with _FILE -MAIL_MAILER=log -MAIL_HOST=null -MAIL_PORT=2525 -MAIL_FROM=changeme@example.com +MAIL_MAILER=smtp +MAIL_HOST=127.0.0.1 +MAIL_PORT=25 +MAIL_FROM=__EMAIL__ MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null @@ -212,10 +212,10 @@ ADLDAP_AUTO_CONNECT=true # LDAP connection settings # You can set the following variables from a file by appending them with _FILE: # ADLDAP_CONTROLLERS, ADLDAP_PORT, ADLDAP_BASEDN -ADLDAP_CONTROLLERS= +ADLDAP_CONTROLLERS=127.0.0.1 ADLDAP_PORT=389 ADLDAP_TIMEOUT=5 -ADLDAP_BASEDN="" +ADLDAP_BASEDN="dc=yunohost,dc=org" ADLDAP_FOLLOW_REFFERALS=false # SSL/TLS settings @@ -233,15 +233,15 @@ ADLDAP_ADMIN_USERNAME= ADLDAP_ADMIN_PASSWORD= # You can set the following variables from a file by appending them with _FILE: -ADLDAP_ACCOUNT_PREFIX= -ADLDAP_ACCOUNT_SUFFIX= +ADLDAP_ACCOUNT_PREFIX="uid=" +ADLDAP_ACCOUNT_SUFFIX=",dc=yunohost,dc=org" # LDAP authentication settings. ADLDAP_PASSWORD_SYNC=false ADLDAP_LOGIN_FALLBACK=false -ADLDAP_DISCOVER_FIELD=distinguishedname -ADLDAP_AUTH_FIELD=distinguishedname +ADLDAP_DISCOVER_FIELD="uid" +ADLDAP_AUTH_FIELD="uid" # field to sync as local username. # You can set the following variable from a file by appending it with _FILE: @@ -326,4 +326,4 @@ FIREFLY_III_LAYOUT=v1 # # If you're stuck I understand you get desperate but look SOMEWHERE ELSE. # -APP_URL=http://localhost \ No newline at end of file +APP_URL=http://__DOMAIN____PATH__ \ No newline at end of file diff --git a/manifest.json b/manifest.json index 71f638b..abcf9b6 100644 --- a/manifest.json +++ b/manifest.json @@ -15,47 +15,31 @@ "url": "https://datamol.org" }, "requirements": { - "yunohost": ">= 4.1.0" + "yunohost": ">= 4.2.0" }, "multi_instance": true, - "services": ["nginx", "php7.0-fpm", "mysql"], + "services": ["nginx", "php7.4-fpm", "mysql"], "arguments": { "install": [ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for Firefly III", - "fr": "Choisissez un nom de domaine pour Firefly III" - }, "example": "example.com" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Firefly III", - "fr": "Choisissez un chemin pour Firefly III" - }, "example": "/example", "default": "/firefly" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose an admin user (should be a YunoHost registered user)", - "fr": "Choisissez l’administrateur (should be a YunoHost registered user)" - }, "example": "johndoe" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, "default": true } ] diff --git a/scripts/install b/scripts/install index 697fcf5..1416494 100755 --- a/scripts/install +++ b/scripts/install @@ -70,6 +70,14 @@ 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 +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$appp --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -87,14 +95,6 @@ ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -118,36 +118,12 @@ ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$f #================================================= ynh_script_progression --message="Modifying a config file..." -config="$final_path/.env" -cp -f ../conf/.env "$config" +random_key="$random_key" -ynh_replace_string --match_string="SomeRandomStringOf32CharsExactly" --replace_string="$random_key" --target_file="$config" -ynh_replace_string --match_string="fireflyiiidb" --replace_string="127.0.0.1" --target_file="$config" -ynh_replace_string --match_string="DB_DATABASE=firefly" --replace_string="DB_DATABASE=$db_name" --target_file="$config" -ynh_replace_string --match_string="DB_USERNAME=firefly" --replace_string="DB_USERNAME=$db_name" --target_file="$config" -ynh_replace_string --match_string="secret_firefly_password" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="MAIL_MAILER=log" --replace_string="MAIL_MAILER=smtp" --target_file="$config" -ynh_replace_string --match_string="MAIL_HOST=null" --replace_string="MAIL_HOST=127.0.0.1" --target_file="$config" -ynh_replace_string --match_string="MAIL_PORT=2525" --replace_string="MAIL_PORT=25" --target_file="$config" -ynh_replace_string --match_string="mail@example.com" --replace_string="$email" --target_file="$config" -ynh_replace_string --match_string="changeme@example.com" --replace_string="$app@$domain" --target_file="$config" -# These helpers are for reference purpose.Uncomment them once app gets support for LDAP. Put them directly in .env +ynh_add_config --template="../conf/.env" --destination="$final_path/.env" -# ynh_replace_string --match_string="ADLDAP_CONTROLLERS=" --replace_string="ADLDAP_CONTROLLERS=127.0.0.1" --target_file="$config" -# ynh_replace_string --match_string='ADLDAP_BASEDN=""' --replace_string='ADLDAP_BASEDN="dc=yunohost,dc=org"' --target_file="$config" -# ynh_replace_string --match_string="ADLDAP_ACCOUNT_PREFIX=" --replace_string='ADLDAP_ACCOUNT_PREFIX="uid="' --target_file="$config" -# ynh_replace_string --match_string="ADLDAP_ACCOUNT_SUFFIX=" --replace_string='ADLDAP_ACCOUNT_SUFFIX=",dc=yunohost,dc=org"' --target_file="$config" -# ynh_replace_string --match_string="distinguishedname" --replace_string="uid" --target_file="$config" -# ynh_replace_string --match_string="userprincipalname" --replace_string="uid" --target_file="$config" -ynh_replace_string --match_string="localhost" --replace_string="$domain$path_url" --target_file="$config" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config" +chmod 400 "$final_path/.env" +chown $app:$app "$final_path/.env" #================================================= # DEPLOY @@ -176,11 +152,7 @@ chmod -R 775 $final_path/storage #================================================= ynh_script_progression --message="Setuping a cron..." -cp ../conf/cron /etc/cron.d/$app - -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # SETUP LOGROTATE diff --git a/scripts/upgrade b/scripts/upgrade index 8495f66..11269e1 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -82,6 +82,14 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$appp --home_dir="$final_path" + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -157,14 +165,6 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies "$pkg_dependencies" -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -190,32 +190,12 @@ ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$f #================================================= ynh_script_progression --message="Modifying a config file..." -config="$final_path/.env" -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/.env "$config" +random_key="$random_key" -ynh_replace_string --match_string="SomeRandomStringOf32CharsExactly" --replace_string="$random_key" --target_file="$config" -ynh_replace_string --match_string="fireflyiiidb" --replace_string="127.0.0.1" --target_file="$config" -ynh_replace_string --match_string="DB_DATABASE=firefly" --replace_string="DB_DATABASE=$db_name" --target_file="$config" -ynh_replace_string --match_string="DB_USERNAME=firefly" --replace_string="DB_USERNAME=$db_name" --target_file="$config" -ynh_replace_string --match_string="secret_firefly_password" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="MAIL_MAILER=log" --replace_string="MAIL_MAILER=smtp" --target_file="$config" -ynh_replace_string --match_string="MAIL_HOST=null" --replace_string="MAIL_HOST=127.0.0.1" --target_file="$config" -ynh_replace_string --match_string="MAIL_PORT=2525" --replace_string="MAIL_PORT=25" --target_file="$config" -ynh_replace_string --match_string="mail@example.com" --replace_string="$email" --target_file="$config" -ynh_replace_string --match_string="changeme@example.com" --replace_string="$app@$domain" --target_file="$config" -# These helpers are for reference.Remove them once app gets support for LDAP. Put them directly in .env +ynh_add_config --template="../conf/.env" --destination="$final_path/.env" -# ynh_replace_string --match_string="ADLDAP_CONTROLLERS=" --replace_string="ADLDAP_CONTROLLERS=127.0.0.1" --target_file="$config" -# ynh_replace_string --match_string='ADLDAP_BASEDN=""' --replace_string='ADLDAP_BASEDN="dc=yunohost,dc=org"' --target_file="$config" -# ynh_replace_string --match_string="ADLDAP_ACCOUNT_PREFIX=" --replace_string='ADLDAP_ACCOUNT_PREFIX="uid="' --target_file="$config" -# ynh_replace_string --match_string="ADLDAP_ACCOUNT_SUFFIX=" --replace_string='ADLDAP_ACCOUNT_SUFFIX=",dc=yunohost,dc=org"' --target_file="$config" -# ynh_replace_string --match_string="distinguishedname" --replace_string="uid" --target_file="$config" -# ynh_replace_string --match_string="userprincipalname" --replace_string="uid" --target_file="$config" -ynh_replace_string --match_string="localhost" --replace_string="$domain$path_url" --target_file="$config" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config" +chmod 400 "$final_path/.env" +chown $app:$app "$final_path/.env" #================================================= # DEPLOYMENT @@ -255,11 +235,7 @@ chmod -R 775 $final_path/storage #================================================= ynh_script_progression --message="Setuping a cron..." -cp ../conf/cron /etc/cron.d/$app - -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/cron.d/$app" -ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$phpversion" --target_file="/etc/cron.d/$app" +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # RELOAD NGINX