2016-12-21 18:46:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# Charge les fonctions génériques habituellement utilisées dans le script
|
|
|
|
source fonctions
|
|
|
|
|
|
|
|
# Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
TRAP_ON
|
|
|
|
|
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# We retrieve app parameters
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# We check variables are not empty
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
|
|
|
|
path=$(ynh_app_setting_get $app path)
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
finalnginxconf=$(ynh_app_setting_get $app finalnginxconf)
|
|
|
|
finalphpconf=$(ynh_app_setting_get $app finalphpconf)
|
2016-12-22 01:44:07 +01:00
|
|
|
runninguser=$(ynh_app_setting_get $app runninguser)
|
2016-12-22 03:42:11 +01:00
|
|
|
calibrepath=$(ynh_app_setting_get $app calibrepath)
|
2016-12-22 13:01:20 +01:00
|
|
|
basicauthcreate=$(ynh_app_setting_get $app basicauthcreate)
|
2016-12-22 03:42:11 +01:00
|
|
|
|
2016-12-22 14:19:29 +01:00
|
|
|
# We check that calibrepath is correct
|
|
|
|
CHECK_CALIBREPATH
|
|
|
|
|
2016-12-22 13:01:20 +01:00
|
|
|
# Add basic auth if requested
|
|
|
|
if [ "$basicauthcreate" = "Yes" ];
|
|
|
|
then
|
|
|
|
basicauthuser=$(ynh_app_setting_get $app basicauthuser)
|
|
|
|
basicauthpass=$(ynh_app_setting_get $app basicauthpass)
|
|
|
|
|
|
|
|
# Generation of the htpasswd file according https://www.nginx.com/resources/wiki/community/faq/
|
|
|
|
SALT="$(openssl rand -base64 3)"
|
|
|
|
(SHA1=$(printf "$basicauthpass$SALT" |
|
|
|
|
openssl dgst -binary -sha1 | xxd -ps |
|
|
|
|
sed 's#$#'"`echo -n $SALT | xxd -ps`"'#' |
|
|
|
|
xxd -r -ps |
|
|
|
|
base64);printf "$basicauthuser:{SSHA}$SHA1\n" >> ../sources/htpasswd)
|
|
|
|
|
|
|
|
# Modif nginx
|
2016-12-22 13:34:28 +01:00
|
|
|
sed -i "s|^.*\bauth_basic\b.*$| auth_basic \"Private Library\";|" ../conf/nginx.conf;
|
2016-12-22 13:01:20 +01:00
|
|
|
sed -i "s|^.*\bauth_basic_user_file\b.*$| auth_basic_user_file $final_path/htpasswd;|" ../conf/nginx.conf;
|
|
|
|
else
|
|
|
|
echo "No basic auth";
|
|
|
|
fi
|
2016-12-22 03:42:11 +01:00
|
|
|
|
2016-12-21 18:46:36 +01:00
|
|
|
|
2016-12-22 01:47:34 +01:00
|
|
|
# We install dependencies
|
2016-12-22 02:08:38 +01:00
|
|
|
sudo apt-get install --quiet --assume-yes php5-gd php5-sqlite php5-json php5-intl
|
2016-12-22 01:47:34 +01:00
|
|
|
|
2016-12-21 18:46:36 +01:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
|
|
|
|
sudo cp ../conf/nginx.conf $finalnginxconf
|
|
|
|
|
|
|
|
|
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
2016-12-22 01:08:35 +01:00
|
|
|
sed -i "s@FOLDERTOCHANGE@$final_path@g" ../conf/php-fpm.conf
|
2016-12-22 01:44:07 +01:00
|
|
|
sed -i "s@USERTOCHANGE@$runninguser@g" ../conf/php-fpm.conf
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
|
|
sudo chown root: $finalphpconf
|
|
|
|
sudo chmod 644 $finalphpconf
|
|
|
|
|
2016-12-22 02:13:41 +01:00
|
|
|
# Removal of old folder and restart from fresh
|
|
|
|
sudo rm -rf $final_path
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2016-12-22 03:42:11 +01:00
|
|
|
# Site adjustments
|
|
|
|
sudo cp ../conf/config_local.php ../sources/
|
|
|
|
sed -i "s@CALIBRETOCHANGE@$calibrepath@g" ../sources/config_local.php
|
2016-12-22 14:08:07 +01:00
|
|
|
timezone=`sudo cat /etc/timezone`;
|
2016-12-22 14:11:35 +01:00
|
|
|
sed -i "s@TIMEZONETOCHANGE@$timezone@g" ../sources/config_local.php
|
2016-12-22 03:42:11 +01:00
|
|
|
|
2016-12-23 09:17:08 +01:00
|
|
|
sudo cp ../conf/robots.txt ../sources/
|
|
|
|
|
2016-12-22 02:13:41 +01:00
|
|
|
# Base site
|
|
|
|
sudo cp -a ../sources/* $final_path/
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
# We adjust permissions
|
|
|
|
sudo chmod 775 -R $final_path
|
2016-12-22 13:47:17 +01:00
|
|
|
sudo chown -hR $runninguser:$runninguser $final_path
|
2016-12-22 13:01:20 +01:00
|
|
|
|
|
|
|
if [ "$basicauthcreate" = "Yes" ];
|
|
|
|
then
|
2016-12-22 13:47:17 +01:00
|
|
|
sudo chmod 440 $final_path/htpasswd
|
|
|
|
sudo chown www-data:www-data $final_path/htpasswd
|
2016-12-22 13:01:20 +01:00
|
|
|
else
|
|
|
|
echo "Nothing to do"
|
|
|
|
fi
|
|
|
|
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
|
|
else
|
|
|
|
ynh_app_setting_set $app protected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service php5-fpm reload
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|