1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bozon_ynh.git synced 2024-09-03 18:16:09 +02:00
bozon_ynh/scripts/install

113 lines
3.3 KiB
Text
Raw Normal View History

2016-03-23 19:30:43 +01:00
#! /bin/bash
2016-04-04 22:35:43 +02:00
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
2016-04-05 20:03:26 +02:00
# retrieve arguments
2016-03-23 19:30:43 +01:00
domain=$1
path=$2
2016-04-17 18:37:01 +02:00
is_public=$3
default_lang=$4
filesize=$5
2016-04-17 19:06:54 +02:00
version=$6
2016-04-20 22:15:16 +02:00
admin=$7
password=$8
2016-03-23 19:30:43 +01:00
2016-04-04 20:01:54 +02:00
# definie useful vars
app=bozon
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
exit 1
fi
2016-04-05 20:03:26 +02:00
# save app settings
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-04-05 20:03:26 +02:00
# download bozon
2016-04-17 19:06:54 +02:00
if [ "$version" = "Latest" ];
then
sudo wget https://github.com/broncowdd/BoZoN/archive/master.zip -O $parent_path/master.zip
else
2016-04-17 20:14:49 +02:00
stable=$(curl https://raw.githubusercontent.com/ewilly/bozon_ynh/master/BoZoN-stable)
2016-04-17 19:06:54 +02:00
sudo wget https://github.com/broncowdd/BoZoN/archive/$stable.zip -O $parent_path/master.zip
fi
2016-04-04 21:41:27 +02:00
sudo unzip $parent_path/master.zip -d $parent_path/
2016-04-04 21:29:46 +02:00
sudo rm $parent_path/master.zip
2016-04-17 19:06:54 +02:00
sudo mv $parent_path/BoZoN-* $parent_path/$app
2016-03-23 19:30:43 +01:00
2016-04-06 20:22:44 +02:00
# add required packages
sudo apt-get install php5-curl php5-gd
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-04-16 19:52:04 +02:00
sudo sed -i "s@default_language='en';@default_language='$default_lang';@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
## file upload size limit
postsize=$(echo "${filesize%?}.1${filesize: -1}")
2016-04-16 17:17:11 +02:00
sudo sed -i "s@YNH_FILE_SIZE@$filesize@g" ../conf/nginx.conf
sudo sed -i "s@YNH_POST_SIZE@$postsize@g" ../conf/nginx.conf
## path
2016-03-23 19:30:43 +01:00
folder_path=${path%/}
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
2016-04-05 20:03:26 +02:00
# if path is only / (without subfolder), add trailing slash to alias
2016-03-23 19:30:43 +01:00
alias_path=$final_path
[ "$path" == '/' ] && alias_path=$alias_path'/'
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$alias_path@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_FOLDER@$folder_path@g" ../conf/nginx.conf
2016-04-16 17:17:11 +02:00
2016-03-23 19:30:43 +01:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.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 \
-d creation="1" \
-d login=$admin \
-d pass=$password \
-d confirm=$password \
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-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
else
sudo yunohost app setting $app unprotected_uris -v "/"
2016-03-23 19:30:43 +01:00
fi
2016-04-05 20:03:26 +02:00
# restart services
2016-03-23 19:30:43 +01:00
sudo service nginx reload
sudo yunohost app ssowatconf