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

117 lines
4.3 KiB
Text
Raw Normal View History

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-04-05 20:03:26 +02:00
# retrieve arguments
2016-10-11 20:16:36 +02:00
app=bozon
domain=$1
path=${2%/}
is_public=$3
2016-10-12 07:15:37 +02:00
language=$4
filesize=$5
admin=$6
password=$7
2016-03-23 19:30:43 +01:00
2016-04-04 20:01:54 +02:00
# definie useful vars
parent_path=/var/www
2016-10-11 20:16:36 +02:00
final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/"$app"
2016-03-23 19:30:43 +01:00
2016-04-05 20:03:26 +02:00
# check domain/path availability
2016-10-11 20:16:36 +02:00
sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die "The path ${domain}${path} is not available for app installation."
2016-03-23 19:30:43 +01:00
# check that admin user is an existing account
2016-10-11 20:16:36 +02:00
ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist."
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-10-11 20:16:36 +02:00
ynh_app_setting_set "$app" admin_user "$admin"
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path "$path"
ynh_app_setting_set "$app" filesize "$filesize"
2016-03-23 19:30:43 +01:00
2016-09-05 21:11:16 +02:00
# download upstream_version version of bozon
2016-10-11 20:16:36 +02:00
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
2016-10-11 21:32:25 +02:00
sudo mv /tmp/BoZoN-"$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-10-11 20:16:36 +02: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-03-23 19:30:43 +01:00
2016-10-12 07:15:37 +02:00
# configure config file
sudo sed -i "s@languageuage='en';@languageuage='${language}';@g" "$final_path"/config.php
2016-04-05 20:03:26 +02:00
# create data folders
2016-10-11 20:16:36 +02:00
sudo mkdir -p "$final_path"/private
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
sudo chown -R www-data: "$final_path"/private
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-10-11 20:16:36 +02:00
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf "$nginx_conf"
2016-03-23 19:30:43 +01:00
2016-05-23 20:59:08 +02:00
# copy and set php-fpm configuration
2016-10-11 20:16:36 +02:00
postsize=${filesize%?}.1${filesize: -1}
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
2016-05-23 20:59:08 +02:00
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
2016-10-11 20:16:36 +02:00
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
2016-05-23 20:59:08 +02:00
## copy final and set permissions
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
2016-10-11 20:16:36 +02:00
sudo chown root: "$phpfpm_conf"
sudo chmod 644 "$phpfpm_conf"
2016-05-23 20:59:08 +02:00
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-10-11 22:09:43 +02:00
2016-10-12 20:59:47 +02:00
# set temporary public access
ynh_app_setting_set "$app" unprotected_uris "/"
sudo yunohost app ssowatconf
2016-10-11 22:09:43 +02:00
# fill the superadmin creation form
curl_path=$([ "$path" == "/" ] || echo "$path")
2016-10-12 20:59:47 +02:00
curl https://"$domain""$curl_path"/ > /dev/null 2>&1
2016-10-12 07:15:37 +02:00
curl -X POST \
2016-10-11 22:17:59 +02:00
--data-urlencode creation="1" \
--data-urlencode login="$admin" \
--data-urlencode pass="$password" \
--data-urlencode confirm="$password" \
https://"$domain""$curl_path"/index.php?p=login > /dev/null 2>&1
2016-10-12 20:59:47 +02:00
# if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ];
then
ynh_app_setting_delete "$app" unprotected_uris
# 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')
regexList=${domainluaregex}${pathluaregex}/index.php%?f=.+$","${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$","${domainluaregex}${pathluaregex}/private/temp/.+%.zip$","${domainluaregex}${pathluaregex}/core/js/.*$","${domainluaregex}${pathluaregex}/templates/.*$"
ynh_app_setting_set "$app" unprotected_regex "$regexList"
fi
sudo yunohost app ssowatconf