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
|
|
|
|
domain=$1
|
2018-11-23 23:56:53 +01:00
|
|
|
path_url=$2
|
2018-11-18 16:00:35 +01:00
|
|
|
admin=$3
|
|
|
|
is_public=$4
|
|
|
|
final_path=/var/www/$app
|
|
|
|
postfix=/etc/postfix/main.cf
|
|
|
|
|
2018-11-23 23:43:40 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
#sudo yunohost app setting $app is_public -v "$is_public"
|
2018-11-18 16:00:35 +01:00
|
|
|
|
2018-11-21 18:09:13 +01:00
|
|
|
#install dependency
|
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)
|
|
|
|
for i in $lang
|
|
|
|
do
|
2018-11-24 00:26:38 +01:00
|
|
|
# cat /etc/locale.gen | grep "^[^#;]" | grep $i
|
|
|
|
# if [[ ! $? -eq 0 ]]; then
|
|
|
|
# echo "$i UTF-8" >> /etc/locale.gen
|
|
|
|
# locale=1
|
|
|
|
# fi
|
|
|
|
ynh_replace_string "#$i" "$i" /etc/locale.gen
|
|
|
|
|
2018-11-23 19:03:57 +01:00
|
|
|
done
|
2018-11-24 00:26:38 +01:00
|
|
|
#if [[ $locale -eq 1 ]]; then
|
2018-11-23 19:03:57 +01:00
|
|
|
locale-gen
|
2018-11-24 00:26:38 +01:00
|
|
|
#fi
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
# Copy source files
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
sudo cp -R ../src/* $final_path
|
2018-11-22 22:13:27 +01:00
|
|
|
sudo cp ../conf/index_source.php $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-11-18 16:00:35 +01:00
|
|
|
#configuring with given settings
|
|
|
|
sudo cp $final_path/conf-dist.php $final_path/conf.php
|
|
|
|
sudo chown -R www-data:www-data $final_path
|
|
|
|
sudo sed -i "s@exemple.fr@$domain@g" $final_path/conf.php
|
|
|
|
sudo sed -i "s@exemple.com@$domain@g" $final_path/conf.php
|
|
|
|
|
|
|
|
#generating random password for database
|
|
|
|
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
db_user=emailPoubelle
|
|
|
|
|
|
|
|
#write password to the conf file
|
2018-11-23 23:43:40 +01:00
|
|
|
ynh_replace_string "motdepassedefou" "$db_pwd" $final_path/conf.php
|
|
|
|
#sudo sed -i "s@motdepassedefou@$db_pwd@g" $final_path/conf.php
|
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)
|
|
|
|
ynh_mysql_create_db $db_user $db_user $db_pwd
|
|
|
|
#sudo yunohost app initdb $db_user -p $db_pwd
|
2018-11-18 16:00:35 +01:00
|
|
|
|
|
|
|
#setting postfix to use virtual aliases file
|
|
|
|
sudo cp $postfix $postfix.emailpoubelle.bak #backup it eventually if that causes some issues
|
|
|
|
sudo sed -i "s/^virtual_alias_maps/#virtual_alias_maps/g" $postfix
|
|
|
|
echo "virtual_alias_maps = hash:$final_path/var/virtual" | sudo tee -a $postfix
|
|
|
|
|
|
|
|
#create the virtual aliases file
|
|
|
|
sudo touch $final_path/var/virtual
|
|
|
|
sudo postmap $final_path/var/virtual
|
|
|
|
sudo chown www-data $final_path/var/virtual
|
|
|
|
sudo chown www-data $final_path/var/virtual.db
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2018-11-24 01:16:09 +01:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path_url@g" ../conf/nginx.conf
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path/www/@g" ../conf/nginx.conf
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2018-11-23 23:29:21 +01:00
|
|
|
|
|
|
|
# Handle root path, avoid double slash.
|
|
|
|
# Temporary fix, in waiting for an upgrade of the helper. (#361)
|
2018-11-24 01:16:09 +01:00
|
|
|
#path_url_slash_less=${path_url%/}
|
|
|
|
#ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf"
|
|
|
|
#ynh_replace_string "__FINALPATH__/" "$final_path/www" "../conf/nginx.conf"
|
2018-11-23 23:29:21 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2018-11-24 01:16:09 +01:00
|
|
|
#ynh_add_nginx_config
|
2018-11-23 23:29:21 +01:00
|
|
|
|
2018-11-18 16:00:35 +01:00
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
|
|
|
sudo yunohost app setting $app skipped_uris -v "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#adding php-cli for cron
|
|
|
|
sudo apt-get update -qq
|
|
|
|
sudo apt-get install -yqq php5-cli
|
|
|
|
#adding cronjob for removing expired email addresses
|
|
|
|
sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle
|
|
|
|
sudo chmod 644 /etc/cron.d/emailpoubelle
|
|
|
|
|
|
|
|
# Restart services
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo service postfix reload
|
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
|
|
|
|