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

155 lines
5.1 KiB
Text
Raw Normal View History

2016-09-18 11:03:26 +02:00
#!/bin/bash
2018-05-05 17:03:04 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-09-18 11:03:26 +02:00
2018-05-05 17:03:04 +02:00
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2016-09-18 11:03:26 +02:00
domain=$YNH_APP_ARG_DOMAIN
2018-05-05 17:03:04 +02:00
path_url=$YNH_APP_ARG_PATH
2016-09-18 11:03:26 +02:00
password=$YNH_APP_ARG_PASSWORD
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-05-05 17:03:04 +02:00
app=$YNH_APP_INSTANCE_NAME
2016-09-18 11:03:26 +02:00
2018-05-05 17:03:04 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Validating installation parameters..."
2016-09-18 11:03:26 +02:00
2018-05-05 17:03:04 +02:00
final_path=/var/www/$app
2021-07-19 10:45:36 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2016-12-30 17:46:49 +01:00
2018-05-05 17:03:04 +02:00
# Register (book) web path
2021-07-19 10:45:36 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2016-12-30 17:46:49 +01:00
2018-05-05 17:03:04 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2021-07-19 10:45:36 +02:00
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=password --value=$password
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
2016-09-18 11:03:26 +02:00
2021-07-19 10:45:36 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-05-05 17:03:04 +02:00
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Creating a MySQL database..."
2019-03-04 23:51:16 +01:00
2021-07-19 10:45:36 +02:00
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_mysql_setup_db --db_user=$db_user --db_name=$db_name
2018-05-05 17:03:04 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Setting up source files..."
2018-05-05 17:03:04 +02:00
2021-07-19 10:45:36 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-05-05 17:03:04 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2021-07-19 10:45:36 +02:00
ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2018-05-05 17:03:04 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2018-05-05 17:03:04 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Configuring PHP-FPM..."
2018-05-05 17:03:04 +02:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
2016-09-18 11:03:26 +02:00
2018-05-05 17:03:04 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
2016-09-18 11:03:26 +02:00
# Add cron job
2018-05-05 17:03:04 +02:00
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Configuring a cron task..."
2018-05-20 19:38:56 +02:00
2021-07-19 10:45:36 +02:00
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
2018-05-20 19:38:56 +02:00
2018-05-05 17:03:04 +02:00
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
# Set right permissions for curl install
2021-07-19 10:45:36 +02:00
chown -R $app $final_path
2018-05-05 17:03:04 +02:00
# Set the app as temporarily public for curl call
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Configuring permissions..."
2021-07-19 09:44:10 +02:00
# Making the app public for curl
ynh_permission_update --permission="main" --add="visitors"
2018-05-05 17:03:04 +02:00
# Reload Nginx
systemctl reload nginx
2019-03-04 23:51:16 +01:00
# Installation with curl
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Finalizing installation..."
# Get database password
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_local_curl "/index.php?mod=install" "password=$password" "confirmPassword=$password" "type=db" "db[host]=localhost" "db[user]=$db_name" "db[password]=$db_pwd" "db[dbname]=$db_name"
2018-05-05 17:03:04 +02:00
# Remove the public access
2021-07-19 09:44:10 +02:00
ynh_permission_update --permission="main" --remove="visitors"
2018-05-05 17:03:04 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Configuring permissions..."
2018-05-05 17:03:04 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
2021-07-19 09:12:22 +02:00
ynh_permission_update --permission="main" --add="visitors"
2018-05-05 17:03:04 +02:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2018-05-05 17:03:04 +02:00
2021-07-19 10:45:36 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-03-04 23:51:16 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-07-19 10:45:36 +02:00
ynh_script_progression --message="Installation of $app completed"