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

148 lines
5.9 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2016-10-13 06:51:38 +02:00
source /usr/share/yunohost/helpers
2016-05-23 21:40:55 +02:00
2020-01-05 19:49:24 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2020-01-05 19:49:24 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
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
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"
2020-01-05 19:49:24 +01:00
path_url=$(ynh_normalize_url_path --path_url="$path_url")
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
## check domain/path availability
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
## register (book) web path
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
## check that admin user is an existing account
ynh_user_exists --username="$admin"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
ynh_app_setting_set --app="$app" --key=path --value="$path_url"
ynh_app_setting_set --app="$app" --key=is_public --value=$is_public
ynh_app_setting_set --app="$app" --key=admin_user --value="$admin"
ynh_app_setting_set --app="$app" --key=backup_core_only --value=$backup_core_only
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
ynh_app_setting_set --app="$app" --key=data_path --value="$data_path"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=3
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username="$app"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
## download source
tmpdir=$(mktemp -d)
ynh_setup_source --dest_dir="$tmpdir"
## clean & copy files needed to final folder
2017-09-22 19:33:28 +02:00
myynh_clean_source
2020-01-05 19:49:24 +01:00
mv "$tmpdir" "$final_path"
## create private & data folders
myynh_create_dir "$final_path/private"
myynh_create_dir "$data_path/uploads"
myynh_create_dir "$data_path/thumbs"
2017-09-22 19:33:28 +02:00
ln -s "$data_path/uploads" "$final_path/uploads"
ln -s "$data_path/thumbs" "$final_path/thumbs"
2020-01-05 19:49:24 +01:00
## set permissions
2017-07-07 17:03:57 +02:00
myynh_set_permissions
2016-03-25 09:32:16 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
2018-05-26 14:44:52 +02:00
if [ "$path_url" != "/" ]; then
2020-01-05 19:49:24 +01:00
ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf"
2018-05-26 13:17:41 +02:00
fi
ynh_add_nginx_config
2016-03-23 19:30:43 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..."
2018-05-26 13:17:41 +02:00
ynh_add_fpm_config
2020-01-05 19:49:24 +01:00
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
# create admin user in bozon
ynh_script_progression --message="Configuring admin user in BoZon..." --weight=2
## set the app as temporarily public for curl call
ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/"
## reload SSOwat config
2017-09-23 19:01:29 +02:00
yunohost app ssowatconf
2020-01-05 19:49:24 +01:00
## reload Nginx
ynh_systemd_action --service_name=nginx --action=reload
## fill the superadmin creation form (helper ynh_local_curl doesn't work due to --data vs --data-urlencode ?)
2019-11-18 10:23:03 +01:00
admin_url="/index.php?p=login"
2020-01-05 19:49:24 +01:00
admin=$(myynh_urlencode $admin)
ynh_print_OFF
password=$(myynh_urlencode $password)
ynh_local_curl $admin_url "creation=1" "login=$admin" "pass=$password" "confirm=$password"
ynh_print_ON
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..."
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=.*$"
2020-01-05 19:49:24 +01:00
ynh_app_setting_set --app="$app" --key=protected_regex --value="$regexList"
2016-03-23 19:30:43 +01:00
fi
2020-01-05 19:49:24 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last