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

134 lines
4.9 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
2016-10-13 06:51:38 +02:00
# Exit on command errors and treat unset variables as an error
set -eu
2016-04-04 22:35:43 +02:00
2016-10-13 06:51:38 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2016-05-23 21:40:55 +02:00
2016-04-05 20:03:26 +02:00
# retrieve arguments
2016-10-13 06:51:38 +02:00
app=bozon
domain=$1
2017-01-07 14:26:26 +01:00
path=$2
2016-10-13 06:51:38 +02:00
is_public=$3
language=$4
filesize=$5
admin=$6
password=$7
2016-03-23 19:30:43 +01:00
2017-01-07 12:41:56 +01:00
# chech if / is present at start and not at end
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then
# first char is not / && path not empty => add / at start
path="/$path"
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
# last char is / && path is gretter than /
path="${path:0:${#path}-1}"
fi
2016-04-04 20:01:54 +02:00
# definie useful vars
parent_path=/var/www
2016-10-13 06:51:38 +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-13 06:51:38 +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-13 06:51:38 +02:00
ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist."
2016-10-13 06:51:38 +02:00
# add required packages
ynh_package_is_installed "php5-curl" || ynh_package_install "php5-curl"
ynh_package_is_installed "php5-gd" || ynh_package_install "php5-gd"
# 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-13 06:51:38 +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-10-13 06:51:38 +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/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-13 06:51:38 +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-04-05 20:03:26 +02:00
# configure config file
2016-10-13 06:51:38 +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-10-13 06:51:38 +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-13 06:51:38 +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-13 06:51:38 +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-13 06:51:38 +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-13 06:51:38 +02:00
sudo chown root: "$phpfpm_conf"
sudo chmod 644 "$phpfpm_conf"
# restart services
sudo service php5-fpm restart || true
sudo service nginx reload || true
# set temporary public access
ynh_app_setting_set "$app" unprotected_uris "/"
2016-04-20 22:15:16 +02:00
sudo yunohost app ssowatconf
2016-10-13 06:51:38 +02:00
2017-01-07 12:41:56 +01:00
# add alias line in hosts file
echo "127.0.0.1 $domain # $app" | sudo tee -a /etc/hosts
2016-10-13 06:51:38 +02:00
# fill the superadmin creation form
curl_path=$([ "$path" == "/" ] || echo "$path")
2017-01-07 14:26:26 +01:00
curl -k https://"$domain""$curl_path"/ > /dev/null 2>&1
2017-01-07 12:41:56 +01:00
sleep 1 && curl -kX POST \
--data-urlencode creation="1" \
--data-urlencode login="$admin" \
--data-urlencode pass="$password" \
--data-urlencode confirm="$password" \
2016-10-13 06:51:38 +02:00
https://"$domain""$curl_path"/index.php?p=login > /dev/null 2>&1
2017-01-07 12:41:56 +01:00
# remove alias line from hosts file
sudo sed -i "/# $app/d" /etc/hosts
2016-04-20 22:15:16 +02:00
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-10-13 06:51:38 +02:00
ynh_app_setting_delete "$app" unprotected_uris
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=$([ "$path" == "/" ] || echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
2016-10-13 06:51:38 +02:00
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"
sudo yunohost app ssowatconf
2016-03-23 19:30:43 +01:00
fi