2016-12-21 18:46:36 +01:00
|
|
|
#!/bin/bash
|
2016-12-23 21:24:09 +01:00
|
|
|
#set -eu
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2016-12-22 03:42:11 +01:00
|
|
|
runninguser=$YNH_APP_ARG_RUNNINGUSER
|
2016-12-23 23:02:50 +01:00
|
|
|
calibre=$YNH_APP_ARG_CALIBRE
|
2016-12-22 13:01:20 +01:00
|
|
|
basicauthcreate=$YNH_APP_ARG_BASICAUTHCREATE
|
|
|
|
basicauthuser=$YNH_APP_ARG_BASICAUTHUSER
|
|
|
|
basicauthpass=$YNH_APP_ARG_BASICAUTHPASS
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
# We check variables are not empty
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
|
|
|
|
# Check the path value and correct it (adds / at begining and removes it at the end)
|
2016-12-23 21:24:09 +01:00
|
|
|
CHECK_PATH;
|
2016-12-21 18:46:36 +01:00
|
|
|
# Check domain and path availibility
|
|
|
|
CHECK_DOMAINPATH
|
|
|
|
# Check destination folder is not used already
|
|
|
|
CHECK_FINALPATH
|
|
|
|
|
2016-12-23 23:02:50 +01:00
|
|
|
# We check that calibre path is correct
|
|
|
|
CHECK_CALIBRE () { # Vérifie la présence du / en début de path. Et son absence à la fin.
|
|
|
|
if [ "${calibre:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
|
|
|
|
calibre="/$calibre" # Ajoute un / en début de path
|
|
|
|
fi
|
|
|
|
if [ "${calibre:${#calibre}-1}" == "/" ] && [ ${#calibre} -gt 1 ]; then # Si le dernier caractère est un / $
|
|
|
|
calibre="${calibre:0:${#calibre}-1}" # Supprime le dernier caractère
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_CALIBRE;
|
2016-12-23 22:01:37 +01:00
|
|
|
|
2016-12-21 18:46:36 +01:00
|
|
|
final_path=/var/www/$app
|
|
|
|
|
|
|
|
# Define variables and Save app settings
|
|
|
|
ynh_app_setting_set "$app" domain "$domain"
|
2016-12-23 18:05:13 +01:00
|
|
|
#ynh_app_setting_set "$app" path "$path"
|
2016-12-21 18:46:36 +01:00
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
2016-12-22 03:42:11 +01:00
|
|
|
ynh_app_setting_set "$app" runninguser "$runninguser"
|
2016-12-23 23:02:50 +01:00
|
|
|
ynh_app_setting_set "$app" calibre "$calibre"
|
2016-12-22 13:22:16 +01:00
|
|
|
ynh_app_setting_set "$app" basicauthcreate "$basicauthcreate"
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
finalnginxconf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
|
|
ynh_app_setting_set "$app" finalnginxconf "$finalnginxconf"
|
|
|
|
|
|
|
|
finalphpconf="/etc/php5/fpm/pool.d/${app}.conf"
|
|
|
|
ynh_app_setting_set "$app" finalphpconf "$finalphpconf"
|
|
|
|
|
2016-12-22 01:47:34 +01:00
|
|
|
# We install dependencies
|
2016-12-23 13:16:34 +01:00
|
|
|
sudo apt-get update -y
|
|
|
|
sudo apt-get install php5-gd php5-sqlite php5-json php5-intl -y
|
2016-12-21 18:46:36 +01:00
|
|
|
|
|
|
|
# Creation of folder
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2016-12-23 21:24:09 +01:00
|
|
|
# We download the sources and check the md5sum
|
|
|
|
cops_file=`sudo cat ../sources/source_file`;
|
2016-12-23 21:59:20 +01:00
|
|
|
sudo wget -nv -i ../sources/source_url -O $cops_file
|
2016-12-23 21:24:09 +01:00
|
|
|
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
2016-12-23 21:56:43 +01:00
|
|
|
sudo unzip ${cops_file} -d $final_path
|
2016-12-23 21:24:09 +01:00
|
|
|
|
2016-12-22 03:42:11 +01:00
|
|
|
# Site adjustments
|
2016-12-23 23:02:50 +01:00
|
|
|
sed -i "s@CALIBRETOCHANGE@$calibre@g" ../conf/config_local.php
|
2016-12-22 14:08:07 +01:00
|
|
|
timezone=`sudo cat /etc/timezone`;
|
2016-12-23 21:24:09 +01:00
|
|
|
sed -i "s@TIMEZONETOCHANGE@$timezone@g" ../conf/config_local.php
|
2016-12-22 14:08:07 +01:00
|
|
|
|
2016-12-23 21:24:09 +01:00
|
|
|
sudo cp ../conf/config_local.php $final_path
|
|
|
|
sudo cp ../conf/robots.txt $final_path
|
2016-12-22 03:42:11 +01:00
|
|
|
|
2016-12-23 21:24:09 +01:00
|
|
|
# Set permissions
|
|
|
|
sudo chmod 775 -R $final_path
|
|
|
|
sudo chown -hR $runninguser:$runninguser $final_path
|
2016-12-22 13:01:20 +01:00
|
|
|
|
|
|
|
# Add basic auth if requested
|
|
|
|
if [ "$basicauthcreate" = "Yes" ];
|
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" basicauthuser "$basicauthuser"
|
|
|
|
ynh_app_setting_set "$app" basicauthpass "$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)
|
2016-12-23 21:24:09 +01:00
|
|
|
sudo cp ../sources/htpasswd $final_path
|
|
|
|
sudo chmod 440 $final_path/htpasswd
|
|
|
|
sudo chown www-data:www-data $final_path/htpasswd
|
2016-12-22 13:01:20 +01:00
|
|
|
|
|
|
|
# Modif nginx
|
2016-12-22 13:34:28 +01:00
|
|
|
sed -i "s|^.*\bauth_basic\b.*$| auth_basic \"Private Library\";|" ../conf/nginx.conf;
|
|
|
|
sed -i "s|^.*\bauth_basic_user_file\b.*$| auth_basic_user_file $final_path/htpasswd;|" ../conf/nginx.conf;
|
2016-12-22 13:01:20 +01:00
|
|
|
else
|
|
|
|
echo "No basic auth";
|
|
|
|
fi
|
|
|
|
|
2016-12-23 21:24:09 +01:00
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf.d directory
|
2016-12-21 18:46:36 +01:00
|
|
|
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
|
|
|
|
|
2016-12-23 21:24:09 +01:00
|
|
|
# Modify php-fpm configuration file and copy it to php-fpm pool.d directory
|
2016-12-21 18:46:36 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
# 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 "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service php5-fpm reload
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|