2017-12-14 18:03:01 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source psql.sh
|
2019-11-05 17:30:30 +01:00
|
|
|
source ynh_install_php
|
2019-11-05 17:31:31 +01:00
|
|
|
source ynh_add_extra_apt_repos
|
2017-12-14 18:03:01 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2018-09-01 14:32:40 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
2017-12-14 18:03:01 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
# db names, ...
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app path $path_url
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
2019-11-05 17:50:23 +01:00
|
|
|
# INSTALL PHP7.3 AND DEPENDENCIES (EXP HELPER)
|
2017-12-14 18:03:01 +01:00
|
|
|
#=================================================
|
2019-11-05 17:50:23 +01:00
|
|
|
ynh_print_info --message="Installing php7.1..."
|
|
|
|
|
2019-11-05 17:51:05 +01:00
|
|
|
extra_pkg_dependencies="php7.1-zip php7.1-mysql php7.1-xml php7.1-intl php7.1-mbstring php7.1-gd php7.1-curl php7.1-soap php7.1-pgsql php7.1-xmlrpc postgresql"
|
2019-11-05 17:50:23 +01:00
|
|
|
ynh_install_php --phpversion="7.1" --package="$extra_pkg_dependencies"
|
2019-11-05 17:51:05 +01:00
|
|
|
|
2017-12-14 18:03:01 +01:00
|
|
|
#=================================================
|
|
|
|
# Create postgresql database
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
db_name=$app
|
|
|
|
db_pwd=$(ynh_string_random 30)
|
|
|
|
ynh_app_setting_set $app psql_db $db_name
|
|
|
|
ynh_app_setting_set $app psqlpwd $db_pwd
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
ynh_psql_create_user $app $db_pwd
|
|
|
|
ynh_psql_execute_as_root \
|
|
|
|
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
cp ../conf/config.php $final_path/.
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2018-09-01 14:32:40 +02:00
|
|
|
### `ynh_add_fpm_config` is used to set up a PHP config.
|
|
|
|
### You can remove it if your app doesn't use PHP.
|
|
|
|
### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini
|
|
|
|
### If you're not using these lines:
|
|
|
|
### - You can remove these files in conf/.
|
|
|
|
### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script
|
|
|
|
### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script
|
|
|
|
### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script
|
|
|
|
### With the reload at the end of the script.
|
|
|
|
### - And the section "PHP-FPM CONFIGURATION" in the upgrade script
|
|
|
|
|
2017-12-14 18:03:01 +01:00
|
|
|
# Create a dedicated php-fpm config
|
2018-09-01 14:32:40 +02:00
|
|
|
ynh_add_fpm_config
|
2017-12-14 18:03:01 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# SETUP config file
|
|
|
|
#=================================================
|
|
|
|
var_root=/home/yunohost.app/$app
|
|
|
|
ynh_replace_string "YNH_DB_USER" "$app" "$final_path/config.php"
|
|
|
|
ynh_replace_string "YNH_APP" "$db_name" "$final_path/config.php"
|
|
|
|
ynh_replace_string "YNH_DB_PWD" "$db_pwd" "$final_path/config.php"
|
|
|
|
ynh_replace_string "YNH_DOMAIN" "$domain" "$final_path/config.php"
|
|
|
|
if [ "$path_url" = "/" ]
|
|
|
|
then
|
|
|
|
ynh_replace_string "YNH_WWW_PATH" "" "$final_path/config.php"
|
|
|
|
else
|
|
|
|
ynh_replace_string "YNH_WWW_PATH" "$path_url" "$final_path/config.php"
|
|
|
|
fi
|
|
|
|
ynh_replace_string "YNH_VAR_ROOT" "$var_root" "$final_path/config.php"
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/config.php"
|
|
|
|
|
|
|
|
# Create the home directory
|
|
|
|
mkdir -p $var_root
|
2018-09-01 14:32:40 +02:00
|
|
|
chown -R $app: $var_root
|
2017-12-14 18:03:01 +01:00
|
|
|
chmod -R 700 $var_root
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP APPLICATION WITH CURL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set right permissions for curl install
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
|
|
|
# Reload Nginx
|
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown root: $final_path/config.php
|
|
|
|
|
|
|
|
|
|
|
|
# Set up poller
|
|
|
|
sudo cp ../conf/cron /etc/cron.d/$app
|
|
|
|
ynh_replace_string "YNH_DOMAIN" "$final_path" "/etc/cron.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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 unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
yunohost app ssowatconf
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl reload nginx
|