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

174 lines
6.1 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
#=================================================
2022-07-28 03:39:57 +02:00
2017-01-17 20:08:23 +01:00
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
2017-01-07 12:41:56 +01:00
2022-07-28 03:39:57 +02:00
app=$YNH_APP_INSTANCE_NAME
2020-01-05 19:49:24 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
2022-07-28 03:39:57 +02:00
final_path=/var/www/$app
datadir="/home/yunohost.app/$app"
path_url=$(ynh_normalize_url_path --path_url="$path_url")
2020-01-05 19:49:24 +01:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2022-07-28 03:39:57 +02:00
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2020-01-05 19:49:24 +01:00
## check that admin user is an existing account
ynh_user_exists --username="$admin"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
2022-07-28 03:39:57 +02:00
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=admin_user --value=$admin
ynh_app_setting_set --app=$app --key=final_path --value="$final_path"
ynh_app_setting_set --app=$app --key=datadir --value="$datadir"
2020-01-05 19:49:24 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=3
2022-07-28 03:39:57 +02:00
ynh_install_app_dependencies $pkg_dependencies
2020-01-05 19:49:24 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
2022-07-28 03:39:57 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2020-01-05 19:49:24 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
2022-07-28 03:39:57 +02:00
2020-01-05 19:49:24 +01:00
## 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"
2022-07-28 03:39:57 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
2016-03-25 09:32:16 +01:00
2020-01-05 19:49:24 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2022-07-28 03:39:57 +02:00
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
#=================================================
2022-07-28 03:39:57 +02:00
# SPECIFIC SETUP
2020-01-05 19:49:24 +01:00
#=================================================
2022-07-28 03:39:57 +02:00
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
## create private & data folders
myynh_create_dir "$final_path/private"
myynh_create_dir "$datadir/uploads"
myynh_create_dir "$datadir/thumbs"
ln -s "$datadir/uploads" "$final_path/uploads"
ln -s "$datadir/thumbs" "$final_path/thumbs"
## set permissions
myynh_set_permissions
2020-01-05 19:49:24 +01:00
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
ynh_script_progression --message="Configuring admin user in BoZon..." --weight=2
2022-07-28 03:39:57 +02:00
# Set the app as temporarily public for curl call
ynh_script_progression --message="Configuring SSOwat..."
# Making the app public for curl
ynh_permission_update --permission="main" --add="visitors"
2020-01-05 19:49:24 +01:00
## 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..."
2022-07-28 03:39:57 +02:00
2020-01-05 19:49:24 +01:00
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=.*$"
2016-03-23 19:30:43 +01:00
fi
2020-01-05 19:49:24 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2022-07-28 03:39:57 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2020-01-05 19:49:24 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2022-07-28 03:39:57 +02:00
2020-01-05 19:49:24 +01:00
ynh_script_progression --message="Installation of $app completed" --last