2019-02-16 15:00:20 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2019-02-23 17:45:11 +01:00
|
|
|
path_url=/
|
2019-02-16 15:00:20 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2019-02-23 17:45:11 +01:00
|
|
|
is_public=1
|
2019-02-16 15:00:20 +01:00
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Validating installation parameters..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Storing installation settings..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app path $path_url
|
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2019-02-17 19:02:16 +01:00
|
|
|
ynh_app_setting_set $app password $password
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Find a free port
|
|
|
|
port=$(ynh_find_port 8080)
|
|
|
|
# Open this port
|
|
|
|
ynh_app_setting_set $app port $port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Creating a MySQL database..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
ynh_mysql_setup_db $db_name $db_name
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Setting up source files..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path" $architecture
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Configuring nginx web server..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Configuring system user..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Create config file..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
cp ../conf/config.yml "$final_path/config.yml"
|
2019-02-23 17:47:12 +01:00
|
|
|
ynh_replace_string "__APP__" $app "$final_path/config.yml"
|
2019-02-16 15:00:20 +01:00
|
|
|
ynh_replace_string "__PORT__" $port "$final_path/config.yml"
|
|
|
|
ynh_replace_string "__DBNAME__" $db_name "$final_path/config.yml"
|
|
|
|
ynh_replace_string "__DBPASS__" $db_pwd "$final_path/config.yml"
|
|
|
|
ynh_replace_string "__ADMINUSER__" $admin "$final_path/config.yml"
|
|
|
|
ynh_replace_string "__ADMINPASS__" $password "$final_path/config.yml"
|
|
|
|
ynh_replace_string "__DOMAIN__" $domain "$final_path/config.yml"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/config.yml"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R root: $final_path
|
|
|
|
mkdir $final_path/data
|
|
|
|
chown $app $final_path/data
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
yunohost service add $app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Configuring SSOwat..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2019-02-16 15:00:20 +01:00
|
|
|
|
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
systemctl start $app
|
2019-03-10 17:11:52 +01:00
|
|
|
ynh_print_info "Installation of $app completed"
|