1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ampache_ynh.git synced 2024-09-03 18:15:55 +02:00
ampache_ynh/scripts/install
2019-02-11 20:23:11 +01:00

196 lines
5.7 KiB
Bash

#!/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
path_url=$YNH_APP_ARG_PATH
admin_ampache=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
final_path=/var/www/$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)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin_ampache
ynh_app_setting_set $app is_public $is_public
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies libav-tools php-cli
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
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
#=================================================
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"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE AMPACHE
#=================================================
conf_file="$final_path/config/ampache.cfg.php"
cp ../conf/ampache.cfg.php "$conf_file"
ynh_replace_string "__DBUSER__" "$db_name" "$conf_file"
ynh_replace_string "__DBPWD__" "$db_pwd" "$conf_file"
ynh_replace_string "__DBNAME__" "$db_name" "$conf_file"
ynh_replace_string "__PATHTOCHANGE__" "$path_url" "$conf_file"
ynh_replace_string "__DOMAINTOCHANGE__" "$domain" "$conf_file"
secret_key=$(ynh_string_random 24)
ynh_replace_string "__RANDOMKEYTOCHANGE__" "$secret_key" "$conf_file"
ynh_app_setting_set $app secret_key $secret_key
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$conf_file"
#=================================================
# LOAD DEFAULT DATABASE
#=================================================
# Load default ampache database
ynh_mysql_connect_as $app $db_pwd $app < "$final_path/sql/ampache.sql"
#=================================================
# INSTALL AMPACHE WITH COMPOSER
#=================================================
(
export COMPOSER_HOME=$final_path
cd $final_path
# Install composer
curl -sS https://getcomposer.org/installer \
| php -- --quiet --install-dir="$final_path" \
|| ynh_die "Unable to install Composer"
ynh_exec_warn_less php composer.phar install --prefer-source --no-interaction --no-dev
)
#=================================================
# INSTALL MULTIMEDIA DIRECTORIES
#=================================================
ynh_multimedia_build_main_dir
#=================================================
# PRE CONFIGURE AMPACHE
#=================================================
# Set the app as temporarily public for curl call
ynh_app_setting_set $app unprotected_uris "/"
# Reload SSOwat config
yunohost app ssowatconf
# Reload Nginx
systemctl reload nginx
ynh_local_curl /update.php?action=update
sleep 1
#=================================================
# LOAD ADMIN DATABASE
#=================================================
cp ../conf/admin.sql /tmp/
ynh_replace_string "__ADMIN__" "$admin_ampache" /tmp/admin.sql
ynh_mysql_connect_as "$app" "$db_pwd" "$app" < /tmp/admin.sql
ynh_secure_remove /tmp/admin.sql
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to ampache directory
chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# Keep app public if necessary
if [ $is_public -eq 0 ]
then
ynh_app_setting_delete $app unprotected_uris
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx