mirror of
https://github.com/YunoHost-Apps/bozon_ynh.git
synced 2024-09-03 18:16:09 +02:00
114 lines
3.9 KiB
Bash
114 lines
3.9 KiB
Bash
#!/bin/bash
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# manage script failure
|
|
ynh_abort_if_errors
|
|
|
|
# retrieve arguments
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
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
|
|
|
|
# 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"
|
|
|
|
# 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"
|
|
|
|
# check that admin user is an existing account
|
|
ynh_user_exists "$admin"
|
|
|
|
# add required packages
|
|
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
|
|
|
# save app settings
|
|
ynh_app_setting_set "$app" domain "$domain"
|
|
ynh_app_setting_set "$app" path "$path_url"
|
|
ynh_app_setting_set "$app" is_public $is_public
|
|
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
|
|
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"
|
|
|
|
# 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
|
|
sudo find "$final_path" -type f | xargs sudo chmod 0644
|
|
sudo find "$final_path" -type d | xargs sudo chmod 0755
|
|
sudo find "$data_path" -type d | xargs sudo chmod 0755
|
|
sudo chown -R "$app": "$final_path/private"
|
|
sudo chown -R "$app": "$data_path/uploads"
|
|
sudo chown -R "$app": "$data_path/thumbs"
|
|
|
|
# configure nginx settings
|
|
myynh_add_nginx_config
|
|
|
|
# copy and set php-fpm configuration
|
|
myynh_add_fpm_config
|
|
|
|
# set temporary public access for curl call
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
sudo yunohost app ssowatconf
|
|
|
|
# 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
|
|
|
|
# if app is private, remove url to SSOWat conf from skipped_uris
|
|
if [ $is_public -eq 0 ]
|
|
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
|
|
fi
|