From 30bc787b0c9e70981448901fd1a1fe1dec1d7d40 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 17 Jul 2021 16:48:02 +0200 Subject: [PATCH] Fix --- check_process | 4 +- conf/conf.php | 8 --- conf/cron | 2 + conf/htconfig.php | 112 ----------------------------------- conf/local-sample.config.php | 44 ++++++++++++++ conf/local.ini.php | 41 ------------- conf/nginx.conf | 37 +----------- conf/poller-cron | 2 - manifest.json | 12 +--- scripts/backup | 2 +- scripts/install | 61 +++++++++---------- scripts/restore | 35 ++++------- scripts/upgrade | 61 ++++++------------- 13 files changed, 111 insertions(+), 310 deletions(-) delete mode 100644 conf/conf.php create mode 100644 conf/cron delete mode 100644 conf/htconfig.php create mode 100644 conf/local-sample.config.php delete mode 100644 conf/local.ini.php delete mode 100644 conf/poller-cron diff --git a/check_process b/check_process index d073319..4e92030 100644 --- a/check_process +++ b/check_process @@ -1,7 +1,7 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - admin="john" (USER) + domain="domain.tld" + admin="john" ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/conf/conf.php b/conf/conf.php deleted file mode 100644 index d6d8569..0000000 --- a/conf/conf.php +++ /dev/null @@ -1,8 +0,0 @@ - -$a->config['system']['addon'] = 'ldapauth'; - -$a->config['ldapauth']['ldap_server'] = 'localhost'; -$a->config['ldapauth']['ldap_searchdn'] = 'ou=users,dc=yunohost,dc=org'; -$a->config['ldapauth']['ldap_userattr'] = 'uid'; -$a->config['ldapauth']['ldap_autocreateaccount'] = 'true'; -$a->config['ldapauth']['ldap_autocreateaccount_emailattribute'] = 'mail'; diff --git a/conf/cron b/conf/cron new file mode 100644 index 0000000..f401a8f --- /dev/null +++ b/conf/cron @@ -0,0 +1,2 @@ +# Run poller periodically to update Friendica +*/10 * * * * __APP__ cd __FINALPATH__; /usr/bin/php__PHPVERSION__ bin/worker.php diff --git a/conf/htconfig.php b/conf/htconfig.php deleted file mode 100644 index 30f157e..0000000 --- a/conf/htconfig.php +++ /dev/null @@ -1,112 +0,0 @@ -config['system']['db_charset'] = "utf8mb4"; - -// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". -// It can be changed later and only applies to timestamps for anonymous viewers. - -$default_timezone = 'America/Los_Angeles'; - -// Default system language - -$a->config['system']['language'] = 'en'; - -// What is your site name? - -$a->config['sitename'] = "YunoHost Friendica Social Network"; - -// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED. -// Be certain to create your own personal account before setting -// REGISTER_CLOSED. 'register_text' (if set) will be displayed prominently on -// the registration page. REGISTER_APPROVE requires you set 'admin_email' -// to the email address of an already registered person who can authorise -// and/or approve/deny the request. - -// In order to perform system administration via the admin panel, admin_email -// must precisely match the email address of the person logged in. - -$a->config['register_policy'] = REGISTER_CLOSEDS; -$a->config['register_text'] = ''; -$a->config['admin_email'] = '__ADMIN_EMAIL__'; - -// Maximum size of an imported message, 0 is unlimited - -$a->config['max_import_size'] = 200000; - -// maximum size of uploaded photos - -$a->config['system']['maximagesize'] = 800000; - -// Location of PHP command line processor - -$a->config['php_path'] = 'php'; - -// Server-to-server private message encryption (RINO) is allowed by default. -// set to 0 to disable, 1 to enable - -$a->config['system']['rino_encrypt'] = 1; - -// allowed themes (change this from admin panel after installation) - -$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly'; - -// default system theme - -$a->config['system']['theme'] = 'vier'; - - -// By default allow pseudonyms - -$a->config['system']['no_regfullname'] = true; - -//Deny public access to the local directory -//$a->config['system']['block_local_dir'] = false; - -// Location of the global directory -$a->config['system']['directory'] = 'https://dir.friendica.social'; - -// Allowed protocols in link URLs; HTTP protocols always are accepted -$a->config['system']['allowed_link_protocols'] = ['ftp', 'ftps', 'mailto', 'cid', 'gopher']; - -// Authentication cookie lifetime, in days -$a->config['system']['auth_cookie_lifetime'] = 7; diff --git a/conf/local-sample.config.php b/conf/local-sample.config.php new file mode 100644 index 0000000..ad05da0 --- /dev/null +++ b/conf/local-sample.config.php @@ -0,0 +1,44 @@ + [ + 'hostname' => 'localhost', + 'username' => '__DB_NAME__', + 'password' => '__DB_PWD__', + 'database' => '__DB_NAME__', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'admin_email' => '__EMAIL__', + 'sitename' => 'Friendica Social Network', + 'register_policy' => \Friendica\Module\Register::OPEN, + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; diff --git a/conf/local.ini.php b/conf/local.ini.php deleted file mode 100644 index 359f3ee..0000000 --- a/conf/local.ini.php +++ /dev/null @@ -1,41 +0,0 @@ -= 4.1.0" + "yunohost": ">= 4.2.0" }, "previous_maintainers": { "name": "aymhce", @@ -31,20 +31,12 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for Friendica. Friendica must be installed on the ROOT domain, so be careful!", - "fr": "Choisissez un domaine pour Friendica.Friendica doit etre installe a la racine, soyez prudent" - }, "example": "domain.org" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose the Friendica administrator (must be an existing YunoHost user)", - "fr": "Choisissez l'administrateur pour Friendica (l'utilisateur YunoHost doit exister)" - }, - "example": "homer" + "example": "johndoe" } ] diff --git a/scripts/backup b/scripts/backup index b50cd45..c31c808 100644 --- a/scripts/backup +++ b/scripts/backup @@ -71,4 +71,4 @@ ynh_backup --src_path="/etc/cron.d/$app" # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 463903b..e3d7994 100644 --- a/scripts/install +++ b/scripts/install @@ -28,7 +28,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url='/' admin=$YNH_APP_ARG_ADMIN -admin_mail=$(yunohost user info $admin | grep "mail:" | cut -d' ' -f2) +email=$(ynh_user_get_info --username=$admin --key=mail) is_public=1 database="1" @@ -53,10 +53,17 @@ ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=is_public --value=$is_public -ynh_app_setting_set --app=$app --key=email --value=$admin_mail +ynh_app_setting_set --app=$app --key=email --value=$email ynh_app_setting_set --app=$app --key=database --value=$database +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -82,6 +89,10 @@ cp -f "$final_path/.htaccess-dist" "$final_path/.htaccess" # 2 - Clone addons repo git clone https://github.com/friendica/friendica-addons.git -b stable "$final_path/addon" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -90,29 +101,15 @@ ynh_script_progression --message="Configuring NGINX web server..." # Create a dedicated nginx config ynh_add_nginx_config -# configure friendica -config="$final_path/config/local.config.php" -cp -f "$final_path/config/local-sample.config.php" $config -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$config" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$config" -#ynh_replace_string --match_string="OPEN" --replace_string="CLOSED" --target_file="$config" + + +ynh_add_config --template="../conf/local-sample.config.php" --destination="$final_path/config/local.config.php" # init db ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "$final_path/database.sql" -# ldap addon config -cp "../conf/addon.config.php" "$final_path/config/." - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app +# LDAP addon config +ynh_add_config --template="../conf/addon.config.php" --destination="$final_path/config/addon.config.php" #================================================= # PHP-FPM CONFIGURATION @@ -127,11 +124,14 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) mkdir -p "${final_path}/view/smarty3" chmod -R 775 $final_path/view/smarty3 -# Set up poller -ynh_replace_string --match_string="__YNH_WWW_PATH__" --replace_string="$final_path" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" -cp ../conf/poller-cron /etc/cron.d/$app +#================================================= +# SETUP A CRON +#================================================= +ynh_script_progression --message="Setuping a cron..." + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -145,14 +145,9 @@ pushd "$final_path" php$phpversion bin/composer.phar install 2>/dev/null bin/console config system addon ldapauth popd + ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" <<< "INSERT INTO addon (id, name, version, installed, hidden, timestamp, plugin_admin) VALUES (NULL, 'ldapauth', '', '1', '0', UNIX_TIMESTAMP(), '0');" -#================================================= -# Folder rights -#================================================= - -chown -R $app: $final_path - #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/restore b/scripts/restore index 69d4a40..4ffbc75 100644 --- a/scripts/restore +++ b/scripts/restore @@ -60,6 +60,14 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $db_name $db_name $db_pwd ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_print_info "Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create $app --home_dir="$final_path" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -67,13 +75,10 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_print_info "Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create $app +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod -R 775 $final_path/view/smarty3 #================================================= # RESTORE THE PHP-FPM CONFIGURATION @@ -85,28 +90,12 @@ ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" # Recreate a dedicated php-fpm config ynh_add_fpm_config --package="$extra_php_dependencies" -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -# set permission -chmod -R 775 $final_path/view/smarty3 - #================================================= # RESTORE THE CRON FILE #================================================= ynh_restore_file "/etc/cron.d/$app" -#================================================= -# Folder rights -#================================================= - -chown -R $app: $final_path - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 83e7989..ace4c7b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -admin_mail=$(ynh_app_setting_get --app=$app --key=email) +email=$(ynh_app_setting_get --app=$app --key=email) admin=$(ynh_app_setting_get --app=$app --key=admin) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) @@ -76,9 +76,9 @@ if [ -f $final_path/.htconfig.php ]; then fi # If admin_mail setting doesn't exist, create it -if [ -z $admin_mail ]; then - admin_mail=$(ynh_user_get_info --username=$admin --key=mail) - ynh_app_setting_set --app=$app --key=email --value=$admin_mail +if [ -z $email ]; then + email=$(ynh_user_get_info --username=$admin --key=mail) + ynh_app_setting_set --app=$app --key=email --value=$email fi # Cleaning legacy permissions @@ -88,6 +88,14 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +#================================================= +# 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 --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -132,24 +140,15 @@ else # Restore the smarty3 folder cp -a "$tmpdir/view/smarty3" "${final_path}" ynh_secure_remove "$tmpdir" - fi fi # Copy config file for correct place -config="$final_path/config/local.config.php" -cp -a "/var/www/$app/config/local-sample.config.php" $config +ynh_add_config --template="../conf/local-sample.config.php" --destination="$final_path/config/local.config.php" -# Replace strings in config file -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$config" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file= "$config" -ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$config" -#ynh_replace_string --match_string="OPEN" --replace_string="CLOSED" --target_file="$config" - -# ldap addon config -cp -f "../conf/addon.config.php" "$final_path/config/." +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" # 3 - some extra folders chmod -R 775 $final_path/view/smarty3 @@ -162,14 +161,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config -#================================================= -# 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 #================================================= @@ -182,17 +173,9 @@ ynh_add_fpm_config --package="$extra_php_dependencies" # STORE THE CONFIG FILE CHECKSUM #================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/config/local.config.php" -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/config/local.config.php" - -# Set up cron job -ynh_replace_string --match_string="__YNH_WWW_PATH__" --replace_string="$final_path" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" -cp "../conf/poller-cron" "/etc/cron.d/$app" +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" # Run composer pushd "$final_path" @@ -200,12 +183,6 @@ pushd "$final_path" bin/console config system addon ldapauth popd -#================================================= -# Folder rights -#================================================= - -chown -R $app: $final_path - #================================================= # RELOAD NGINX #=================================================