1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/garradin_ynh.git synced 2024-09-03 18:36:17 +02:00
garradin_ynh/scripts/install

157 lines
5.7 KiB
Text
Raw Normal View History

2017-01-28 22:05:00 +01:00
#!/bin/bash
#=================================================
2018-03-24 01:16:50 +01:00
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2017-01-28 22:05:00 +01:00
2018-03-24 01:16:50 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
2017-01-28 22:05:00 +01:00
# Retrieve arguments
#=================================================
2020-04-29 01:16:00 +02:00
#domain=$YNH_APP_ARG_DOMAIN
#path_url=$YNH_APP_ARG_PATH
#is_public=$YNH_APP_ARG_IS_PUBLIC
#app=$YNH_APP_INSTANCE_NAME
2017-01-28 22:05:00 +01:00
#=================================================
2018-03-24 01:16:50 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
2018-03-24 01:16:50 +01:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
2017-02-11 20:26:05 +01:00
2018-03-24 01:16:50 +01:00
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
2017-02-12 11:08:59 +01:00
2018-03-24 01:16:50 +01:00
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2017-02-11 19:50:47 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
2020-04-29 01:16:00 +02:00
#ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
2017-01-28 23:11:24 +01:00
# Install dependency to convert tracks to a readable format for the browser
#=================================================
ynh_script_progression --message="Installing dependencies..." --time --weight=1
2020-03-31 17:43:53 +02:00
2020-04-02 16:34:46 +02:00
if [ "$(lsb_release --codename --short)" != "jessie" ]
then
ynh_install_app_dependencies $pkg_dependencies
2020-04-02 16:34:46 +02:00
else
ynh_die --message="Votre version de Debian n'est pas compatible..." --time --weight=1
2020-04-02 16:34:46 +02:00
fi
2017-01-29 16:06:11 +01:00
#=================================================
2018-03-24 01:16:50 +01:00
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --time --weight=1
2018-03-24 01:16:50 +01:00
# Create a system user
ynh_system_user_create --username=$app
2017-01-28 22:05:00 +01:00
#=================================================
2018-03-24 01:16:50 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-03-24 01:16:50 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2018-03-24 01:16:50 +01:00
2017-01-28 22:05:00 +01:00
#=================================================
2018-03-24 01:16:50 +01:00
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
2018-03-24 01:16:50 +01:00
# Create a dedicated nginx config
2020-04-02 16:34:46 +02:00
ynh_add_nginx_config
2017-01-28 22:05:00 +01:00
2018-03-24 01:25:15 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..." --time --weight=1
2018-03-24 01:25:15 +01:00
# Create a dedicated php-fpm config
2020-04-02 16:34:46 +02:00
ynh_add_fpm_config
2018-03-24 01:25:15 +01:00
#=================================================
2020-04-29 01:16:00 +02:00
# Files owned by user app
#=================================================
2020-04-29 01:16:00 +02:00
chown $app:$app $final_path -R
chmod 755 $final_path -R
# Remove the public access
ynh_app_setting_delete --app=$app --key=skipped_uris
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --time --weight=1
# if [ $is_public -eq 0 ]
# then # Remove the public access
# ynh_app_setting_delete $app skipped_uris
# fi
# # Make app public if necessary
# if [ $is_public -eq 1 ]
# then
# # unprotected_uris allows SSO credentials to be passed anyway.
# ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
# fi
2018-03-24 01:16:50 +01:00
# Make app public if necessary
if [ $is_public -eq 1 ]
2017-01-28 22:05:00 +01:00
then
2020-04-29 01:16:00 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission "main" --add "visitors"
2017-01-28 22:05:00 +01:00
fi
2020-04-29 01:16:00 +02:00
# Only the users can access to the panel of the app
# ynh_permission_update --permission="main" --add "all_users"
2020-04-09 13:05:20 +02:00
#=================================================
2020-04-10 17:07:35 +02:00
# MODIFY A CONFIG FILE
2020-04-09 13:05:20 +02:00
#=================================================
2020-04-10 17:45:02 +02:00
# copy config.dist.php creating config.local.php
cp -a $final_path/config.dist.php $final_path/config.local.php
2020-04-10 17:45:02 +02:00
# create a key for the secret key CSFR;
key=$(ynh_string_random --length=50)
# edit config.local.php
ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php"
2020-04-10 17:45:02 +02:00
if [ "$path_url" == "/" ]; then
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php"
else
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php"
fi
2020-04-10 17:07:35 +02:00
#=================================================
2020-04-29 01:16:00 +02:00
# RELOAD NGINX
2020-04-10 17:07:35 +02:00
#=================================================
2020-04-29 01:16:00 +02:00
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
2020-04-10 17:07:35 +02:00
2020-04-29 01:16:00 +02:00
systemctl reload nginx
2020-04-10 17:07:35 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last