2015-05-31 13:46:25 +02:00
|
|
|
#!/bin/bash
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-01-14 01:29:27 +01:00
|
|
|
# GENERIC START
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-02-02 03:37:01 +01:00
|
|
|
source _common.sh
|
2021-07-12 13:54:37 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2022-01-14 01:29:27 +01:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
2021-07-12 14:45:08 +02:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2017-02-02 03:37:01 +01:00
|
|
|
#=================================================
|
2022-01-14 01:29:27 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-02-02 03:37:01 +01:00
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
# Register (book) web path
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2019-05-21 02:07:00 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-07-12 12:28:53 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2019-05-21 02:07:00 +02:00
|
|
|
|
2021-07-12 12:11:43 +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 --value=$admin
|
|
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2015-06-01 00:00:38 +02:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..." --weight=1
|
|
|
|
|
2021-07-12 12:16:32 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
2021-07-12 12:11:43 +02:00
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-03-13 21:49:11 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2015-06-01 00:00:38 +02:00
|
|
|
|
2021-07-12 13:10:03 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2022-01-14 01:29:27 +01:00
|
|
|
chmod 750 "$final_path/tmp"
|
2022-01-14 02:31:12 +01:00
|
|
|
chmod 750 "$final_path/upload"
|
2022-01-14 01:29:27 +01:00
|
|
|
chmod 750 "$final_path/application/config/"
|
2021-07-12 12:28:53 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2019-05-21 02:07:00 +02:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
# Create a dedicated NGINX config
|
2018-03-13 21:49:11 +01:00
|
|
|
ynh_add_nginx_config
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
# Create a dedicated PHP-FPM config
|
2018-03-13 21:49:11 +01:00
|
|
|
ynh_add_fpm_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
2022-01-14 01:29:27 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE THE DATA DIRECTORY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a data directory..." --weight=1
|
|
|
|
|
2022-01-14 10:24:42 +01:00
|
|
|
datadir=/home/yunohost.app/limesurvey/upload
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
2022-01-14 01:29:27 +01:00
|
|
|
mkdir -p $datadir
|
2022-01-14 10:24:42 +01:00
|
|
|
# Remove upload if empty
|
|
|
|
rmdir $datadir && mv "$final_path/upload" $datadir || true
|
2022-01-14 01:29:27 +01:00
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
|
2022-01-14 02:31:12 +01:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring Limesurvey..." --weight=1
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/config.php" --destination="$final_path/application/config/config.php"
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2018-03-14 14:11:46 +01:00
|
|
|
# INSTALL
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
|
2018-03-14 14:11:46 +01:00
|
|
|
ls_cli=$final_path/application/commands/console.php
|
2021-07-12 14:45:08 +02:00
|
|
|
|
2018-03-14 14:11:46 +01:00
|
|
|
fullname=$(ynh_user_get_info "$admin" "fullname")
|
|
|
|
mail=$(ynh_user_get_info "$admin" "mail")
|
2015-05-31 22:36:35 +02:00
|
|
|
|
2018-03-14 14:11:46 +01:00
|
|
|
# Permission should be correctly set before to do this
|
2021-07-12 14:45:08 +02:00
|
|
|
ynh_exec_as "$app" php $ls_cli install "$admin" "$password" "$fullname" "$mail"
|
|
|
|
|
|
|
|
# Permission should be correctly set before to do this
|
|
|
|
#ynh_exec_as "$app" php $ls_cli install "$admin" "$(ynh_string_random 24)" "$fullname" "$mail"
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
2018-03-14 14:11:46 +01:00
|
|
|
# LOAD SQL SPECIFIC CONFIG
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2022-01-14 01:29:27 +01:00
|
|
|
ynh_add_config --template="../conf/data.sql" --destination="./data.sql"
|
2021-07-12 12:11:43 +02:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./data.sql
|
2021-08-29 18:28:18 +02:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
ynh_secure_remove --file=./data.sql
|
2021-07-12 12:35:11 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2018-03-14 14:11:46 +01:00
|
|
|
# Add nice themes
|
|
|
|
#=================================================
|
2021-07-12 13:35:31 +02:00
|
|
|
|
2022-01-14 10:24:42 +01:00
|
|
|
#ynh_setup_source "$datadir/upload/templates/libreform" libreform
|
2018-03-14 14:11:46 +01:00
|
|
|
#ynh_setup_source "$final_path/upload/templates/librepoll" librepoll
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
2022-01-14 01:29:27 +01:00
|
|
|
#ynh_script_progression --message="Configuring fail2ban..." --weight=1
|
2021-07-12 14:33:54 +02:00
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
# No message in logs and the apps contains already a 10 minutes ban policy
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-07-12 12:35:11 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2021-07-12 12:28:53 +02:00
|
|
|
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2022-01-14 02:31:12 +01:00
|
|
|
allowed_groups="visitors $admin"
|
2022-01-14 01:29:27 +01:00
|
|
|
else
|
|
|
|
allowed_groups="$admin"
|
2021-07-12 12:28:53 +02:00
|
|
|
fi
|
2022-01-14 02:31:12 +01:00
|
|
|
ynh_permission_update --permission="main" --show_tile="false" --add="visitors"
|
2021-07-12 12:28:53 +02:00
|
|
|
|
2022-01-14 02:31:12 +01:00
|
|
|
ynh_permission_create --permission="admin" --url="/admin" --allowed=$allowed_groups --show_tile="true"
|
2021-07-12 12:28:53 +02:00
|
|
|
|
2015-05-31 22:36:35 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-07-12 12:28:53 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 12:28:53 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
2021-07-12 14:06:32 +02:00
|
|
|
ynh_script_progression --message="Sending a readme for the admin..." --weight=1
|
2019-05-21 02:07:00 +02:00
|
|
|
|
2021-07-12 14:06:32 +02:00
|
|
|
message="LimeSurvey was successfully installed :)
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 14:06:32 +02:00
|
|
|
You can now create a poll on this address: https://$domain$path_url/admin/
|
|
|
|
|
|
|
|
If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/limesurvey_ynh/issues"
|
|
|
|
|
|
|
|
ynh_send_readme_to_admin "$message"
|
2019-05-21 02:07:00 +02:00
|
|
|
|
2021-07-12 12:28:53 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|