mirror of
https://github.com/YunoHost-Apps/streams_ynh.git
synced 2024-09-03 20:26:20 +02:00
114 lines
3.7 KiB
Bash
Executable file
114 lines
3.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INITIALIZE SETTINGS
|
|
#=================================================
|
|
ynh_script_progression "Initialize installation settings..."
|
|
|
|
ynh_app_setting_set_default --key=email --value=$(ynh_user_get_info --username=$admin --key=mail)
|
|
ynh_app_setting_set_default --key=upload --value="256M"
|
|
ynh_app_setting_set_default --key=random_string --value="$(ynh_string_random --length=48)"
|
|
|
|
#=================================================
|
|
# CREATE A DATABASE
|
|
#=================================================
|
|
ynh_script_progression "Tweak database character set..."
|
|
|
|
ynh_mysql_db_shell \
|
|
<<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression "Setting up source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from GitHub
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
ynh_setup_source --dest_dir="$install_dir/addon" --source_id="addons"
|
|
|
|
ynh_exec_as_app mkdir -p "$install_dir/store"
|
|
ynh_exec_as_app mkdir -p "$install_dir/cache/smarty3"
|
|
|
|
ynh_exec_as_app chmod -R 775 $install_dir/store $install_dir/cache
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Configuring PHP-FPM..."
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_config_add_phpfpm
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_config_add_nginx
|
|
|
|
#=================================================
|
|
# COMPOSER
|
|
#=================================================
|
|
ynh_script_progression "Pulling in external libraries with Composer..."
|
|
|
|
ynh_composer_install
|
|
ynh_composer_exec install --no-dev
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# PROVISION DATABASE
|
|
#=================================================
|
|
ynh_script_progression "Provisionning database..."
|
|
|
|
ynh_mysql_db_shell < $install_dir/install/schema_mysql.sql
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression "Adding $app's configuration..."
|
|
|
|
timezone=$(</etc/timezone)
|
|
|
|
if [ $activate_directory -eq 1 ]
|
|
then
|
|
max_imported_follow=10
|
|
else
|
|
max_imported_follow=0
|
|
fi
|
|
|
|
ynh_config_add --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php"
|
|
|
|
ynh_store_file_checksum $install_dir/.htconfig.php
|
|
|
|
ynh_exec_as_app touch $data_dir/extra_conf.php
|
|
|
|
#=================================================
|
|
# SET CRON JOBS
|
|
#=================================================
|
|
ynh_script_progression "Setuping cron job..."
|
|
|
|
# Set up cron job
|
|
ynh_config_add --template="cronjobs" --destination="/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression "Configuring log rotation..."
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_config_add_logrotate "/var/log/$app/php.log"
|
|
ynh_exec_as_app touch "/var/log/$app/php.log"
|
|
|
|
#=================================================
|
|
# SETUP FAIL2BAN
|
|
#=================================================
|
|
ynh_script_progression "Configuring Fail2Ban..."
|
|
|
|
# Create a dedicated Fail2Ban config
|
|
ynh_config_add_fail2ban --logpath="/var/log/$app/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Installation of $app completed"
|