mirror of
https://github.com/YunoHost-Apps/ampache_ynh.git
synced 2024-09-03 18:15:55 +02:00
66 lines
1.8 KiB
Bash
66 lines
1.8 KiB
Bash
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
# Retrieve arguments
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path=$YNH_APP_ARG_PATH
|
|
admin_ampache=$YNH_APP_ARG_ADMIN
|
|
|
|
# Source helpers
|
|
. /usr/share/yunohost/helpers
|
|
. _common
|
|
ynh_abort_if_errors
|
|
|
|
# Check if admin exists
|
|
sudo yunohost user list --json | grep -qi "\"username\": \"$admin_ampache\"" || ynh_die "wrong admin username"
|
|
|
|
ynh_app_setting_set $app admin $admin_ampache
|
|
|
|
# Check domain/path availability
|
|
path=$(ynh_normalize_url_path $path)
|
|
ynh_webpath_available $domain $path
|
|
ynh_webpath_register $app $domain $path
|
|
|
|
# get sources and copy files to the right place
|
|
ampache_ynh_getsources
|
|
|
|
sudo cp ../conf/admin.sql /tmp/
|
|
|
|
# Generate random password
|
|
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
# Initialize database and store mysql password for upgrade
|
|
ynh_app_setting_set $app mysqlpwd $db_pwd
|
|
ynh_mysql_setup_db "$app" "$app" "$db_pwd"
|
|
ynh_mysql_connect_as "$app" "$db_pwd" "$app" < "$final_path/sql/ampache.sql"
|
|
|
|
# Change variables in Ampache configuration
|
|
ampache_ynh_prepareconfig
|
|
|
|
sudo sed -i "s/yunoadmin/$admin_ampache/g" /tmp/admin.sql
|
|
random_key=db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
sudo sed -i "s@RANDOMKEYTOCHANGE@$random_key@g" $final_path/config/ampache.cfg.php
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
ampache_ynh_preparenginx
|
|
|
|
# Install dependency
|
|
sudo apt-get update
|
|
sudo apt-get install libav-tools -y
|
|
|
|
# Ampache installation
|
|
ampache_ynh_install
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
ampache_ynh_reloadservices
|
|
|
|
# Pre config ampache
|
|
ampache_ynh_doconfig
|
|
|
|
ynh_mysql_connect_as "$app" "$db_pwd" "$app" < /tmp/admin.sql
|
|
|
|
# Clean install
|
|
sudo rm -rf ../ampache-$version
|
|
sudo rm /tmp/admin.sql
|