add automounter and check for storage device

This commit is contained in:
mmaster 2021-09-22 02:09:06 +02:00
parent c8f0cc6164
commit 7ac3f78715
2 changed files with 29 additions and 5 deletions

View File

@ -1,8 +1,9 @@
#!/bin/sh
mountpoint="/media/video"
mountoptions="ro"
device="sda1"
mountpoint="/media/video" ### var: mountpoint
mountoptions="ro" ### var: mountoptions
device="sda1" ### var: mount device
player="randomvideo.sh" ### var: player process
if [ ! -d "$mountpoint" ]; then
sudo mkdir $mountpoint
@ -26,8 +27,18 @@ while true; do
elif [ -z "$dev_plug_state" ] && [ ! -z "$dev_mount_state" ]; then
echo "/dev/$device is not plugged in and is mounted on $mountpoint"
playerstat="$(pgrep $player)"
if [ ! -z "$playerstat" ]; then
echo "Terminating $player"
pkill $player
echo "Done!"
fi
echo "Umounting $mountpoint"
sudo umount $mountpoint
echo "Done!"
fi

View File

@ -1,12 +1,14 @@
#!/bin/sh
folder="/home/pi/Video" ### var: path to video files
folderext="/media/video" ### var: path to videofiles on external device
folderint="/home/pi/Video" ### var: path to videofiles on sdcard storage
player="cvlc" ### var: player command
playerparam="--no-osd --play-and-exit" ### var: player parameters
player_path="$(command -v $player)"
player_package="vlc" ### var: player apt package
mountdevice="sda1" ### var: device for mediafiles
if [ -z "$player_path" ]; then
echo "Missing $player, try to install it ..."
@ -29,12 +31,23 @@ if [ -z "$player_path" ]; then
fi
while true; do
mountstat="$(mount | grep $mountdevice)"
if [ -z "$mountstat" ]; then
folder="$folderint"
elif [ ! -z "$mountstat" ]; then
folder="$folderext"
fi
file="$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)"
while [ "$file" = "$oldfile" ]; do
file="$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)"
done
oldfile="$file"
$player $playerparam $file
done