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

191 lines
6.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
2020-07-30 18:54:44 +02:00
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
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=is_public --value=$is_public
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
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)
2020-10-16 11:21:00 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_name --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
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
2017-08-01 11:29:01 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-09-01 18:12:10 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Configuring system user..."
2017-07-01 19:54:37 +02:00
2018-09-01 18:12:10 +02:00
# Create a system user
2020-07-30 18:54:44 +02:00
ynh_system_user_create --username=$app
2017-07-01 19:54:37 +02:00
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
2020-10-16 11:21:00 +02:00
ynh_add_fpm_config --phpversion=$YNH_PHP_VERSION
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
ynh_replace_string "__dbuser__" "$db_name" "../conf/config.ini.php"
ynh_replace_string "__dbpass__" "$db_pwd" "../conf/config.ini.php"
ynh_replace_string "__dbname__" "$db_name" "../conf/config.ini.php"
# Copy the config file to the final path
2020-07-30 18:44:39 +02:00
cp ../conf/config.ini.php $final_path/data/.
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 "__USER_NAME__" "$admin_username" "../conf/sql/admin.sql"
ynh_replace_string "__NAME__" "$admin_name" "../conf/sql/admin.sql"
ynh_replace_string "__USER_EMAIL__" "$admin_email" "../conf/sql/admin.sql"
ynh_replace_string "__PASSWORD__" "$admin_password" "../conf/sql/admin.sql"
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/sql/admin.sql"
2017-07-01 19:54:37 +02:00
2019-04-06 20:29:15 +02:00
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Calculate and store the config file checksum into the app settings
2020-07-30 18:54:44 +02:00
ynh_store_file_checksum --file="$final_path/data/config.ini.php"
2019-04-06 20:29:15 +02:00
2019-04-18 04:59:41 +02:00
#=================================================
2019-04-18 05:00:01 +02:00
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
2019-04-18 04:59:41 +02:00
#=================================================
2020-07-30 18:54:44 +02:00
### For security reason, any app should set the permissions to root: before anything else.
### Then, if write authorization is needed, any access should be given only to directories
### that really need such authorization.
2019-04-18 05:00:01 +02:00
# Set permissions to app files
2019-04-18 04:59:41 +02:00
chown -R $app: $final_path
2020-07-30 18:44:39 +02:00
chmod -R 700 $final_path/data
2019-04-18 04:59:41 +02:00
2018-09-01 18:12:10 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-07-30 18:54:44 +02:00
ynh_script_progression --message="Configuring SSOwat..."
2018-09-01 18:12:10 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
2020-07-30 18:54:44 +02:00
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
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
#=================================================
2020-10-16 11:21:00 +02:00
ynh_script_progression --message="Installation of Webtrees completed"