2018-11-18 16:00:35 +01:00
|
|
|
#!/bin/bash
|
2018-11-20 23:57:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2018-11-24 00:08:25 +01:00
|
|
|
source _common.sh
|
2018-11-20 23:57:22 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
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
|
|
|
|
|
|
|
# Retrieve arguments
|
2018-11-24 11:02:54 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_OFF
|
2018-11-24 18:15:10 +01:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_ON
|
2018-11-25 16:29:36 +01:00
|
|
|
is_public=$5
|
2018-11-18 16:00:35 +01:00
|
|
|
final_path=/var/www/$app
|
2018-11-24 11:52:31 +01:00
|
|
|
db_user=emailPoubelle
|
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
|
|
|
|
#=================================================
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_info "Check settings for installation"
|
2018-11-23 23:43:40 +01:00
|
|
|
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)
|
2018-11-18 16:00:35 +01:00
|
|
|
|
2018-11-20 23:50:48 +01:00
|
|
|
# Check web path availability
|
2018-11-23 23:43:40 +01:00
|
|
|
ynh_webpath_available $domain $path_url
|
2018-11-20 23:50:48 +01:00
|
|
|
# Register (book) web path
|
2018-11-23 23:43:40 +01:00
|
|
|
ynh_webpath_register $app $domain $path_url
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
# Check user
|
2018-11-21 00:19:45 +01:00
|
|
|
ynh_user_exists "$admin"
|
2018-11-24 00:26:38 +01:00
|
|
|
|
2018-11-23 23:43:40 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2018-11-18 16:00:35 +01:00
|
|
|
|
2018-11-23 23:43:40 +01:00
|
|
|
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
|
2018-11-24 11:52:31 +01:00
|
|
|
ynh_app_setting_set $app db_name $db_user
|
2018-11-24 11:57:51 +01:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2018-11-18 16:00:35 +01:00
|
|
|
|
2018-11-24 14:19:37 +01:00
|
|
|
#=================================================
|
|
|
|
#INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_info "Installing dependencies"
|
2018-11-24 00:09:49 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2018-11-18 16:00:35 +01: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
|
|
|
|
ynh_replace_string "# $i" "$i" /etc/locale.gen
|
2018-11-23 19:03:57 +01:00
|
|
|
done
|
2018-11-24 01:23:27 +01:00
|
|
|
locale-gen
|
|
|
|
|
2018-11-24 14:19:37 +01:00
|
|
|
#=================================================
|
|
|
|
#INSTALL SOURCES
|
|
|
|
#===============================================
|
2018-11-18 16:00:35 +01:00
|
|
|
# Copy source files
|
2019-03-04 21:10:34 +01:00
|
|
|
|
|
|
|
ynh_print_info "Downloading sources to $final_path"
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
2018-11-22 22:13:27 +01:00
|
|
|
sudo cp ../conf/index_source.php $final_path/www/index.php
|
2018-11-25 11:56:19 +01:00
|
|
|
ynh_replace_string "Template-exemple" "$domain" $final_path/www/index.php
|
2018-11-18 16:00:35 +01:00
|
|
|
|
2018-11-22 21:39:07 +01:00
|
|
|
#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
|
2018-12-01 11:43:23 +01:00
|
|
|
ln -s $final_path/www/template-exemple $final_path/template-exemple
|
2018-11-22 21:39:07 +01:00
|
|
|
|
2018-11-24 14:19:37 +01:00
|
|
|
|
|
|
|
#===============================================
|
|
|
|
#SETTINGS & DATABASE
|
|
|
|
#===============================================
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_info "Setting database & settings"
|
2018-11-24 14:19:37 +01:00
|
|
|
|
|
|
|
#generating random password for database
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_OFF
|
2018-11-24 14:19:37 +01:00
|
|
|
db_pwd=$(ynh_string_random)
|
2018-11-25 15:10:28 +01:00
|
|
|
ynh_app_setting_set $app mysqlpwd $db_pwd
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_ON
|
2018-11-24 14:19:37 +01:00
|
|
|
|
2018-11-18 16:00:35 +01:00
|
|
|
#configuring with given settings
|
|
|
|
sudo cp $final_path/conf-dist.php $final_path/conf.php
|
2018-11-24 11:52:31 +01:00
|
|
|
#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
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_OFF
|
2018-11-24 11:52:31 +01:00
|
|
|
ynh_replace_string "motdepassedefou" "$db_pwd" $final_path/conf.php
|
2018-11-24 18:15:10 +01:00
|
|
|
ynh_replace_string "define('ADMIN_PASSWORD', 'admin');" "define('ADMIN_PASSWORD', '$password');" $final_path/conf.php
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_ON
|
2018-11-18 16:00:35 +01:00
|
|
|
#setting conf file not world-readable (dude, there is a plain-text password !)
|
|
|
|
sudo chmod o-r $final_path/conf.php
|
2018-11-21 00:19:45 +01:00
|
|
|
#initialize database (databasename = db_user)
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_OFF
|
2018-11-21 00:19:45 +01:00
|
|
|
ynh_mysql_create_db $db_user $db_user $db_pwd
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_print_ON
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
#setting postfix to use virtual aliases file
|
2019-03-04 21:10:34 +01:00
|
|
|
# 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
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
#create the virtual aliases file
|
|
|
|
sudo touch $final_path/var/virtual
|
|
|
|
sudo postmap $final_path/var/virtual
|
2018-11-24 14:21:51 +01:00
|
|
|
sudo chown -R www-data:www-data $final_path
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
#create an alias for deleted junk adresses
|
|
|
|
sudo cp /etc/aliases /etc/aliases.emailpoubelle.bak #backup it
|
|
|
|
sudo echo "devnull:/dev/null" | sudo tee -a /etc/aliases
|
|
|
|
sudo newaliases
|
|
|
|
|
2019-03-05 22:43:49 +01:00
|
|
|
#adding cronjob for removing expired email addresses
|
|
|
|
sudo cp -a ../conf/$app.cron /etc/cron.d/$app
|
|
|
|
sudo chmod 644 /etc/cron.d/$app
|
2018-11-23 23:29:21 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2019-03-05 22:43:49 +01:00
|
|
|
ynh_add_nginx_config
|
2019-03-04 21:10:34 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
2018-11-18 16:00:35 +01:00
|
|
|
then
|
2019-03-04 21:10:34 +01:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2018-11-18 16:00:35 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Restart services
|
2018-11-25 15:05:26 +01:00
|
|
|
systemctl reload nginx
|
|
|
|
systemctl reload postfix
|
2018-11-23 19:05:47 +01:00
|
|
|
sudo service php* reload
|
2018-11-18 16:00:35 +01:00
|
|
|
sudo yunohost app ssowatconf
|
2018-11-23 19:05:47 +01:00
|
|
|
|