diff --git a/README.md b/README.md index 5c95c50..b5c73a1 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ [Friendica](http://friendi.ca/) integration for YunoHost
-**Version:2018.09**

+**Version:2019.01**

Current snapshot in *sources*: -* https://github.com/friendica/friendica: 2018.09 (commit c48fcd4a8f329946cdf09d214596ecf29e859cff) -* https://github.com/friendica/friendica-addons: 2018.09 (commit 9c275a4185956fb2ca790263fb72f6da6311742f) +* https://github.com/friendica/friendica: 2019.01 +* https://github.com/friendica/friendica-addons: 2018.01 ## Important Notes @@ -22,11 +22,8 @@ Before installing, read the [Friendica installation instructions](https://github Note:You can use accounts from YunoHost's LDAP. There are not yet active SSO.

# To-do -- [X] Installation and remove script. -- [X] Ldap integration. -- [X] Upgrade script -- [X] Backup and restore script. -- [X] Multi-instance +- [ ] Fail2Ban support + ## Installation diff --git a/check_process b/check_process index f6c3cc5..1cbbf2b 100644 --- a/check_process +++ b/check_process @@ -1,5 +1,4 @@ -;; Default test - auto_remove=1 +;; Test complet ; Manifest domain="domain.tld" (DOMAIN) admin="john" (USER) @@ -11,18 +10,19 @@ setup_private=0 setup_public=1 upgrade=1 + upgrade=1 from_commit=1c018b9ed379e25d5bcab4bd27e9833feee9da68 backup_restore=1 multi_instance=1 incorrect_path=1 port_already_use=0 change_url=0 + ;;; Levels Level 1=auto Level 2=auto Level 3=auto # There is LDAP support for the app Level 4=1 - # Level 5: Level 5=auto Level 6=auto Level 7=auto @@ -31,4 +31,4 @@ Level 10=0 ;;; Options Email=anmol@datamol.org - Notification=none + Notification=change diff --git a/conf/addon.config.php b/conf/addon.config.php new file mode 100644 index 0000000..c2800ff --- /dev/null +++ b/conf/addon.config.php @@ -0,0 +1,11 @@ + [ + 'ldap_server' => 'localhost', + 'ldap_searchdn' => 'ou=users,dc=yunohost,dc=org', + 'ldap_userattr' => 'uid', + 'ldap_autocreateaccount_emailattribute' => 'mail', + ], +]; diff --git a/conf/addon.ini.php b/conf/addon.ini.php deleted file mode 100644 index 8098cb6..0000000 --- a/conf/addon.ini.php +++ /dev/null @@ -1,21 +0,0 @@ - db.sql # Backup cron job ynh_backup "/etc/cron.d/$app" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will now copy those files to the archive)." + diff --git a/scripts/install b/scripts/install index c4cf0a0..472b7e6 100644 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,10 @@ 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 @@ -44,21 +48,23 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_print_info "Validating installation parameters..." # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -70,13 +76,21 @@ ynh_app_setting_set $app database $database #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Installing dependencies..." ynh_install_app_dependencies 'php-mbstring|base-files(<<9.0)' php5-cli 'php5-imagick|php-imagick' php5-gd php5-mcrypt 'php-xml|base-files(<<9.0)' #================================================= # CREATE A MYSQL DATABASE #================================================= -# If your app uses a MySQL database, you can use these lines to bootstrap -# a database, an associated user and save the password in app settings +ynh_print_info "Creating a MySQL database..." +### Use these lines if you need a database for the application. +### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. +### The password will be stored as 'mysqlpwd' into the app settings, +### and will be available as $db_pwd +### If you're not using these lines: +### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script +### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script +### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -85,6 +99,11 @@ ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info "Setting up source files..." + +### `ynh_setup_source` is used to install an app from a zip or tar.gz file, +### downloaded from an upstream source, like a git repository. +### `ynh_setup_source` use the file conf/app.src ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src @@ -98,30 +117,34 @@ ynh_setup_source "$final_path/addon" "addons" #================================================= # NGINX CONFIGURATION #================================================= +ynh_print_info "Configuring nginx web server..." + +### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config ynh_add_nginx_config # configure friendica -sudo cp -f "/var/www/$app/config/local-sample.ini.php" "/var/www/$app/config/local.ini.php" -ynh_replace_string "your.mysqlhost.com" "localhost" "$final_path/config/local.ini.php" -ynh_replace_string "mysqlusername" "$db_name" "$final_path/config/local.ini.php" -ynh_replace_string "mysqldatabasename" "$db_name" "$final_path/config/local.ini.php" -ynh_replace_string "mysqlpassword" "$db_pwd" "$final_path/config/local.ini.php" -ynh_replace_string "admin_email =" "admin_email = $admin_mail" "$final_path/config/local.ini.php" -ynh_replace_string "register_policy = REGISTER_OPEN" "register_policy = REGISTER_CLOSED" "$final_path/config/local.ini.php" +sudo cp -f "/var/www/$app/config/local-sample.config.php" "/var/www/$app/config/local.config.php" +ynh_replace_string "your.mysqlhost.com" "localhost" "$final_path/config/local.config.php" +ynh_replace_string "mysqlusername" "$db_name" "$final_path/config/local.config.php" +ynh_replace_string "mysqldatabasename" "$db_name" "$final_path/config/local.config.php" +ynh_replace_string "mysqlpassword" "$db_pwd" "$final_path/config/local.config.php" +ynh_replace_string "'admin_email' => ''," "'admin_email' => '$admin_mail'," "$final_path/config/local.config.php" +ynh_replace_string "REGISTER_OPEN" "REGISTER_CLOSED" "$final_path/config/local.config.php" # init db ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "$final_path/database.sql" # addon config -sudo cp "../conf/addon.ini.php" "$final_path/config/." +sudo cp "../conf/addon.config.php" "$final_path/config/." #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app @@ -129,12 +152,22 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Configuring php-fpm..." +### `ynh_add_fpm_config` is used to set up a PHP config. +### You can remove it if your app doesn't use PHP. +### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script +### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script +### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script +### With the reload at the end of the script. +### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a dedicated php-fpm config ynh_add_fpm_config -# set permission sudo chown -R www-data:www-data $final_path # 3 - some extra folders @@ -147,14 +180,19 @@ ynh_replace_string "__USER__" "$app" ../conf/poller-cron sudo cp ../conf/poller-cron /etc/cron.d/$app #================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE +# STORE THE CONFIG FILE CHECKSUM #================================================= +### `ynh_store_file_checksum` is used to store the checksum of a file. +### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, +### you can make a backup of this file before modifying it again if the admin had modified it. + # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/config/local.ini.php" +ynh_store_file_checksum "$final_path/config/local.config.php" # Run composer (cd $final_path && sudo php bin/composer.phar install) +(cd $final_path && sudo bin/console config system addon ldapauth) chown -R $app: $final_path @@ -170,6 +208,12 @@ ynh_app_setting_set $app unprotected_uris "/" #================================================= # RELOAD NGINX #================================================= -sudo systemctl reload php5-fpm -sudo systemctl reload nginx -sudo yunohost app ssowatconf +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 00c966e..365c59e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -21,6 +22,7 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_print_info "Removing dependencies" # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -28,6 +30,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE THE MYSQL DATABASE #================================================= +ynh_print_info "Removing the MySQL database" # Remove a database if it exists, along with the associated user ynh_mysql_remove_db $db_name $db_name @@ -35,6 +38,7 @@ ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_print_info "Removing app main directory" # Remove the app directory securely ynh_secure_remove "/var/www/$app" @@ -42,6 +46,7 @@ ynh_secure_remove "/var/www/$app" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config @@ -49,6 +54,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Removing php-fpm configuration" # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -61,6 +67,13 @@ ynh_secure_remove "/etc/cron.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= +ynh_print_info "Removing the dedicated system user" # Delete a system user ynh_system_user_delete $app + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index cd74c85..fb0e695 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,25 +6,28 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +source ../settings/scripts/_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 SETTINGS #================================================= +ynh_print_info "Loading settings..." + app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) @@ -36,7 +39,9 @@ db_name=$(ynh_app_setting_get $app db_name) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ +ynh_print_info "Validating restoration parameters..." + +ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die "There is already a directory: $final_path " @@ -63,6 +68,7 @@ ynh_restore_file "$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 @@ -71,13 +77,14 @@ ynh_system_user_create $app # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" +ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_print_info "Reinstalling dependencies..." ynh_install_app_dependencies 'php-mbstring|base-files(<<9.0)' php5-cli 'php5-imagick|php-imagick' php5-gd php5-mcrypt 'php-xml|base-files(<<9.0)' @@ -92,11 +99,25 @@ ynh_restore_file "/etc/cron.d/$app" # Run composer (cd $final_path && sudo php bin/composer.phar install) +(cd $final_path && sudo bin/console config system addon ldapauth) + +chown -R $app: $final_path # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" -# And Reload services -sudo service php5-fpm reload -sudo service nginx reload -sudo yunohost app ssowatconf +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_print_info "Reloading nginx web server and php-fpm..." + +systemctl reload php7.0-fpm +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index b8c9a98..8e0da3b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -23,9 +24,21 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) admin_mail=$(ynh_app_setting_get $app email) admin=$(ynh_app_setting_get $app admin) +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_print_info "Ensuring downward compatibility..." + +# If db_name doesn't exist, create it +if [ -z $db_name ]; then + db_name=$(ynh_sanitize_dbid $app) + ynh_app_setting_set $app db_name $db_name +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_print_info "Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -52,11 +65,19 @@ if [ -z $final_path ]; then final_path=/var/www/$app ynh_app_setting_set $app final_path $final_path fi + +# Remove files for upgrade compatibilty from previous versions of Friendica if [ -f $final_path/.htconfig.php ]; then rm "$final_path/.htconfig.php" fi -if [ -z $admin_mail ]; then # If admin_mail setting doesn't exist +if [ -f $final_path/.htconfig.php ]; then + rm "$final_path/config/local.ini.php" +fi + + +# If admin_mail setting doesn't exist, create it +if [ -z $admin_mail ]; then admin_mail=$(sudo yunohost user info $admin | grep "mail:" | cut -d' ' -f2) ynh_app_setting_set $app email $admin_mail fi @@ -65,15 +86,15 @@ fi ynh_setup_source "$final_path" # Copy config file for correct place -cp -f "/var/www/$app/config/local-sample.ini.php" "/var/www/$app/config/local.ini.php" +cp -f "/var/www/$app/config/local-sample.config.php" "/var/www/$app/config/local.config.php" # Replace strings in config file -ynh_replace_string "your.mysqlhost.com" "localhost" "$final_path/config/local.ini.php" -ynh_replace_string "mysqlusername" "$db_name" "$final_path/config/local.ini.php" -ynh_replace_string "mysqldatabasename" "$db_name" "$final_path/config/local.ini.php" -ynh_replace_string "mysqlpassword" "$db_pwd" "$final_path/config/local.ini.php" -ynh_replace_string "admin_email =" "admin_email = $admin_mail" "$final_path/config/local.ini.php" -ynh_replace_string "register_policy = REGISTER_OPEN" "register_policy = REGISTER_CLOSED" "$final_path/config/local.ini.php" +ynh_replace_string "your.mysqlhost.com" "localhost" "$final_path/config/local.config.php" +ynh_replace_string "mysqlusername" "$db_name" "$final_path/config/local.config.php" +ynh_replace_string "mysqldatabasename" "$db_name" "$final_path/config/local.config.php" +ynh_replace_string "mysqlpassword" "$db_pwd" "$final_path/config/local.config.php" +ynh_replace_string "'admin_email' => ''," "'admin_email' => '$admin_mail'," "$final_path/config/local.config.php" +ynh_replace_string "REGISTER_OPEN" "REGISTER_CLOSED" "$final_path/config/local.config.php" #Copy Addons @@ -86,24 +107,33 @@ sudo chmod -R 775 $final_path/view/smarty3 #================================================= # CREATE DEDICATED USER #================================================= +ynh_print_info "Making sure dedicated system user exists..." -# Create a system user +# Create a dedicated user (if not existing) ynh_system_user_create $app +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_print_info "Upgrading nginx web server configuration..." + # Create a dedicated nginx config ynh_add_nginx_config #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$final_path/config/local.ini.php" -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/config/local.ini.php" + +### 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 "$final_path/config/local.config.php" +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum "$final_path/config/local.config.php" # Set up cron job ynh_replace_string "__YNH_WWW_PATH__" "$final_path" ../conf/poller-cron @@ -112,6 +142,7 @@ sudo cp ../conf/poller-cron /etc/cron.d/$app # Run composer (cd $final_path && sudo php bin/composer.phar install) +(cd $final_path && sudo bin/console config system addon ldapauth) # Set app as owner chown -R $app: $final_path @@ -119,13 +150,21 @@ chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= - +ynh_print_info "Upgrading SSOwat configuration..." # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app skipped_uris "/" -# Reload services -sudo service php5-fpm reload || true -sudo service nginx reload || true -sudo yunohost app ssowatconf +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info "Reloading nginx web server..." + +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Upgrade of $app completed"