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

109 lines
3.5 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
source _common.sh
2016-10-13 06:51:38 +02:00
source /usr/share/yunohost/helpers
2016-05-23 21:40:55 +02:00
# manage script failure
ynh_abort_if_errors
2016-04-05 20:03:26 +02:00
# retrieve arguments
2017-01-17 20:08:23 +01:00
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
2017-01-17 20:08:23 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2017-01-18 19:10:07 +01:00
language=$YNH_APP_ARG_LANGUAGE
filesize=$YNH_APP_ARG_FILESIZE
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
backup_core_only=$YNH_APP_ARG_BACKUP_CORE_ONLY
2017-01-07 12:41:56 +01:00
2016-04-04 20:01:54 +02:00
# definie useful vars
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
bozon_conf="$final_path/config.php"
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
2016-03-23 19:30:43 +01:00
2016-04-05 20:03:26 +02:00
# check domain/path availability
path_url=$(ynh_normalize_url_path "$path_url")
ynh_webpath_available "$domain" "$path_url"
ynh_webpath_register "$app" "$domain" "$path_url"
myynh_check_path "$final_path"
2016-03-23 19:30:43 +01:00
# check that admin user is an existing account
ynh_user_exists "$admin"
2016-10-13 06:51:38 +02:00
# add required packages
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
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" domain "$domain"
ynh_app_setting_set "$app" path "$path_url"
ynh_app_setting_set "$app" is_public $is_public
2016-10-13 06:51:38 +02:00
ynh_app_setting_set "$app" filesize "$filesize"
ynh_app_setting_set "$app" language "$language"
ynh_app_setting_set "$app" admin_user "$admin"
ynh_app_setting_set "$app" backup_core_only $backup_core_only
# create a dedicated system user
ynh_system_user_create "$app"
# download & unpack bozon
TMPDIR=$(mktemp -d)
ynh_setup_source "$TMPDIR"
# clean & copy files needed to final folder
sudo find "$TMPDIR" -type f -name ".htaccess" | xargs sudo rm
if [ -e "$TMPDIR/.gitignore" ]; then
for f in $(sudo cat "$TMPDIR/.gitignore") ; do
[ -e "$TMPDIR$f" ] && sudo rm -R "$TMPDIR$f"
done
sudo rm "$TMPDIR/.gitignore"
fi
sudo mv "$TMPDIR" "$final_path"
2016-03-23 19:30:43 +01:00
2016-04-05 20:03:26 +02:00
# configure config file
ynh_replace_string "default_language='en'" "default_language='$language'" "$bozon_conf"
ynh_store_file_checksum "$bozon_conf"
# create private & data folders
myynh_create_dir "$final_path/private"
myynh_create_dir "$data_path/uploads"
myynh_create_dir "$data_path/thumbs"
sudo ln -s "$data_path/uploads" "$final_path/uploads"
sudo ln -s "$data_path/thumbs" "$final_path/thumbs"
# set permissions
2017-07-07 17:03:57 +02:00
myynh_set_permissions
2016-03-25 09:32:16 +01:00
2016-04-05 20:03:26 +02:00
# configure nginx settings
myynh_add_nginx_config
2016-03-23 19:30:43 +01:00
2016-05-23 20:59:08 +02:00
# copy and set php-fpm configuration
myynh_add_fpm_config
# set temporary public access for curl call
2016-10-13 06:51:38 +02:00
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
# fill the superadmin creation form (helper ynh_local_curl doesn't work due to --data vs --data-urlencode ?)
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 https://localhost"$path_url"/ > /dev/null 2>&1
sleep 1
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST \
--data-urlencode creation="1" \
--data-urlencode login="$admin" \
--data-urlencode pass="$password" \
--data-urlencode confirm="$password" \
https://localhost"$path_url"/index.php?p=login > /dev/null 2>&1
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
if [ $is_public -eq 0 ]
2016-03-23 19:30:43 +01:00
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=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
ynh_app_setting_set "$app" protected_regex "$regexList"
sudo yunohost app ssowatconf
2016-03-23 19:30:43 +01:00
fi