From 0135bf40e267f08f33e6d0538fccc14f4b228f0a Mon Sep 17 00:00:00 2001 From: Pecusx Date: Sun, 20 May 2018 16:54:49 +0200 Subject: [PATCH] Backup and Restore station list added to webinterface. --- hardware/audio/mpd.conf | 2 +- html/config.php | 4 +- html/s_stlist.php | 82 ++++++++++++++++++++++++++++++++ html/scripts/make_stlist_file.sh | 23 +++++++++ html/scripts/restore_stlist.sh | 29 +++++++++++ version | 2 +- 6 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 html/s_stlist.php create mode 100644 html/scripts/make_stlist_file.sh create mode 100644 html/scripts/restore_stlist.sh diff --git a/hardware/audio/mpd.conf b/hardware/audio/mpd.conf index aa2e760..f2b2b24 100644 --- a/hardware/audio/mpd.conf +++ b/hardware/audio/mpd.conf @@ -48,7 +48,7 @@ input { audio_output { type "alsa" name "Main Alsa" - format "41000:16:2" + format "44100:16:2" device "hw:0,0" # optional # mixer_type "software" # optional # mixer_device "default" # optional diff --git a/html/config.php b/html/config.php index 3091c82..2e09be9 100755 --- a/html/config.php +++ b/html/config.php @@ -180,8 +180,8 @@ echo $stations; echo ''; ?>
- - + +
diff --git a/html/s_stlist.php b/html/s_stlist.php new file mode 100644 index 0000000..8b41980 --- /dev/null +++ b/html/s_stlist.php @@ -0,0 +1,82 @@ + + + + + + + PiRadio mini web interface - station list backup and restore + + +PiRadio
config

+
+ 0) + { + echo "Error: " . $_FILES["file"]["error"] . "
"; + } else { + echo "File: "; + echo $_FILES["file"]["name"] ; + echo " loaded.
\r\n"; + move_uploaded_file($_FILES["file"]["tmp_name"], "/tmp/piradio.stl"); + $tablica = explode('.', $_FILES["file"]["name"]); + $ostatni = count($tablica); + if($tablica[$ostatni-1] == 'stl') { + $end = shell_exec('sudo ./scripts/restore_stlist.sh unpack'); + if (file_exists("/tmp/radiod/config/version")) { + echo "Setting new station list.
\r\n"; + $end = shell_exec('sudo ./scripts/restore_stlist.sh apply'); + echo "O.K.
\r\n"; + $end = shell_exec('sudo ./scripts/restart.sh'); + /* UWAGA! Folder z plikami uruchamianymi przez sudo + musi byc dopisany w pliku /etc/sudoers */ + echo "PiRadio restart in progress.
\r\n"; + echo "Wait!
\r\n"; + echo "\r\n"; + } else { + echo "This is not PiRadio station list file!!!
\r\n"; + echo "\r\n"; + } + } else { + unlink("/tmp/piradio.stl"); + echo "This is wrong file!
\r\n"; + echo "\r\n"; + } + } +} else { + $end = shell_exec('sudo ./scripts/make_stlist_file.sh'); + echo "Backup PiRadio station list
\r\n"; + echo "
\r\nClick the 'Backup' button to download station list backup file to your computer.\r\n
\r\n"; + echo ''; + echo "
\r\n"; + echo "Restore PiRadio station list
\r\n"; + echo "
After restoringing PiRadio will be restarted!
\r\n"; + echo "
\r\n"; + echo "
\r\n"; + echo " \r\n"; + echo "
\r\n"; + echo " \r\n"; + echo "
\r\n"; +} +?> +
+ + + + \ No newline at end of file diff --git a/html/scripts/make_stlist_file.sh b/html/scripts/make_stlist_file.sh new file mode 100644 index 0000000..ee96b03 --- /dev/null +++ b/html/scripts/make_stlist_file.sh @@ -0,0 +1,23 @@ +# Backup current station list to file + +# prepare temp folder +rm -r /tmp/radiod/config +mkdir /tmp/radiod/config + +# Version +cp /usr/share/radio/version /tmp/radiod/config/ + +# PiRadio stationlist file +mkdir /tmp/radiod/config/radiod/ +cp /var/lib/radiod/stationlist /tmp/radiod/config/radiod/ + +# MPD playlists +mkdir /tmp/radiod/config/playlists/ +cp /var/lib/mpd/playlists/* /tmp/radiod/config/playlists/ + +# Make ready for download file +cd /tmp/radiod/config +tar -zcf /home/pi/radio/html/piradio.stl * + +# clear temp +rm -r /tmp/radiod/config diff --git a/html/scripts/restore_stlist.sh b/html/scripts/restore_stlist.sh new file mode 100644 index 0000000..8b46958 --- /dev/null +++ b/html/scripts/restore_stlist.sh @@ -0,0 +1,29 @@ +# Restore station list from file + +# Only if 1 params +if [ $# = 1 ]; then + # Get parameter from commandline + + # "unpack" or "apply" + OPTION=$1 + + # Unpack or apply + if [ ${OPTION} = "unpack" ]; then + # prepare temp folder + rm -r /tmp/radiod/config + mkdir /tmp/radiod/config + # Unpack configuration + cd /tmp/radiod/config + tar -zxf /tmp/piradio.stl + # remove station list backup file + rm /tmp/piradio.stl + elif [ ${OPTION} = "apply" ]; then + # PiRadio statiolist file + cp /tmp/radiod/config/radiod/stationlist /var/lib/radiod/ + # MPD playlists + rm /var/lib/mpd/playlists/* + cp /tmp/radiod/config/playlists/* /var/lib/mpd/playlists/ + # clear temp + rm -r /tmp/radiod/config + fi +fi diff --git a/version b/version index 6f7f133..461c2b3 100644 --- a/version +++ b/version @@ -1 +1 @@ -5.5n +5.5o