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
2016-10-11 21:44:13 +02:00

120 lines
4.3 KiB
Bash

#! /bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# retrieve arguments
app=bozon
domain=$1
path=${2%/}
is_public=$3
language=$4
filesize=$5
admin=$6
password=$7
# definie useful vars
parent_path=/var/www
final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/"$app"
# check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die "The path ${domain}${path} is not available for app installation."
# check that admin user is an existing account
ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist."
# 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)
# save app settings
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"
# 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/BoZoN-"$upstream_version" "$parent_path"/"$app"
# copy files to final folder and set permissions
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
# configure config file
sudo sed -i "s@languageuage='en';@languageuage='$language';@g" $final_path/config.php
# create data folders
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
# configure nginx settings
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"
# copy and set php-fpm configuration
postsize=${filesize%?}.1${filesize: -1}
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
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
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: "$phpfpm_conf"
sudo chmod 644 "$phpfpm_conf"
# create the superadmin
## set temporary public access
ynh_app_setting_set "$app" unprotected_uris "/"
## start app
sudo service nginx reload
sudo yunohost app ssowatconf
## fill the superadmin creation form
curl_path=$([ "$path" == "/" ] || echo "$path")
curl -k -X POST \
--data-urlencode creation="1" \
--data-urlencode login="$admin" \
--data-urlencode pass="$password" \
--data-urlencode confirm="$password" \
https://"$domain""$curl_path"/index.php?p=admin > /dev/null 2>&1
# if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ];
then
# 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')
# redirect to SSOwat login in
ynh_app_setting_delete "$app" unprotected_uris
ynh_app_setting_set "$app" unprotected_regex \
"${domainluaregex}${pathluaregex}/index.php%?f=.+$", \
"${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$", \
"${domainluaregex}${pathluaregex}/private/temp/.+%.zip$", \
"${domainluaregex}${pathluaregex}/core/js/.*$", \
"${domainluaregex}${pathluaregex}/templates/.*$"
fi
# restart services
sudo service php5-fpm restart || true
sudo service nginx restart || true