1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/horde_ynh.git synced 2024-09-03 19:16:08 +02:00
horde_ynh/scripts/install

249 lines
8.2 KiB
Text
Raw Normal View History

2018-02-06 14:33:23 +01:00
#!/bin/bash
2018-02-11 00:32:26 +01:00
#=================================================
# GENERIC START
#=================================================
2018-02-06 14:33:23 +01:00
# IMPORT GENERIC HELPERS
2022-03-09 00:27:32 +01:00
#=================================================
source _common.sh
2018-02-06 14:33:23 +01:00
source /usr/share/yunohost/helpers
2022-03-09 00:27:32 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
2018-02-06 14:33:23 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2022-03-09 00:27:32 +01:00
#=================================================
2018-02-06 14:33:23 +01:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2022-03-09 00:27:32 +01:00
#=================================================
2018-02-06 14:33:23 +01:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$(ynh_normalize_url_path --path_url $YNH_APP_ARG_PATH)
2018-02-06 14:33:23 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
2022-03-09 00:27:32 +01:00
admin=$YNH_APP_ARG_ADMIN
service_autodiscovery=$YNH_APP_ARG_SERVICE_AUTODISCOVERY
2018-02-06 14:33:23 +01:00
whups_install=$YNH_APP_ARG_WHUPS_INSTALL
sesha_install=$YNH_APP_ARG_SESHA_INSTALL
ansel_install=$YNH_APP_ARG_ANSEL_INSTALL
wicked_install=$YNH_APP_ARG_WICKED_INSTALL
2022-03-09 00:27:32 +01:00
app=$YNH_APP_INSTANCE_NAME
2018-02-06 14:33:23 +01:00
2022-03-09 00:27:32 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2018-02-06 14:33:23 +01:00
# Register (book) web path
2022-03-09 00:27:32 +01:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-02-06 14:33:23 +01:00
2022-03-09 00:27:32 +01:00
#=================================================
# 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=language --value=$language
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=service_autodiscovery --value=$service_autodiscovery
ynh_app_setting_set --app=$app --key=whups_install --value=$whups_install
ynh_app_setting_set --app=$app --key=sesha_install --value=$sesha_install
ynh_app_setting_set --app=$app --key=ansel_install --value=$ansel_install
ynh_app_setting_set --app=$app --key=wicked_install --value=$wicked_install
2018-02-06 14:33:23 +01:00
# Set list of optionnal app to install
optionnal_apps_list=""
ynh_script_progression --message="Configuring options and language..."
2018-02-06 14:33:23 +01:00
if [[ $whups_install == 1 ]]
then
optionnal_apps_list="$optionnal_apps_list horde/whups"
fi
if [[ $sesha_install == 1 ]]
then
optionnal_apps_list="$optionnal_apps_list horde/sesha"
fi
# if [[ $ansel_install == 1 ]]
# then
# optionnal_apps_list="$optionnal_apps_list horde/ansel"
# fi
if [[ $wicked_install == 1 ]]
then
optionnal_apps_list="$optionnal_apps_list horde/wicked"
fi
2018-02-11 00:32:26 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2018-02-06 14:33:23 +01:00
# Enable all necessary locales
if [[ "$language" != "en" ]]
then
locale_lang=$(egrep -i "(${language})_\1\.UTF-8" /etc/locale.gen | egrep -o "[a-z]{2}_[A-Z]{2}\.UTF-8")
2018-11-29 14:59:47 +01:00
for l in $locale_lang; do
ynh_replace_string "^#\s$l" "$l" /etc/locale.gen
done
2018-02-06 14:33:23 +01:00
locale-gen
fi
2022-03-09 00:27:32 +01:00
#=================================================
2018-02-06 14:33:23 +01:00
# INSTALL DEPENDENCIES
2022-03-09 00:27:32 +01:00
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=7
2022-03-09 00:27:32 +01:00
2018-02-06 14:33:23 +01:00
install_dependance
2022-03-09 00:27:32 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
2018-02-06 14:33:23 +01:00
# Create a system user
2022-03-09 00:27:32 +01:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-02-06 14:33:23 +01:00
2022-03-09 00:27:32 +01:00
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
2018-02-06 14:33:23 +01:00
2022-03-09 00:27:32 +01:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
2018-02-06 14:33:23 +01:00
mkdir $final_path
mkdir $final_path/data
2022-03-09 00:27:32 +01:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
config_nginx
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..."
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
gollem_data_dir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=gollem_data_dir --value=$gollem_data_dir
2018-02-06 14:33:23 +01:00
mkdir -p $gollem_data_dir
2022-03-09 00:27:32 +01:00
chmod 750 "$gollem_data_dir"
chmod -R o-rwx "$gollem_data_dir"
chown -R $app:www-data "$gollem_data_dir"
#=================================================
# ...
#=================================================
# Set execution for expect scripts
chmod +x ../conf/init_horde_install.exp
chmod +x ../conf/config_horde.exp
ynh_script_progression --message="Installing sources files..." --weight=7
2018-02-06 14:33:23 +01:00
pear config-create "$final_path" "$final_path/pear.conf"
pear -c "$final_path/pear.conf" install -o -f pear
pear_cmd="$final_path/pear/pear -c $final_path/pear.conf"
$pear_cmd config-set auto_discover 1
$pear_cmd config-set data_dir $final_path/data
$pear_cmd channel-discover pear.horde.org
$pear_cmd install horde/horde_role
../conf/init_horde_install.exp "$final_path" "$final_path/horde"
$pear_cmd config-set horde_dir "$final_path/horde"
$pear_cmd install -a -B horde/webmail $optionnal_apps_list
PHP_PEAR_SYSCONF_DIR=$final_path ../conf/config_horde.exp "$final_path" "$db_name" "$db_user" "$db_pwd" "$admin"
secret_key=$(grep 'secret_key' "$final_path/horde/config/conf.php" | cut -d"'" -f4)
2022-03-09 00:27:32 +01:00
ynh_app_setting_set --app=$app --key=secret_key --value="$secret_key"
2018-02-06 14:33:23 +01:00
# Patch the app
ynh_script_progression --message="Patching application..." --weight=7
2018-02-06 14:33:23 +01:00
patch_app
# Configure Horde
ynh_script_progression --message="Configuring application..." --weight=3
2018-02-06 14:33:23 +01:00
config_horde
2022-03-09 00:27:32 +01:00
# SECURE FILES AND DIRECTORIES
ynh_script_progression --message="Protecting directory..."
set_permission
2018-02-06 14:33:23 +01:00
2018-02-11 00:32:26 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2022-03-09 00:27:32 +01:00
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
2018-02-11 00:32:26 +01:00
2022-03-09 00:27:32 +01:00
ynh_use_logrotate $final_path/horde --nonappend --specific_user www-data/horde
ynh_use_logrotate $final_path/horde/services --append --specific_user www-data/horde
ynh_use_logrotate $final_path/horde/services/portal --append --specific_user www-data/horde
2018-02-06 14:33:23 +01:00
2022-03-09 00:27:32 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
2022-03-09 00:27:32 +01:00
2018-02-06 14:33:23 +01:00
if [ "$is_public" = "0" ];
then # Retire l'accès public
2022-03-09 00:27:32 +01:00
ynh_app_setting_delete --app=$app --key=skipped_uris
2018-02-06 14:33:23 +01:00
else
2022-03-09 00:27:32 +01:00
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2018-02-06 14:33:23 +01:00
fi
2022-03-09 00:27:32 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2022-03-09 00:27:32 +01:00
ynh_script_progression --message="Installation of $app completed"