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
2019-05-21 00:20:22 +02:00

156 lines
5.4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
ynh_print_OFF
password=$YNH_APP_ARG_PASSWORD
ynh_print_ON
is_public=$5
final_path=/var/www/$app
db_user=emailPoubelle
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_print_info "Check settings for installation"
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# 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
# Check user
ynh_user_exists "$admin"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app db_name $db_user
ynh_app_setting_set $app final_path $final_path
#=================================================
#INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies"
ynh_install_app_dependencies $pkg_dependencies
#install locale (nginx will restart at the end of the install)
for i in $lang ; do
ynh_replace_string "# $i" "$i" /etc/locale.gen
done
locale-gen
#=================================================
#INSTALL SOURCES
#===============================================
ynh_print_info "Downloading sources to $final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
cp ../conf/index_source.php $final_path/www/index.php
ynh_replace_string "Template-exemple" "$domain" $final_path/www/index.php
#Temporaire - mettre en config
ln -s $final_path/lang/fr $final_path/lang/fr_FR
ln -s $final_path/lang/it $final_path/lang/it_IT
ln -s $final_path/www/template-exemple $final_path/template-exemple
#===============================================
#SETTINGS & DATABASE
#===============================================
ynh_print_info "Setting database & settings"
#generating random password for database
ynh_print_OFF
db_pwd=$(ynh_string_random)
ynh_app_setting_set $app mysqlpwd $db_pwd
ynh_print_ON
#configuring with given settings
cp $final_path/conf-dist.php $final_path/conf.php
#Update various conf : domain, database, user and password
ynh_replace_string "exemple.fr" "$domain" $final_path/conf.php
ynh_replace_string "exemple.com" "$domain" $final_path/conf.php
ynh_replace_string "define('DB', 'sqlite:'" "//define('DB', 'sqlite:'" $final_path/conf.php
ynh_replace_string "define('ALIASLIMITBYMAIL" "//define('ALIASLIMITBYMAIL" $final_path/conf.php
ynh_replace_string "// define('DB', 'mysql" " define('DB', 'mysql" $final_path/conf.php
ynh_replace_string "// define('DBUSER'," " define('DBUSER'," $final_path/conf.php
ynh_replace_string "// define('DBPASS'," " define('DBPASS'," $final_path/conf.php
ynh_replace_string "baseMysql" "$db_user" $final_path/conf.php
ynh_replace_string "utilisateurMysql" "$db_user" $final_path/conf.php
ynh_print_OFF
ynh_replace_string "motdepassedefou" "$db_pwd" $final_path/conf.php
ynh_replace_string "define('ADMIN_PASSWORD', 'admin');" "define('ADMIN_PASSWORD', '$password');" $final_path/conf.php
ynh_print_ON
#setting conf file not world-readable (dude, there is a plain-text password !)
chmod o-r $final_path/conf.php
#initialize database (databasename = db_user)
ynh_print_OFF
ynh_mysql_create_db $db_user $db_user $db_pwd
ynh_print_ON
#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/
yunohost service regen-conf postfix
#create the virtual aliases file
touch $final_path/var/virtual
postmap $final_path/var/virtual
chown -R www-data:www-data $final_path
#create an alias for deleted junk adresses
cp /etc/aliases /etc/aliases.emailpoubelle.bak #backup it
echo "devnull:/dev/null" | tee -a /etc/aliases
newaliases
#adding cronjob for removing expired email addresses
cp -a ../conf/$app.cron /etc/cron.d/$app
chmod 644 /etc/cron.d/$app
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD SERVICES
#=================================================
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=postfix --action=reload
service php* reload