From ed5e041e7e0ee70b62b2cc7e0d1ef63936b22bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20CHASSAIGNE?= Date: Fri, 16 Sep 2016 14:55:46 +0000 Subject: [PATCH] Auto-import script + doc --- doc/2-PI.rst | 29 +++++++++++++++++++++++++++++ share/89-usbcopy.rules | 1 + share/98-usbcopy.rules | 1 - share/import_music.sh | 32 ++++++++++++++++++++++++++++++++ share/musique.sh | 25 ------------------------- 5 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 share/89-usbcopy.rules delete mode 100644 share/98-usbcopy.rules create mode 100755 share/import_music.sh delete mode 100755 share/musique.sh diff --git a/doc/2-PI.rst b/doc/2-PI.rst index 61da887..fc0cfc1 100644 --- a/doc/2-PI.rst +++ b/doc/2-PI.rst @@ -63,6 +63,35 @@ To be able to play the songs correctly, ALSA needs a bit of configuration. To do defaults.ctl.!card 1; +Auto-load .song files from a USB key +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +WARNING: You first need to clone the server's repository on the Pi an open its folder (see ``3-COMPILING.rst`` for details about the procedure). + +First, open the ``share/import_music.sh`` to setup the copy script. You can change the following variables: + +``extension`` + Extension of the song files. Default: ``"song"``. + +``destination`` + Folder where to copy the files. Default: ``"/home/pi/songs"``. + +``user`` + Name of the user that owns the ``destination`` folder. Default: ``"pi"``. + +``led`` + LED's ``wiringpi`` GPIO identifier (to signal the script is running). Default: ``"5"`` + +Once it's done (you can also leave the default values), copy the script to ``/usr/local/bin``, and the ``udev`` rule file to ``/etc/udev/rules.d``:: + + # cp share/import_music.sh /usr/local/bin/ + # cp share/89-usbcopy.rules /etc/udev/rules.d/ + +The system should automatically detect the new rule, and will automatically copy the .song (or whatever you want) files from a USB key/drive to the folder you choosed. +Note that a LED should be activated during the whole operation, so don't touch the key or drive during that time. + + + Wifi bridge setup ----------------- diff --git a/share/89-usbcopy.rules b/share/89-usbcopy.rules new file mode 100644 index 0000000..256e8fe --- /dev/null +++ b/share/89-usbcopy.rules @@ -0,0 +1 @@ +KERNEL=="sd[a-z]?", SUBSYSTEM=="block", ACTION=="add", RUN+="/usr/local/bin/import_music.sh %k" diff --git a/share/98-usbcopy.rules b/share/98-usbcopy.rules deleted file mode 100644 index be08257..0000000 --- a/share/98-usbcopy.rules +++ /dev/null @@ -1 +0,0 @@ -ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]1", RUN +="/bin/mount -o dmask=777,fmask=777 /dev/%k /media/song_usb", RUN+="/usr/local/bin/musique.sh /dev/%k" diff --git a/share/import_music.sh b/share/import_music.sh new file mode 100755 index 0000000..63f6541 --- /dev/null +++ b/share/import_music.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +###### +# Copy the $extension files from the root folder (/) +# of a USB key to the $destination folder +# +# $1 : Device's kernel name +###### + +extension="song" +destination="/home/pi/songs" +user="pi" +led="5" + +gpio mode $led out +gpio write $led 1 + +mkdir /media/song_$1 + +mount /dev/$1 /media/song_$1 + +echo "mounted" >> /home/pi/truc.txt + +cp -n /media/song_$1/*.$extension $destination +sudo chown -R $user $destination +sync + +umount /media/song_$1 +rmdir /media/song_$1 + +gpio write $led 0 + diff --git a/share/musique.sh b/share/musique.sh deleted file mode 100755 index 035dee4..0000000 --- a/share/musique.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -###### -# Copy the $extension files from the root folder (/) -# of a USB key to the $destination folder -# -# $1 : USB key's kernel name -###### - -extension="song" -destination="/home/pi/songs" - -#export DISPLAY=":0" -#notify-send "Copying new songs... Please wait." - -gpio mode 5 out -gpio write 5 1 - -cp -n /dev/$1/*.$extension $destination -sync -umount /media/song_usb - -gpio write 5 0 - -#notify-send "Copying done, you can safely remove the USB key"