1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wallabag2_ynh.git synced 2024-10-01 13:35:06 +02:00
wallabag2_ynh/scripts/install
lapineige af450e0559
Testing : implement logrotate / fix php-redis dependency blockign other apps (#151)
* Apply last example_ynh (#117)

* Apply last example_ynh

* Cleanup backup

* Create DISCLAIMER.md

* Create DISCLAIMER_fr.md

* Auto-update README

* Add files via upload

* Fix heading size

* Auto-update README

* Fix heading size

* Auto-update README

* Fix charset

* Auto-update README

* Update check_process

* 2.4.3 (#125)

* Upgrade to 2.4.2~ynh1

* Fix craue_config_setting

* Upgrade to 2.4.3~ynh1

* Upgrade to 2.4.3~ynh1

* Auto-update README

Co-authored-by: yalh76 <yalh@yahoo.com>
Co-authored-by: Yunohost-Bot <>

* Specify PHP version in every calls (#132)

* Specify PHP version in every calls

* Switch (back) to php7.4

* Add PHP-xml dependency for DOM extension

Co-authored-by: lapineige <lapineige@users.noreply.github.com>

* Auto-update README

* Fix php version reference (#136)

* Auto-update README

* Use YNH_PHP_VERSION

* Proper YNH_PHP_VERSION syntax

* Proper YNH_PHP_VERSION syntax : typo

* YNH_PHP_VERSION: fix missing change

* Fix phpversion → YNH_PHP_VERSION

* Upgrade to 2.5 (#134)

* Upgrade to 2.5

* Auto-update README

* Upgrade to 2.5

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

* Merge master (2.4.3/php7.4) into testing (2.5) (#137)

* Testing (#124)

* Apply last example_ynh (#117)

* Apply last example_ynh

* Cleanup backup

* Create DISCLAIMER.md

* Create DISCLAIMER_fr.md

* Auto-update README

* Add files via upload

* Fix heading size

* Auto-update README

* Fix heading size

* Auto-update README

* Fix charset

* Auto-update README

* Update check_process

Co-authored-by: lapineige <lapineige@users.noreply.github.com>
Co-authored-by: Yunohost-Bot <>

* Testing: update to 2.4.3 (#128)

* Apply last example_ynh (#117)

* Apply last example_ynh

* Cleanup backup

* Create DISCLAIMER.md

* Create DISCLAIMER_fr.md

* Auto-update README

* Add files via upload

* Fix heading size

* Auto-update README

* Fix heading size

* Auto-update README

* Fix charset

* Auto-update README

* Update check_process

* 2.4.3 (#125)

* Upgrade to 2.4.2~ynh1

* Fix craue_config_setting

* Upgrade to 2.4.3~ynh1

* Upgrade to 2.4.3~ynh1

* Auto-update README

Co-authored-by: yalh76 <yalh@yahoo.com>
Co-authored-by: Yunohost-Bot <>

* Specify PHP version in every calls (#132)

* Specify PHP version in every calls

* Switch (back) to php7.4

* Add PHP-xml dependency for DOM extension

Co-authored-by: lapineige <lapineige@users.noreply.github.com>

* Auto-update README

* Fix php version reference (#136)

* Auto-update README

* Use YNH_PHP_VERSION

* Proper YNH_PHP_VERSION syntax

* Proper YNH_PHP_VERSION syntax : typo

* YNH_PHP_VERSION: fix missing change

* Fix phpversion → YNH_PHP_VERSION

Co-authored-by: yalh76 <yalh@yahoo.com>
Co-authored-by: Yunohost-Bot <>
Co-authored-by: tituspijean <tituspijean@outlook.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>

Co-authored-by: yalh76 <yalh@yahoo.com>
Co-authored-by: tituspijean <tituspijean@outlook.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>

* 2.5 (#138)

* Upgrade to 2.5

* Auto-update README

* Upgrade to 2.5

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

* Auto-update README

* Fix PHP dependencies (#142)

* Switch version to 2.5.0~ynh2

* Auto-update README

* 2.5.1 (#146)

* v2.5.1

* Auto-update README

* v2.5.1

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

* fix version number

* Auto-update README

* fix php7.4-redis conflicting with php-redis (#145)

* Auto-update README

* Typo in version number (2.5.1, not 2.5.2)

* Auto-update README

* Setup logrotate (#144)

* Setup logrotate

* Setup logrotate

* Setup logrotate

* Setup logrotate

* Setup logrotate

* bum version number

* Auto-update README

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

* Auto-update README

* Specify PHP version for Redis (#155)

* Specify PHP version for Redis

Now available in Bullseye

* Auto-update README

* Bump requirement to YNH11 for php${version}-redis

* Auto-update README

Co-authored-by: yunohost-bot <yunohost@yunohost.org>

Co-authored-by: yalh76 <yalh@yahoo.com>
Co-authored-by: Yunohost-Bot <>
Co-authored-by: tituspijean <tituspijean@outlook.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>
Co-authored-by: JimboJoe <jimmy@monin.net>
2022-10-01 16:15:39 +02:00

202 lines
7.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=2
final_path=/var/www/$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
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
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
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=12
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
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
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=6
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
# Create a dedicated PHP-FPM config
ynh_add_fpm_config --phpversion=$YNH_PHP_VERSION
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE WALLABAG
#=================================================
ynh_script_progression --message="Configuring wallabag..." --weight=35
# Copy and set Wallabag dist configuration
wb_conf=$final_path/app/config/parameters.yml
cp $final_path/app/config/parameters.yml.dist $wb_conf
ynh_replace_string --match_string="fosuser_registration: true" --replace_string="fosuser_registration: false" --target_file=$wb_conf
ynh_replace_string --match_string="database_name: wallabag" --replace_string="database_name: $db_name" --target_file=$wb_conf
ynh_replace_string --match_string="database_user: root" --replace_string="database_user: $db_user" --target_file=$wb_conf
ynh_replace_string --match_string="database_password: ~" --replace_string="database_password: $db_pwd" --target_file=$wb_conf
ynh_replace_string --match_string="database_table_prefix: wallabag_" --replace_string="database_table_prefix: null" --target_file=$wb_conf
# Generate random DES key & password
deskey=$(ynh_string_random --length=24)
ynh_app_setting_set --app=$app --key=deskey --value=$deskey
ynh_replace_string --match_string="secret: ovmpmAWXRCabNlMgzlzFXDYmCFfzGv" --replace_string="secret: $deskey" --target_file=$wb_conf
ynh_replace_string --match_string="domain_name: https://your-wallabag-url-instance.com" --replace_string="domain_name: https://$domain$path_url" --target_file=$wb_conf
# Alias for php-cli execution command
php_exec="ynh_exec_as $app php$YNH_PHP_VERSION "$final_path/bin/console" --no-interaction --env=prod"
# Set permissions to app files
chown -R $app: $final_path
# Install dependencies and Wallabag
$php_exec wallabag:install
# Add users to Wallabag
for username in $(ynh_user_list)
do
user_email=$(ynh_user_get_info --username="$username" --key=mail)
user_pass=$(ynh_string_random)
$php_exec fos:user:create "$username" "$user_email" "$user_pass"
done
# Set admin user
$php_exec fos:user:promote --super "$admin"
# Configure Wallabag instance URL
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name <<< "UPDATE internal_setting SET value = 'https://$domain$path_url' WHERE name = 'wallabag_url'"
#=================================================
# SETUP HOOKS
#=================================================
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_user_create"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_user_delete"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
set_permissions
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
# Use logrotate to manage application logfile(s)
touch "$final_path/var/logs/prod.log"
ynh_use_logrotate "$final_path/var/logs/prod.log"
chown $app:www-data "$final_path/var/logs/prod.log"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..."
# Create the log file is not already existing during install
mkdir -p "/var/www/$app/var/logs/"
touch "/var/www/$app/var/logs/prod.log"
chown $app: "/var/www/$app/var/logs/prod.log"
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/www/$app/var/logs/prod.log" --failregex='app.ERROR: Authentication failure for user "([\w]+)?", from IP "<HOST>"' --max_retry=5
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
ynh_permission_update --permission="main" --add="visitors"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last