#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Overload the helper ynh_handle_getopts_args to have fixes from unstable. # Needed for composer helpers source _getopts_fix.sh #================================================= # 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 #================================================= ynh_print_info "Validating installation parameters..." 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_print_info "Storing installation settings..." 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_print_info "Installing dependencies..." ynh_install_app_dependencies libav-tools php-cli #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_print_info "Creating 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_print_info "Setting up source files..." 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 #================================================= ynh_print_info "Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_print_info "Configuring php-fpm..." # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE AMPACHE #================================================= ynh_print_info "Preconfiguring 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 #================================================= ynh_print_info "Installing ampache with composer..." # Install composer ynh_install_composer ynh_exec_warn_less ynh_composer_exec --commands=\"install --prefer-source --no-dev\" #================================================= # INSTALL MULTIMEDIA DIRECTORIES #================================================= ynh_multimedia_build_main_dir #================================================= # PRE CONFIGURE AMPACHE #================================================= ynh_print_info "Configuring 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 #================================================= ynh_print_info "Configuring SSOwat..." # Keep app public if necessary if [ $is_public -eq 0 ] then ynh_app_setting_delete $app unprotected_uris fi #================================================= # RELOAD NGINX #================================================= ynh_print_info "Reloading nginx web server..." systemctl reload nginx #================================================= # END OF SCRIPT #================================================= ynh_print_info "Installation of $app completed"