1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/emailpoubelle_ynh.git synced 2024-09-03 18:26:29 +02:00
emailpoubelle_ynh/scripts/install

179 lines
6 KiB
Text
Raw Normal View History

2018-11-18 16:00:35 +01:00
#!/bin/bash
2018-11-20 23:57:22 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2022-06-08 03:24:51 +02:00
2018-11-24 00:08:25 +01:00
source _common.sh
2018-11-20 23:57:22 +01:00
source /usr/share/yunohost/helpers
2022-06-08 03:24:51 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2018-11-23 23:43:40 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2018-11-18 16:00:35 +01:00
2022-06-08 03:24:51 +02:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2018-11-24 11:02:54 +01:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
2022-06-08 03:24:51 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-11-24 11:02:54 +01:00
admin=$YNH_APP_ARG_ADMIN
2018-11-24 18:15:10 +01:00
password=$YNH_APP_ARG_PASSWORD
2022-06-08 03:24:51 +02:00
app=$YNH_APP_INSTANCE_NAME
2018-11-18 16:00:35 +01:00
2018-11-23 23:43:40 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2018-11-23 23:43:40 +01:00
2022-06-08 03:24:51 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2018-11-18 16:00:35 +01:00
2018-11-20 23:50:48 +01:00
# Register (book) web path
2022-06-08 03:24:51 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-11-24 00:26:38 +01:00
2018-11-23 23:43:40 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Storing installation settings..." --weight=1
2018-11-18 16:00:35 +01:00
2022-06-08 03:24:51 +02:00
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
2022-06-18 15:31:20 +02:00
ynh_app_setting_set --app=$app --key=password --value=$password
2018-11-18 16:00:35 +01:00
2018-11-24 14:19:37 +01:00
#=================================================
2022-06-08 03:24:51 +02:00
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
2018-11-24 14:19:37 +01:00
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Installing dependencies..." --weight=15
2022-06-08 03:24:51 +02:00
2018-11-24 00:09:49 +01:00
ynh_install_app_dependencies $pkg_dependencies
2019-05-21 00:20:22 +02:00
2018-11-23 19:03:57 +01:00
#install locale (nginx will restart at the end of the install)
2018-11-24 11:52:31 +01:00
for i in $lang ; do
2022-06-10 20:52:48 +02:00
ynh_replace_string --match_string="# $i" --replace_string="$i" --target_file="/etc/locale.gen"
2018-11-23 19:03:57 +01:00
done
2019-05-21 00:20:22 +02:00
2018-11-24 01:23:27 +01:00
locale-gen
2018-11-24 14:19:37 +01:00
#=================================================
2022-06-08 03:24:51 +02:00
# 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
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
2022-06-08 03:24:51 +02:00
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
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Setting up source files..." --weight=5
2022-06-08 03:24:51 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
2022-06-08 03:24:51 +02:00
ynh_setup_source --dest_dir="$final_path"
ynh_add_config --template="../conf/index_source.php" --destination="$final_path/www/index.php"
2022-06-10 20:52:48 +02:00
ynh_secure_remove --file="$final_path/www/admin.php"
2018-11-18 16:00:35 +01:00
2022-06-10 20:52:48 +02:00
ln -s $final_path/lib $final_path/www/lib
2018-11-22 21:39:07 +01:00
2022-06-08 03:24:51 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/conf-dist.php" --destination="$final_path/conf.php"
chmod 400 "$final_path/conf.php"
chown $app:$app "$final_path/conf.php"
# Setting postfix to use virtual aliases file
# Add postfix configuration hook and regen postfix conf
cp -R ../sources/hooks/conf_regen/98-postfix_emailpoubelle /usr/share/yunohost/hooks/conf_regen/
2020-11-01 16:49:03 +01:00
yunohost tools regen-conf postfix
2018-11-18 16:00:35 +01:00
2022-06-08 03:24:51 +02:00
# Create the virtual aliases file
2019-04-13 15:11:19 +02:00
touch $final_path/var/virtual
postmap $final_path/var/virtual
2022-06-10 20:52:48 +02:00
chown -R $app:www-data "$final_path"
2018-11-18 16:00:35 +01:00
2022-06-08 03:24:51 +02:00
# Create an alias for deleted junk adresses
2019-04-13 15:11:19 +02:00
cp /etc/aliases /etc/aliases.emailpoubelle.bak #backup it
echo "devnull:/dev/null" | tee -a /etc/aliases
newaliases
2022-06-08 03:24:51 +02:00
ynh_systemd_action --service_name=postfix --action=reload
2018-11-18 16:00:35 +01:00
2022-06-08 03:24:51 +02:00
# Adding cronjob for removing expired email addresses
ynh_add_config --template="../conf/emailpoubelle.cron" --destination="/etc/cron.d/$app"
chown root:root /etc/cron.d/$app
2019-04-13 15:11:19 +02:00
chmod 644 /etc/cron.d/$app
2018-11-23 23:29:21 +01:00
2022-06-08 03:24:51 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary
if [ $is_public -eq 1 ]
2018-11-18 16:00:35 +01:00
then
2022-06-08 03:24:51 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
2018-11-18 16:00:35 +01:00
fi
2019-05-21 00:20:22 +02:00
#=================================================
2022-06-08 03:24:51 +02:00
# RELOAD NGINX
2019-05-21 00:20:22 +02:00
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-05-21 00:20:22 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2022-06-08 03:24:51 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Installation of $app completed" --last