freedomboneeee/src/freedombone-app-koel

775 lines
24 KiB
Plaintext
Raw Normal View History

2017-05-25 11:59:38 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2017-05-25 11:59:38 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2017-05-25 11:59:38 +02:00
#
# koel application
# https://gist.github.com/bplower/613a99156d603abac083
#
# License
# =======
#
2018-01-25 19:35:39 +01:00
# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
2017-05-25 11:59:38 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
VARIANTS='full full-vim media'
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
KOEL_DOMAIN_NAME=
KOEL_CODE=
KOEL_ONION_PORT=8118
2017-05-25 12:42:36 +02:00
KOEL_PORT=9002
2017-05-25 11:59:38 +02:00
KOEL_REPO="https://github.com/phanan/koel"
2018-01-21 12:50:49 +01:00
KOEL_COMMIT='8e9b021aa09f2b1460977bdd52fff14ea2bc1607'
2017-05-25 11:59:38 +02:00
KOEL_ADMIN_PASSWORD=
2018-05-28 15:47:12 +02:00
KOEL_SHORT_DESCRIPTION=$'Music player'
KOEL_DESCRIPTION=$'Music player'
KOEL_MOBILE_APP_URL=
2017-05-25 11:59:38 +02:00
koel_variables=(ONION_ONLY
KOEL_DOMAIN_NAME
KOEL_CODE
DDNS_PROVIDER
MY_EMAIL_ADDRESS
MY_USERNAME)
function logging_on_koel {
echo -n ''
}
function logging_off_koel {
echo -n ''
}
2017-05-26 00:52:55 +02:00
function koel_remove_gravatar {
2018-02-27 15:11:56 +01:00
cd "/var/www/${KOEL_DOMAIN_NAME}/htdocs" || exit 8345374534
2017-05-26 00:53:59 +02:00
sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" node_modules/browser-sync-ui/public/js/app.js.map
sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" public/js/app.*.js
2017-05-26 00:52:55 +02:00
if ! grep -q "//Vue.set(user, 'avatar'" resources/assets/js/stores/user.js; then
sed -i "s|Vue.set(user, 'avatar'|//Vue.set(user, 'avatar'|g" resources/assets/js/stores/user.js
fi
}
2017-05-25 11:59:38 +02:00
function remove_user_koel {
remove_username="$1"
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$remove_username" --rmapp koel
2017-05-25 11:59:38 +02:00
}
function add_user_koel {
new_username="$1"
new_user_password="$2"
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$new_username" -a koel -p "$new_user_password"
2017-05-25 11:59:38 +02:00
echo '0'
}
function install_interactive_koel {
2018-02-27 15:11:56 +01:00
if [ ! "$ONION_ONLY" ]; then
2017-05-25 11:59:38 +02:00
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
KOEL_DOMAIN_NAME='koel.local'
else
KOEL_DETAILS_COMPLETE=
while [ ! $KOEL_DETAILS_COMPLETE ]
do
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
2018-05-12 18:48:20 +02:00
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
2017-05-25 11:59:38 +02:00
dialog --backtitle $"Freedombone Configuration" \
--title $"Koel Configuration" \
2018-02-27 15:11:56 +01:00
--form $"\\nPlease enter your Koel details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
2017-05-25 11:59:38 +02:00
$"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
$"Code:" 2 1 "$(grep 'KOEL_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
2018-02-27 15:11:56 +01:00
2> "$data"
2017-05-25 11:59:38 +02:00
else
dialog --backtitle $"Freedombone Configuration" \
--title $"Koel Configuration" \
2018-02-27 15:11:56 +01:00
--form $"\\nPlease enter your Koel details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
2017-05-25 11:59:38 +02:00
$"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
2018-02-27 15:11:56 +01:00
2> "$data"
2017-05-25 11:59:38 +02:00
fi
sel=$?
case $sel in
2018-02-27 15:11:56 +01:00
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
2017-05-25 11:59:38 +02:00
esac
2018-02-27 15:11:56 +01:00
KOEL_DOMAIN_NAME=$(sed -n 1p < "$data")
if [ "$KOEL_DOMAIN_NAME" ]; then
if [[ "$KOEL_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=""
fi
TEST_DOMAIN_NAME=$KOEL_DOMAIN_NAME
validate_domain_name
2018-02-27 15:11:56 +01:00
if [[ "$TEST_DOMAIN_NAME" != "$KOEL_DOMAIN_NAME" ]]; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
2018-05-12 18:48:20 +02:00
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
2018-02-27 15:11:56 +01:00
KOEL_CODE=$(sed -n 2p < "$data")
2017-05-25 11:59:38 +02:00
validate_freedns_code "$KOEL_CODE"
2018-02-27 15:11:56 +01:00
if [ ! "$VALID_CODE" ]; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=
fi
fi
fi
fi
if [ $KOEL_DOMAIN_NAME ]; then
KOEL_DETAILS_COMPLETE="yes"
fi
2018-02-27 15:11:56 +01:00
rm -f "$data"
2017-05-25 11:59:38 +02:00
done
# save the results in the config file
write_config_param "KOEL_CODE" "$KOEL_CODE"
fi
write_config_param "KOEL_DOMAIN_NAME" "$KOEL_DOMAIN_NAME"
APP_INSTALLED=1
}
function change_password_koel {
curr_username="$1"
new_user_password="$2"
read_config_param 'KOEL_DOMAIN_NAME'
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$curr_username" -a koel -p "$new_user_password"
2017-05-25 11:59:38 +02:00
}
function koel_create_database {
2018-02-27 15:11:56 +01:00
if [ -f "$IMAGE_PASSWORD_FILE" ]; then
KOEL_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
2017-05-25 11:59:38 +02:00
else
2018-02-27 15:11:56 +01:00
if [ ! "$KOEL_ADMIN_PASSWORD" ]; then
KOEL_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
2017-05-25 11:59:38 +02:00
fi
fi
2018-02-27 15:11:56 +01:00
if [ ! "$KOEL_ADMIN_PASSWORD" ]; then
2017-05-25 11:59:38 +02:00
return
fi
function_check create_database
2018-02-27 15:11:56 +01:00
create_database koel "$KOEL_ADMIN_PASSWORD" "$MY_USERNAME"
2017-05-25 11:59:38 +02:00
}
function reconfigure_koel {
echo -n ''
}
2017-05-25 21:53:43 +02:00
function koel_import_from_directory {
2018-04-07 15:15:53 +02:00
read_config_param MY_USERNAME
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
dialog --title "Choose a directory containing music" --dselect "/home/$MY_USERNAME/" 30 60 2> "$data"
selected_dir=$(cat "$data")
rm -f "$data"
2017-05-25 21:53:43 +02:00
if [[ "$selected_dir" == '/music' ]]; then
return
fi
2018-02-27 15:11:56 +01:00
if [ ! -d "$selected_dir" ]; then
2017-05-25 21:53:43 +02:00
return
fi
if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
return
fi
if [[ "$selected_dir" == "/home/$MY_USERNAME/."* ]]; then
return
fi
if [[ "$selected_dir" == *"/Maildir" || "$selected_dir" == *"/Sync" ]]; then
return
fi
dialog --title $"Import music directory" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-02-27 15:11:56 +01:00
--yesno $"\\nImport the directory:\\n\\n $selected_dir" 12 75
2017-05-25 21:53:43 +02:00
sel=$?
case $sel in
1) return;;
255) return;;
esac
# shellcheck disable=SC2086
mv $selected_dir /music
2017-05-25 21:53:43 +02:00
dialog --title $"Import music directory" \
--msgbox $"Import success. You may need to re-sync within Koel." 6 40
}
function koel_import_from_usb {
2017-05-25 22:35:51 +02:00
clear
detect_usb_drive
2018-02-27 15:11:56 +01:00
if [ ! -b "$USB_DRIVE" ]; then
2017-05-25 22:35:51 +02:00
dialog --title $"Import music from USB drive" --msgbox $'No USB drive found' 6 50
return
fi
2018-02-27 15:11:56 +01:00
backup_mount_drive "${USB_DRIVE}"
if [ ! -d "$USB_MOUNT/Music" ]; then
2017-05-25 22:35:51 +02:00
dialog --title $"Import music from USB drive" --msgbox $'No Music directory found on USB drive' 6 50
2018-02-27 15:11:56 +01:00
backup_unmount_drive "${USB_DRIVE}"
2017-05-25 22:35:51 +02:00
fi
2018-03-03 12:49:17 +01:00
cp -ru "$USB_MOUNT/Music/"* /music
2018-02-27 15:11:56 +01:00
backup_unmount_drive "${USB_DRIVE}"
2017-05-25 22:35:51 +02:00
dialog --title $"Import music from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
2017-05-25 11:59:38 +02:00
}
2017-05-25 22:45:01 +02:00
function koel_export_to_usb {
clear
detect_usb_drive
2018-02-27 15:11:56 +01:00
if [ ! -b "$USB_DRIVE" ]; then
2017-05-25 22:45:01 +02:00
dialog --title $"Export music to USB drive" --msgbox $'No USB drive found' 6 50
return
fi
2018-02-27 15:11:56 +01:00
backup_mount_drive "${USB_DRIVE}"
if [ ! -d "$USB_MOUNT/Music" ]; then
mkdir -p "$USB_MOUNT/Music"
2017-05-25 22:45:01 +02:00
fi
2018-02-27 15:11:56 +01:00
cp -ru /music/* "$USB_MOUNT/Music"
backup_unmount_drive "${USB_DRIVE}"
2017-05-25 22:45:01 +02:00
dialog --title $"Export music to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
}
function format_music_drive {
detect_usb_drive
dialog --title $"Format USB drive $USB_DRIVE for music storage" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-02-27 15:11:56 +01:00
--yesno $"\\nPlease confirm that you wish to format drive\\n\\n ${USB_DRIVE}\\n\\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\\n\\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
clear
echo ''
echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
echo ''
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-format" "$USB_DRIVE"
dialog --title $"Format USB drive $USB_DRIVE for music storage" --msgbox $'Format complete. You may now export music or remove the USB drive' 6 50
}
2017-05-25 21:53:43 +02:00
function configure_interactive_koel {
2018-04-04 13:50:32 +02:00
W=(1 $"Import music from directory"
2 $"Import music from USB drive"
3 $"Export music to USB drive"
4 $"Format a USB drive for music storage")
2017-05-25 21:53:43 +02:00
while true
do
2018-04-04 13:50:32 +02:00
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Koel" --menu $"Choose an operation, or ESC to exit:" 12 60 4 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
2017-05-25 21:53:43 +02:00
1) koel_import_from_directory;;
2) koel_import_from_usb;;
2017-05-25 22:45:01 +02:00
3) koel_export_to_usb;;
4) format_music_drive;;
2017-05-25 21:53:43 +02:00
esac
done
}
2017-05-25 11:59:38 +02:00
function upgrade_koel {
2018-02-27 15:11:56 +01:00
if grep -q "koel domain" "$COMPLETION_FILE"; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
fi
2017-05-26 11:03:28 +02:00
CURR_KOEL_COMMIT=$(get_completion_param "koel commit")
if [[ "$CURR_KOEL_COMMIT" == "$KOEL_COMMIT" ]]; then
return
fi
2017-05-25 19:51:26 +02:00
systemctl stop koel
2017-05-25 11:59:38 +02:00
# update to the next commit
function_check set_repo_commit
2018-02-27 15:11:56 +01:00
set_repo_commit "/var/www/$KOEL_DOMAIN_NAME/htdocs" "koel commit" "$KOEL_COMMIT" $KOEL_REPO
2017-05-25 11:59:38 +02:00
2018-02-27 15:11:56 +01:00
cd "/var/www/${KOEL_DOMAIN_NAME}/htdocs" || exit 7345346358
2017-05-25 19:51:26 +02:00
php artisan koel:init
2017-05-26 00:52:55 +02:00
koel_remove_gravatar
2018-03-03 12:49:17 +01:00
chown -R www-data:www-data "/var/www/${KOEL_DOMAIN_NAME}/htdocs/"*
2017-05-25 19:51:26 +02:00
systemctl start koel
2017-05-25 11:59:38 +02:00
}
function backup_local_koel {
KOEL_DOMAIN_NAME='koel'
2018-02-27 15:11:56 +01:00
if grep -q "koel domain" "$COMPLETION_FILE"; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
fi
2018-02-27 15:11:56 +01:00
source_directory="/var/www/${KOEL_DOMAIN_NAME}/htdocs"
if [ -d "$source_directory" ]; then
2017-06-25 21:44:00 +02:00
systemctl stop koel
2017-05-26 15:26:27 +02:00
2017-05-25 11:59:38 +02:00
dest_directory=koel
function_check suspend_site
2018-02-27 15:11:56 +01:00
suspend_site "${KOEL_DOMAIN_NAME}"
2017-05-25 11:59:38 +02:00
function_check backup_directory_to_usb
2018-02-27 15:11:56 +01:00
backup_directory_to_usb "$source_directory" "$dest_directory"
2017-05-25 11:59:38 +02:00
function_check backup_database_to_usb
backup_database_to_usb koel
function_check restart_site
restart_site
2017-05-26 15:26:27 +02:00
2017-06-25 21:44:00 +02:00
systemctl start koel
2017-05-25 11:59:38 +02:00
fi
}
function restore_local_koel {
2018-02-27 15:11:56 +01:00
if ! grep -q "koel domain" "$COMPLETION_FILE"; then
2017-05-25 11:59:38 +02:00
return
fi
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
2018-02-27 15:11:56 +01:00
if [ "$KOEL_DOMAIN_NAME" ]; then
2017-05-25 11:59:38 +02:00
echo $"Restoring koel"
2017-06-25 21:44:00 +02:00
systemctl stop koel
2017-05-26 15:26:27 +02:00
2017-05-25 11:59:38 +02:00
temp_restore_dir=/root/tempkoel
function_check koel_create_database
koel_create_database
2018-02-27 15:11:56 +01:00
restore_database koel "${KOEL_DOMAIN_NAME}"
2017-05-25 11:59:38 +02:00
if [ -d $temp_restore_dir ]; then
rm -rf $temp_restore_dir
fi
2017-06-25 21:44:00 +02:00
2018-02-27 15:11:56 +01:00
MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 274825424
2017-06-25 21:44:00 +02:00
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
MARIADB_PASSWORD=
systemctl start koel
2017-05-25 11:59:38 +02:00
fi
}
function backup_remote_koel {
2018-02-27 15:11:56 +01:00
if grep -q "koel domain" "$COMPLETION_FILE"; then
2017-05-25 11:59:38 +02:00
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
temp_backup_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
2018-02-27 15:11:56 +01:00
if [ -d "$temp_backup_dir" ]; then
2017-06-25 21:44:00 +02:00
systemctl stop koel
2017-05-26 15:26:27 +02:00
2017-05-25 11:59:38 +02:00
function_check suspend_site
2018-02-27 15:11:56 +01:00
suspend_site "${KOEL_DOMAIN_NAME}"
2017-05-25 11:59:38 +02:00
function_check backup_database_to_friend
backup_database_to_friend koel
echo $"Backing up Koel installation"
function_check backup_directory_to_friend
2018-02-27 15:11:56 +01:00
backup_directory_to_friend "$temp_backup_dir" koel
2017-05-25 11:59:38 +02:00
function_check restart_site
restart_site
2017-05-26 15:26:27 +02:00
2017-06-25 21:44:00 +02:00
systemctl start koel
2017-05-25 11:59:38 +02:00
else
echo $"koel domain specified but not found in ${temp_backup_dir}"
fi
fi
}
function restore_remote_koel {
2018-02-27 15:11:56 +01:00
if grep -q "koel domain" "$COMPLETION_FILE"; then
2017-05-25 11:59:38 +02:00
echo $"Restoring koel"
2017-06-25 21:44:00 +02:00
systemctl stop koel
2017-05-26 15:26:27 +02:00
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
2017-05-25 11:59:38 +02:00
function_check koel_create_database
koel_create_database
function_check restore_database_from_friend
2018-02-27 15:11:56 +01:00
restore_database_from_friend koel "${KOEL_DOMAIN_NAME}"
2017-05-25 11:59:38 +02:00
if [ -d /root/tempkoel ]; then
rm -rf /root/tempkoel
fi
2018-02-27 15:11:56 +01:00
MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 53743682
2017-06-25 21:44:00 +02:00
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
MARIADB_PASSWORD=
systemctl start koel
2017-05-26 15:26:27 +02:00
2017-05-25 11:59:38 +02:00
echo $"Restore of koel complete"
fi
}
function remove_koel {
if [ ${#KOEL_DOMAIN_NAME} -eq 0 ]; then
return
fi
2017-05-25 12:41:29 +02:00
systemctl stop koel
systemctl disable koel
if [ -f /etc/systemd/system/koel.service ]; then
rm /etc/systemd/system/koel.service
fi
2017-06-10 22:37:50 +02:00
systemctl daemon-reload
2017-05-25 12:41:29 +02:00
2017-05-25 11:59:38 +02:00
function_check remove_nodejs
remove_nodejs koel
read_config_param "KOEL_DOMAIN_NAME"
read_config_param "MY_USERNAME"
echo "Removing $KOEL_DOMAIN_NAME"
2018-02-27 15:11:56 +01:00
nginx_dissite "$KOEL_DOMAIN_NAME"
remove_certs "$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
2018-02-27 15:11:56 +01:00
if [ -d "/var/www/$KOEL_DOMAIN_NAME" ]; then
rm -rf "/var/www/$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
fi
2018-02-27 15:11:56 +01:00
if [ -f "/etc/nginx/sites-available/$KOEL_DOMAIN_NAME" ]; then
rm "/etc/nginx/sites-available/$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
fi
function_check drop_database
drop_database koel
function_check remove_onion_service
remove_onion_service koel ${KOEL_ONION_PORT}
remove_app koel
remove_completion_param install_koel
2018-02-27 15:11:56 +01:00
sed -i '/koel/d' "$COMPLETION_FILE"
2017-05-25 11:59:38 +02:00
remove_backup_database_local koel
function_check remove_ddns_domain
2018-02-27 15:11:56 +01:00
remove_ddns_domain "$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
}
function install_koel_main {
2018-02-27 15:11:56 +01:00
if [ ! "$KOEL_DOMAIN_NAME" ]; then
2017-05-25 11:59:38 +02:00
echo $'No domain name was given for koel'
exit 7359
fi
if [[ $(app_is_installed koel_main) == "1" ]]; then
return
fi
function_check install_mariadb
install_mariadb
function_check get_mariadb_password
get_mariadb_password
function_check repair_databases_script
repair_databases_script
2017-06-18 11:59:12 +02:00
apt-get -yq install php-gettext php-curl php-gd php-mysql git curl php-zip
2017-06-03 18:42:22 +02:00
apt-get -yq install php-memcached php-intl exiftool libfcgi0ldbl
2017-07-04 12:16:51 +02:00
apt-get -yq install ffmpeg
2017-05-25 11:59:38 +02:00
2018-02-27 15:11:56 +01:00
if [ ! -d "/var/www/$KOEL_DOMAIN_NAME" ]; then
mkdir "/var/www/$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
fi
2018-02-27 15:11:56 +01:00
if [ ! -d "/var/www/$KOEL_DOMAIN_NAME/htdocs" ]; then
2017-06-15 13:33:16 +02:00
if [ -d /repos/koel ]; then
2018-02-27 15:11:56 +01:00
mkdir "/var/www/$KOEL_DOMAIN_NAME/htdocs"
cp -r -p /repos/koel/. "/var/www/$KOEL_DOMAIN_NAME/htdocs"
cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 23924295
2017-06-15 13:33:16 +02:00
git pull
else
function_check git_clone
2018-02-27 15:11:56 +01:00
git_clone "$KOEL_REPO" "/var/www/$KOEL_DOMAIN_NAME/htdocs"
2017-06-15 13:33:16 +02:00
fi
2018-02-27 15:11:56 +01:00
if [ ! -d "/var/www/$KOEL_DOMAIN_NAME/htdocs" ]; then
2017-05-25 11:59:38 +02:00
echo $'Unable to clone koel repo'
exit 365735
fi
fi
2018-02-27 15:11:56 +01:00
cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 834567242
git checkout "$KOEL_COMMIT" -b "$KOEL_COMMIT"
2017-05-25 11:59:38 +02:00
set_completion_param "koel commit" "$KOEL_COMMIT"
2018-02-27 15:11:56 +01:00
chown -R www-data:www-data "/var/www/$KOEL_DOMAIN_NAME/htdocs"
2017-05-25 11:59:38 +02:00
function_check koel_create_database
koel_create_database
function_check add_ddns_domain
2018-02-27 15:11:56 +01:00
add_ddns_domain "$KOEL_DOMAIN_NAME"
KOEL_ONION_HOSTNAME=$(add_onion_service koel 80 ${KOEL_ONION_PORT})
2017-05-25 11:59:38 +02:00
koel_nginx_site=/etc/nginx/sites-available/$KOEL_DOMAIN_NAME
if [[ $ONION_ONLY == "no" ]]; then
function_check nginx_http_redirect
2018-02-27 15:11:56 +01:00
nginx_http_redirect "$KOEL_DOMAIN_NAME" "index index.php"
{ echo 'server {';
echo ' listen 443 ssl;';
echo ' #listen [::]:443 ssl;';
echo " server_name $KOEL_DOMAIN_NAME;";
echo ''; } >> "$koel_nginx_site"
2017-05-25 11:59:38 +02:00
function_check nginx_compress
2018-02-27 15:11:56 +01:00
nginx_compress "$KOEL_DOMAIN_NAME"
{ echo ' gzip_comp_level 9;';
echo '';
echo ' # Security'; } >> "$koel_nginx_site"
2017-05-25 18:30:30 +02:00
function_check nginx_ssl mobile
2018-02-27 15:11:56 +01:00
nginx_ssl "$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
2018-03-05 19:15:29 +01:00
function_check nginx_security_options
nginx_security_options "$KOEL_DOMAIN_NAME"
2018-02-27 15:11:56 +01:00
{ echo ' add_header Strict-Transport-Security max-age=15768000;';
echo '';
echo ' # Logs';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' # Root';
echo " root /var/www/$KOEL_DOMAIN_NAME/htdocs;";
echo '';
echo ' # Index';
echo ' index index.php;';
echo '';
echo ' # Whitelist only index.php, robots.txt, and those start with public/ or api/';
echo " if (\$request_uri !~ ^/\$|index\\.php|robots\\.txt|api/|public/) {";
echo ' return 404;';
echo ' }';
echo '';
echo ' location /media/ {';
echo ' internal;';
echo '';
echo ' # A X-Media-Root should be set to media_path settings from upstream';
echo " alias \$upstream_http_x_media_root;";
echo '';
echo ' }';
echo '';
echo ' # PHP';
echo ' location ~ \.php {';
echo ' include snippets/fastcgi-php.conf;';
echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
echo ' fastcgi_read_timeout 30;';
echo ' }';
echo '';
echo ' # Location';
echo ' location / {'; } >> "$koel_nginx_site"
2017-05-25 11:59:38 +02:00
function_check nginx_limits
2018-02-27 15:11:56 +01:00
nginx_limits "$KOEL_DOMAIN_NAME" '15m'
{ echo " try_files \$uri \$uri/ @koel;";
echo ' }';
echo '';
echo ' # Fancy URLs';
echo ' location @koel {';
echo " rewrite ^(.*)\$ /index.php?p=\$1 last;";
echo ' }';
echo '';
echo ' # Restrict access that is unnecessary anyway';
echo ' location ~ /\.(ht|git) {';
echo ' deny all;';
echo ' }';
echo '';
echo '}'; } >> "$koel_nginx_site"
else
echo -n '' > "$koel_nginx_site"
fi
if [[ "$ONION_ONLY" == 'no' ]]; then
{ echo 'server {';
echo " listen 127.0.0.1:$KOEL_ONION_PORT default_server;";
echo " server_name $KOEL_DOMAIN_NAME;";
echo ''; } >> "$koel_nginx_site"
2017-05-25 11:59:38 +02:00
else
2018-02-27 15:11:56 +01:00
{ echo 'server {';
echo " listen 127.0.0.1:$KOEL_ONION_PORT default_server;";
echo " server_name $KOEL_ONION_HOSTNAME;";
echo ''; } >> "$koel_nginx_site"
2017-05-25 11:59:38 +02:00
fi
function_check nginx_compress
2018-02-27 15:11:56 +01:00
nginx_compress "$KOEL_DOMAIN_NAME"
{ echo ' gzip_comp_level 9;';
echo '';
echo ' # Logs';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' # Root';
echo " root /var/www/$KOEL_DOMAIN_NAME/htdocs;";
echo '';
echo ' # Index';
echo ' index index.php;';
echo '';
echo ' # Whitelist only index.php, robots.txt, and those start with public/ or api/';
echo " if (\$request_uri !~ ^/\$|index\\.php|robots\\.txt|api/|public/) {";
echo ' return 404;';
echo ' }';
echo '';
echo ' location /media/ {';
echo ' internal;';
echo '';
echo ' # A X-Media-Root should be set to media_path settings from upstream';
echo " alias \$upstream_http_x_media_root;";
echo '';
echo ' }';
echo '';
echo ' # PHP';
echo ' location ~ \.php {';
echo ' include snippets/fastcgi-php.conf;';
echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
echo ' fastcgi_read_timeout 30;';
echo ' }';
echo '';
echo ' # Location';
echo ' location / {'; } >> "$koel_nginx_site"
2017-05-25 11:59:38 +02:00
function_check nginx_limits
2018-02-27 15:11:56 +01:00
nginx_limits "$KOEL_DOMAIN_NAME" '15m'
{ echo " try_files \$uri \$uri/ @koel;";
echo ' }';
echo '';
echo ' # Fancy URLs';
echo ' location @koel {';
echo " rewrite ^(.*)\$ /index.php?p=\$1 last;";
echo ' }';
echo '';
echo ' # Restrict access that is unnecessary anyway';
echo ' location ~ /\.(ht|git) {';
echo ' deny all;';
echo ' }';
echo '';
echo '}'; } >> "$koel_nginx_site"
sed -i 's|gzip_types.*|gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;|g' "$koel_nginx_site"
sed -i 's|DENY;|SAMEORIGIN;|g' "$koel_nginx_site"
2017-05-25 13:31:04 +02:00
2017-05-25 11:59:38 +02:00
function_check configure_php
configure_php
function_check create_site_certificate
2018-02-27 15:11:56 +01:00
create_site_certificate "$KOEL_DOMAIN_NAME" 'yes'
2017-05-25 11:59:38 +02:00
# Ensure that the database gets backed up locally, if remote
# backups are not being used
function_check backup_databases_script_header
backup_databases_script_header
function_check backup_database_local
backup_database_local koel
function_check nginx_ensite
2018-02-27 15:11:56 +01:00
nginx_ensite "$KOEL_DOMAIN_NAME"
2017-05-25 11:59:38 +02:00
2017-06-06 15:26:57 +02:00
systemctl restart mariadb
2017-06-01 20:05:15 +02:00
systemctl restart php7.0-fpm
2017-05-25 11:59:38 +02:00
systemctl restart nginx
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a koel -p "$KOEL_ADMIN_PASSWORD"
2017-05-25 11:59:38 +02:00
set_completion_param "koel domain" "$KOEL_DOMAIN_NAME"
install_completed koel_main
}
function install_koel {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
function_check install_nodejs
install_nodejs koel
install_koel_main
2018-02-27 15:11:56 +01:00
cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 2432848
2017-07-25 23:11:03 +02:00
install_composer
2017-05-25 11:59:38 +02:00
2017-06-08 18:18:50 +02:00
npm install -g yarn
npm install
2017-05-25 11:59:38 +02:00
2017-05-25 19:18:28 +02:00
function_check get_mariadb_password
get_mariadb_password
2017-05-25 11:59:38 +02:00
cp .env.example .env
sed -i "s/ADMIN_EMAIL=.*/ADMIN_EMAIL=$MY_EMAIL_ADDRESS/g" .env
sed -i "s/ADMIN_NAME=.*/ADMIN_NAME=$MY_USERNAME/g" .env
sed -i "s/ADMIN_PASSWORD=.*/ADMIN_PASSWORD=$KOEL_ADMIN_PASSWORD/g" .env
sed -i 's/DB_CONNECTION=.*/DB_CONNECTION=mysql/g' .env
sed -i 's/DB_HOST=.*/DB_HOST=127.0.0.1/g' .env
sed -i 's/DB_DATABASE=.*/DB_DATABASE=koel/g' .env
sed -i 's/DB_USERNAME=.*/DB_USERNAME=root/g' .env
2017-05-25 19:20:01 +02:00
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
2017-05-25 13:22:18 +02:00
sed -i 's/MAIL_HOST=.*/MAIL_HOST=localhost/g' .env
sed -i 's/MAIL_PORT=.*/MAIL_PORT=25/g' .env
2017-07-04 12:16:51 +02:00
sed -i 's|FFMPEG_PATH=.*|FFMPEG_PATH=/usr/bin/ffmpeg|g' .env
2017-05-25 11:59:38 +02:00
2018-02-27 15:11:56 +01:00
if ! php artisan koel:init; then
2017-06-08 18:18:50 +02:00
echo $"Can't install koel:init"
exit 78362
fi
2017-05-26 00:52:55 +02:00
koel_remove_gravatar
2018-02-27 15:11:56 +01:00
chown -R www-data:www-data "/var/www/$KOEL_DOMAIN_NAME/htdocs"
2017-05-25 12:41:29 +02:00
# daemon
2018-02-27 15:11:56 +01:00
{ echo '[Unit]';
echo 'Description=Koel (music player)';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=www-data';
echo 'Group=www-data';
echo "WorkingDirectory=/var/www/$KOEL_DOMAIN_NAME/htdocs";
echo "ExecStart=/usr/bin/php artisan serve --port=$KOEL_PORT";
echo 'Restart=on-failure';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/koel.service
2017-05-25 12:41:29 +02:00
systemctl enable koel.service
systemctl daemon-reload
systemctl start koel.service
2017-05-25 17:17:35 +02:00
if [ ! -d /music ]; then
mkdir /music
fi
chown -R www-data:www-data /music
2017-06-06 15:26:57 +02:00
systemctl restart mariadb
2017-05-25 11:59:38 +02:00
systemctl restart nginx
APP_INSTALLED=1
}
# NOTE: deliberately there is no "exit 0"