2016-03-23 19:30:43 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2016-09-05 21:11:16 +02:00
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-04-04 22:35:43 +02:00
|
|
|
|
2016-05-23 21:40:55 +02:00
|
|
|
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
|
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# retrieve arguments
|
2016-05-23 21:40:55 +02:00
|
|
|
if [ $ynh_version = "2.4" ]; then
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
filesize=$YNH_APP_ARG_FILESIZE
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2016-05-23 21:52:19 +02:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2016-05-23 21:40:55 +02:00
|
|
|
else
|
|
|
|
app=bozon
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
is_public=$3
|
|
|
|
language=$4
|
|
|
|
filesize=$5
|
|
|
|
admin=$6
|
|
|
|
password=$7
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete files and db if exit with an error
|
|
|
|
EXIT_PROPERLY () {
|
|
|
|
trap '' ERR
|
|
|
|
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
|
|
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
|
|
|
|
|
|
|
|
if [ $ynh_version = "2.2" ]; then
|
2016-09-05 21:11:16 +02:00
|
|
|
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.s
|
2016-05-23 21:40:55 +02:00
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
TRAP_ON () { # Activate signal capture
|
|
|
|
trap EXIT_PROPERLY ERR # Capturing exit signals on error
|
|
|
|
}
|
|
|
|
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
|
|
|
|
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
|
|
|
|
# Mais pas la fonction TRAP_OFF...
|
|
|
|
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
|
|
|
|
trap '' ERR # Ignoring exit signals
|
|
|
|
}
|
|
|
|
TRAP_ON
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2016-04-04 20:01:54 +02:00
|
|
|
# definie useful vars
|
|
|
|
parent_path=/var/www
|
|
|
|
final_path=$parent_path/$app
|
2016-04-05 20:03:26 +02:00
|
|
|
data_path=/home/yunohost.app/$app
|
2016-04-04 20:01:54 +02:00
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# remove trailing slash
|
2016-03-23 19:30:43 +01:00
|
|
|
[ "$path" != "/" ] && path=${path%/}
|
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# check domain/path availability
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2016-05-23 21:40:55 +02:00
|
|
|
touch /force_stop
|
2016-03-23 19:30:43 +01:00
|
|
|
fi
|
|
|
|
|
2016-04-21 07:00:24 +02:00
|
|
|
# check that admin user is an existing account
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2016-05-23 21:40:55 +02:00
|
|
|
echo "Error : the chosen admin user does not exist"
|
|
|
|
touch /force_stop
|
2016-04-21 07:00:24 +02:00
|
|
|
fi
|
|
|
|
|
2016-09-05 21:11:16 +02:00
|
|
|
# add required packages
|
|
|
|
ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable to install dependencies"
|
|
|
|
|
|
|
|
# retrieve upstream_version version of bozon
|
|
|
|
upstream_version=$(cat ../conf/upstream_version)
|
2016-04-26 20:17:27 +02:00
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# save app settings
|
2016-04-21 07:00:24 +02:00
|
|
|
sudo yunohost app setting $app admin_user -v "$admin"
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo yunohost app setting $app is_public -v "$is_public"
|
|
|
|
sudo yunohost app setting $app domain -v "$domain"
|
|
|
|
sudo yunohost app setting $app path -v "$path"
|
2016-09-05 21:11:16 +02:00
|
|
|
sudo yunohost app setting $app version -v "$upstream_version"
|
2016-04-26 20:41:05 +02:00
|
|
|
sudo yunohost app setting $app filesize -v "$filesize"
|
2016-03-23 19:30:43 +01:00
|
|
|
|
2016-09-05 21:11:16 +02:00
|
|
|
# download upstream_version version of bozon
|
|
|
|
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/$upstream_version.zip -P /tmp
|
|
|
|
sudo unzip -oq /tmp/$upstream_version.zip -d /tmp
|
|
|
|
sudo mv /tmp/$upstream_version $parent_path/$app
|
2016-04-06 20:22:44 +02:00
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# copy files to final folder and set permissions
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo find $final_path -type f -name ".htaccess" | xargs sudo rm
|
|
|
|
sudo chown -R root: $final_path
|
|
|
|
sudo find $final_path -type f | xargs sudo chmod 644
|
|
|
|
sudo find $final_path -type d | xargs sudo chmod 755
|
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# configure config file
|
2016-05-23 21:40:55 +02:00
|
|
|
sudo sed -i "s@languageuage='en';@languageuage='$language';@g" $final_path/config.php
|
2016-03-24 20:10:52 +01:00
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# create data folders
|
2016-03-25 09:32:16 +01:00
|
|
|
sudo mkdir -p $final_path/private
|
2016-04-05 20:03:26 +02:00
|
|
|
sudo mkdir -p $data_path/uploads
|
|
|
|
sudo ln -s $data_path/uploads $final_path/uploads
|
|
|
|
sudo mkdir -p $data_path/thumbs
|
|
|
|
sudo ln -s $data_path/thumbs $final_path/thumbs
|
2016-03-25 09:32:16 +01:00
|
|
|
sudo chown -R www-data: $final_path/private
|
2016-04-05 20:03:26 +02:00
|
|
|
sudo chown -R www-data: $data_path/uploads
|
|
|
|
sudo chown -R www-data: $data_path/thumbs
|
2016-03-25 09:32:16 +01:00
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# configure nginx settings
|
2016-04-16 17:17:11 +02:00
|
|
|
## path
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
2016-05-23 19:10:38 +02:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf
|
2016-05-23 21:48:23 +02:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
|
2016-05-23 20:59:08 +02:00
|
|
|
## file upload size limit
|
|
|
|
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
|
|
|
|
## copy final
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
2016-05-23 20:59:08 +02:00
|
|
|
# copy and set php-fpm configuration
|
|
|
|
## path
|
|
|
|
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf
|
|
|
|
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
|
|
|
|
## file upload size limit
|
|
|
|
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
|
|
|
|
postsize=${filesize%?}.1${filesize: -1}
|
|
|
|
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
|
|
|
|
## copy final and set permissions
|
|
|
|
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
|
|
|
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
|
|
|
|
sudo chown root: $phpfpm_conf
|
|
|
|
sudo chmod 644 $phpfpm_conf
|
|
|
|
|
2016-04-20 22:15:16 +02:00
|
|
|
# create the superadmin
|
|
|
|
## set temporary public access
|
|
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
|
|
|
## start app
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
## fill the superadmin creation form
|
|
|
|
curl_path=$([ "$path" == "/" ] || echo $path)
|
|
|
|
curl -k -X POST \
|
2016-04-21 06:49:31 +02:00
|
|
|
--data-urlencode creation="1" \
|
|
|
|
--data-urlencode login="$admin" \
|
|
|
|
--data-urlencode pass="$password" \
|
|
|
|
--data-urlencode confirm="$password" \
|
2016-04-20 22:15:16 +02:00
|
|
|
https://$domain$curl_path/index.php?p=admin > /dev/null 2>&1
|
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# if app is private, remove url to SSOWat conf from skipped_uris
|
2016-03-23 19:30:43 +01:00
|
|
|
if [ "$is_public" = "No" ];
|
|
|
|
then
|
2016-04-24 17:20:05 +02:00
|
|
|
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
|
|
|
|
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
|
|
|
pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
2016-04-05 20:03:26 +02:00
|
|
|
# redirect to SSOwat login in
|
2016-04-04 22:35:43 +02:00
|
|
|
sudo yunohost app setting $app unprotected_uris -d
|
2016-04-24 17:45:34 +02:00
|
|
|
sudo yunohost app setting $app unprotected_regex -v "$domainluaregex$pathluaregex/index.php%?f=.+$","$domainluaregex$pathluaregex/index.php%?zipfolder=.+$","$domainluaregex$pathluaregex/private/temp/.+%.zip$","$domainluaregex$pathluaregex/core/js/.*$","$domainluaregex$pathluaregex/templates/.*$"
|
2016-03-23 19:30:43 +01:00
|
|
|
fi
|
|
|
|
|
2016-04-05 20:03:26 +02:00
|
|
|
# restart services
|
2016-05-23 20:59:08 +02:00
|
|
|
sudo service php5-fpm restart || true
|
|
|
|
sudo service nginx restart || true
|
2016-03-23 19:30:43 +01:00
|
|
|
sudo yunohost app ssowatconf
|