Skip to content
Snippets Groups Projects
Commit b0af9722 authored by Bob Mottram's avatar Bob Mottram
Browse files

Integrate koel with syncthing

parent ac431a04
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,59 @@ koel_variables=(ONION_ONLY
MY_EMAIL_ADDRESS
MY_USERNAME)
function koel_upload_from_syncthing {
if [ ! -d /music ]; then
mkdir /music
fi
{ echo '#!/bin/bash';
echo '';
echo "syncdir=/home/$MY_USERNAME/Sync/music_upload";
echo '';
echo 'while true';
echo 'do';
echo " if [ -d \$syncdir ]; then";
echo " cd /home/$MY_USERNAME/Sync";
echo " if [ ! \"\$syncdir_base\" ]; then";
echo " syncdir_base=\$(ls -ld music_upload/*)";
echo ' fi';
echo '';
echo ' while read -r line; do';
echo " curr_dir=\$(echo \"\$line\" | awk -F '/' '{print \$2}')";
echo " if [ -d \$syncdir/\$curr_dir ]; then";
echo " if [ ! -d /music/\$curr_dir ]; then";
echo " mv \$syncdir/\$curr_dir /music";
echo ' fi';
echo ' fi';
echo " done <<< \"\$syncdir_base\"";
echo '';
echo " syncdir_base=\$(ls -ld music_upload/*)";
echo ' fi';
echo ' sleep 10';
echo 'done'; } > /usr/bin/koelsync
chmod +x /usr/bin/koelsync
if [ ! -f /etc/systemd/system/koel_syncthing.service ]; then
{ echo '[Unit]';
echo 'Description=Koel integration with syncthing';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=root';
echo "WorkingDirectory=/music";
echo "ExecStart=/usr/bin/koelsync";
echo 'Restart=on-failure';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/koel_syncthing.service
systemctl enable koel_syncthing.service
systemctl daemon-reload
fi
systemctl restart koel_syncthing.service
}
function koel_setting_upload {
music_file="$1"
......@@ -333,6 +386,8 @@ function configure_interactive_koel {
}
function upgrade_koel {
koel_upload_from_syncthing
if grep -q "koel domain" "$COMPLETION_FILE"; then
KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
fi
......@@ -478,6 +533,11 @@ function remove_koel {
if [ -f /etc/systemd/system/koel.service ]; then
rm /etc/systemd/system/koel.service
fi
if [ -f /etc/systemd/system/koel_syncthing.service ]; then
systemctl stop koel_syncthing
systemctl disable koel_syncthing
rm /etc/systemd/system/koel_syncthing.service
fi
systemctl daemon-reload
function_check remove_nodejs
......@@ -504,6 +564,10 @@ function remove_koel {
sed -i '/koel/d' "$COMPLETION_FILE"
remove_backup_database_local koel
if [ -f /usr/bin/koelsync ]; then
rm /usr/bin/koelsync
fi
function_check remove_ddns_domain
remove_ddns_domain "$KOEL_DOMAIN_NAME"
}
......@@ -800,6 +864,7 @@ function install_koel {
systemctl restart mariadb
systemctl restart nginx
koel_upload_from_syncthing
APP_INSTALLED=1
}
......
......@@ -923,6 +923,7 @@ function install_web_admin {
echo ' error_log /dev/null;';
echo '';
echo ' location ^~ /admin {';
echo ' client_max_body_size 200m;';
echo " ${basic_auth_str} \"${WEBADMIN_LOGIN_TEXT}\";";
echo " ${basic_auth_str}_user_file /etc/nginx/.webadminpasswd;";
echo " root /var/www/${local_hostname}/htdocs;";
......@@ -966,6 +967,7 @@ function install_web_admin {
{ echo ' add_header Strict-Transport-Security max-age=0;';
echo '';
echo ' location ^~ /admin {';
echo ' client_max_body_size 200m;';
echo " ${basic_auth_str} \"${WEBADMIN_LOGIN_TEXT}\";";
echo " ${basic_auth_str}_user_file /etc/nginx/.webadminpasswd;";
echo " root /var/www/${local_hostname}/htdocs;";
......@@ -1008,6 +1010,13 @@ function install_web_admin {
mkdir -p "/var/www/${local_hostname}/htdocs/plinth"
fi
if ! grep -q 'post_max_size = 200M' /etc/php/7.0/fpm/php.ini; then
sed -i 's|post_max_size.*|post_max_size = 200M|g' /etc/php/7.0/fpm/php.ini
fi
if ! grep -q 'upload_max_filesize = 200M' /etc/php/7.0/fpm/php.ini; then
sed -i 's|upload_max_filesize.*|upload_max_filesize = 200M|g' /etc/php/7.0/fpm/php.ini
fi
web_admin_create_users
# make list of apps which can be added
......
......@@ -93,8 +93,8 @@
<p class="settingtext">Upload a <b>zip</b> file containing your music</p>
<form action="settings_koel.php" method="post">
<input type="file" name="musicfile" accept=".zip">
<form action="settings_koel.php" method="post" enctype="multipart/form-data">
<input type="file" name="musicfile" id="musicfile" accept=".zip">
<br><br>
<input type="submit" name="submitcancel" value="Cancel" />
<input type="submit" name="submitmusic" value="Upload" />
......
<?php
// Koel settings menu
$output_filename = "app_koel.html";
if (isset($_POST['submitmusic'])) {
$musicfile = htmlspecialchars($_POST['musicfile']);
$target_dir = "uploads/";
$musicfile = $target_dir . basename($_FILES["musicfile"]["name"]);
if(file_exists($musicfile)) {
$settings_file = fopen(".appsettings.txt", "w") or die("Unable to write to appsettings file");
fwrite($settings_file, "koel,upload,".$musicfile);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment