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

167 lines
5.8 KiB
Text
Raw Normal View History

2017-07-01 19:54:37 +02:00
#!/bin/bash
2017-08-01 11:29:01 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2017-08-01 11:29:01 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-07-01 19:54:37 +02:00
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
2017-08-01 11:29:01 +02:00
path_url=$YNH_APP_ARG_PATH
2017-07-01 19:54:37 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
admin_username=$YNH_APP_ARG_USERNAME
admin_name=$YNH_APP_ARG_NAME
admin_email=$YNH_APP_ARG_EMAIL
2018-09-01 18:12:10 +02:00
password=$(ynh_string_random 24)
admin_password=$(openssl passwd -1 -salt xyz $password)
2019-04-06 20:29:15 +02:00
app=$YNH_APP_INSTANCE_NAME
2017-08-01 11:29:01 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Validating installation parameters..."
2019-04-06 20:29:15 +02:00
2018-09-01 18:12:10 +02:00
final_path=/var/www/$app
2020-07-30 18:54:44 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-07-01 19:54:37 +02:00
2017-08-01 11:29:01 +02:00
# Register (book) web path
2020-07-30 18:54:44 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-09-01 18:12:10 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Storing installation settings..."
2019-04-06 20:29:15 +02:00
2020-10-16 11:21:00 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
2017-07-01 19:54:37 +02:00
2019-04-06 20:29:15 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Installing dependencies..."
2019-04-06 20:29:15 +02:00
ynh_install_app_dependencies $pkg_dependencies
2021-08-22 12:42:38 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2017-08-01 11:29:01 +02:00
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Creating a MySQL database..."
2018-09-01 18:12:10 +02:00
2020-02-23 19:45:22 +01:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
2021-03-31 13:13:00 +02:00
db_user=$db_name
2020-10-16 11:21:00 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2022-03-17 07:46:36 +01:00
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
2017-07-01 19:54:37 +02:00
2019-04-06 20:29:15 +02:00
#=================================================
2019-04-18 04:57:31 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2019-04-06 20:29:15 +02:00
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Setting up source files..."
2019-04-06 20:29:15 +02:00
2020-07-30 18:54:44 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-04-18 04:57:31 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2020-07-30 18:54:44 +02:00
ynh_setup_source --dest_dir="$final_path"
2017-07-01 19:54:37 +02:00
2021-08-22 12:42:38 +02:00
chmod 750 "$final_path"
chmod -R 700 $final_path/data
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2018-09-01 18:12:10 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-10-16 11:21:00 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2018-09-01 18:12:10 +02:00
# Create a dedicated NGINX config
2017-08-01 11:29:01 +02:00
ynh_add_nginx_config
2018-09-01 18:12:10 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2020-10-16 11:21:00 +02:00
ynh_script_progression --message="Configuring PHP-FPM..."
2018-09-01 18:12:10 +02:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
2020-10-16 11:21:00 +02:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2018-09-01 18:12:10 +02:00
#=================================================
2019-04-18 04:58:41 +02:00
# MODIFY A CONFIG FILE
2018-09-01 18:12:10 +02:00
#=================================================
2017-07-01 19:54:37 +02:00
2019-04-18 04:58:41 +02:00
# Adding the details of the database to the config file
2021-03-31 13:13:00 +02:00
ynh_add_config --template="../conf/config.ini.php" --destination="$final_path/data/config.ini.php"
2019-04-18 04:58:41 +02:00
# Load initial SQL into the new database
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/sql/webtrees.sql"
# Replace variables in sql scripts
ynh_replace_string --match_string="__USER_NAME__" --replace_string="$admin_username" --target_file="../conf/sql/admin.sql"
ynh_replace_string --match_string="__NAME__" --replace_string="$admin_name" --target_file="../conf/sql/admin.sql"
ynh_replace_string --match_string="__USER_EMAIL__" --replace_string="$admin_email" --target_file="../conf/sql/admin.sql"
ynh_replace_string --match_string="__PASSWORD__" --replace_string="$admin_password" --target_file="../conf/sql/admin.sql"
2019-04-18 04:58:41 +02:00
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/sql/admin.sql"
2017-07-01 19:54:37 +02:00
2018-09-01 18:12:10 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-03-11 13:47:37 +01:00
ynh_script_progression --message="Configuring permissions..."
2018-09-01 18:12:10 +02:00
# Make app public if necessary or protect it
2018-09-01 18:12:10 +02:00
if [ $is_public -eq 1 ]
then
2021-03-11 13:47:37 +01:00
ynh_permission_update --permission="main" --add="visitors"
2018-09-01 18:12:10 +02:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2020-10-16 11:21:00 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2018-09-01 18:12:10 +02:00
2020-07-30 18:54:44 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-09-01 18:12:10 +02:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2020-10-16 14:16:10 +02:00
message="Webtrees was successfully installed :)
2020-10-16 11:28:38 +02:00
2020-10-16 11:35:59 +02:00
Please open https://$domain$path_url
2020-10-16 11:28:38 +02:00
2020-10-16 11:35:13 +02:00
Your credentials for the admin panel are:
- admin username: $admin_username
- admin password: $password
2020-10-16 11:28:38 +02:00
2020-10-16 14:06:51 +02:00
If you facing an issue or want to improve Webtrees, please open a new issue in this project: https://github.com/YunoHost-Apps/webtrees_ynh"
2018-09-01 18:12:10 +02:00
ynh_send_readme_to_admin "$message"
2019-04-06 20:29:15 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"