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
|
2017-07-05 12:28:42 +02:00
|
|
|
|
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-05 12:28:42 +02:00
|
|
|
|
|
2017-07-01 19:54:37 +02:00
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
|
|
# 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
|
2017-07-01 22:59:17 +02:00
|
|
|
|
admin_password=$(openssl passwd -1 -salt xyz $YNH_APP_ARG_PASSWORD)
|
2017-08-01 11:33:39 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
# Normalize the url path syntax
|
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-07-05 12:28:42 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
# Check web path availability
|
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
|
# Register (book) web path
|
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-07-05 12:28:42 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
final_path=/var/www/$app
|
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Save app settings
|
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
2017-07-05 12:28:42 +02:00
|
|
|
|
ynh_app_setting_set $app domain $domain
|
2017-08-01 11:29:01 +02:00
|
|
|
|
ynh_app_setting_set $app path $path_url
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check password strength
|
|
|
|
|
[[ ${#admin_password} -gt 6 ]] || ynh_die \
|
|
|
|
|
"The password is too weak, it must be longer than 6 characters"
|
|
|
|
|
|
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
|
#=================================================
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02: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"
|
2017-07-01 19:54:37 +02:00
|
|
|
|
# Set permissions to app files
|
|
|
|
|
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
2017-07-05 12:28:42 +02:00
|
|
|
|
sudo chown -R root: $final_path
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
|
#=================================================
|
|
|
|
|
# If your app uses a MySQL database, you can use these lines to bootstrap
|
|
|
|
|
# a database, an associated user and save the password in app settings
|
|
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
|
ynh_mysql_setup_db $db_name $db_name
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
# Adding the details of the database to the config file
|
2017-08-01 11:29:01 +02:00
|
|
|
|
sed -i "s@__dbuser__@$db_name@g" ../conf/config.ini.php
|
|
|
|
|
sed -i "s@__dbpass__@$db_pwd@g" ../conf/config.ini.php
|
|
|
|
|
sed -i "s@__dbname__@$db_name@g" ../conf/config.ini.php
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
2017-07-05 12:28:42 +02:00
|
|
|
|
# Copy the config file to the final path
|
|
|
|
|
sudo cp ../conf/config.ini.php $final_path/data/.
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Load initial SQL into the new database
|
2017-08-01 11:29:01 +02:00
|
|
|
|
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/sql/webtrees.sql"
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "../conf/sql/admin.sql"
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
### MySQL end ###
|
|
|
|
|
|
2017-08-01 11:29:01 +02:00
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
|
if [[ $is_public -eq 1 ]]; then
|
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
|
|
|
|
fi
|
|
|
|
|
|
2017-07-05 12:28:42 +02:00
|
|
|
|
sudo chmod -R 777 $final_path/data
|
2017-07-01 19:54:37 +02:00
|
|
|
|
|
|
|
|
|
# Reload services
|
|
|
|
|
sudo service nginx reload
|