From 7ac3f7871574eb38d66688dbd175ed2e302b99d5 Mon Sep 17 00:00:00 2001 From: mmaster Date: Wed, 22 Sep 2021 02:09:06 +0200 Subject: [PATCH] add automounter and check for storage device --- automount.sh | 17 ++++++++++++++--- randomvideo.sh | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/automount.sh b/automount.sh index ecff85d..ea6f267 100755 --- a/automount.sh +++ b/automount.sh @@ -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 diff --git a/randomvideo.sh b/randomvideo.sh index df83455..25494b4 100755 --- a/randomvideo.sh +++ b/randomvideo.sh @@ -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