2021-09-22 01:48:08 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-09-22 20:55:48 +02:00
|
|
|
# cat vars | grep playerproc | cut -d'=' -f2
|
|
|
|
|
2021-09-22 02:09:06 +02:00
|
|
|
mountpoint="/media/video" ### var: mountpoint
|
2021-09-22 02:29:09 +02:00
|
|
|
mountoptions="ro" ### var: mountoptions
|
2021-09-22 02:09:06 +02:00
|
|
|
device="sda1" ### var: mount device
|
2021-09-22 04:32:45 +02:00
|
|
|
playersh="randomvideo.sh" ### var: playerscript process
|
|
|
|
player="vlc" ### var: player process
|
2021-09-22 01:48:08 +02:00
|
|
|
|
|
|
|
if [ ! -d "$mountpoint" ]; then
|
|
|
|
sudo mkdir $mountpoint
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
|
|
|
dev_plug_state="$(lsblk | grep $device)"
|
|
|
|
dev_mount_state="$(mount | grep $device)"
|
|
|
|
|
2021-09-22 04:40:47 +02:00
|
|
|
if [ -n "$dev_plug_state" ] && [ -z "$dev_mount_state" ]; then
|
2021-09-22 01:48:08 +02:00
|
|
|
echo "Mount /dev/$device on $mountpoint with options $mountoptions"
|
|
|
|
sudo mount /dev/$device $mountpoint -o $mountoptions
|
|
|
|
echo "Done!"
|
|
|
|
|
2021-09-22 04:40:47 +02:00
|
|
|
elif [ -n "$dev_plug_state" ] && [ -n "$dev_mount_state" ]; then
|
2021-09-22 01:48:08 +02:00
|
|
|
echo "/dev/$device is already mounted on $mountpoint"
|
|
|
|
|
|
|
|
elif [ -z "$dev_plug_state" ] && [ -z "$dev_mount_state" ]; then
|
|
|
|
echo "/dev/$device not plugged in and is not mounted!"
|
|
|
|
|
2021-09-22 04:40:47 +02:00
|
|
|
elif [ -z "$dev_plug_state" ] && [ -n "$dev_mount_state" ]; then
|
2021-09-22 01:48:08 +02:00
|
|
|
echo "/dev/$device is not plugged in and is mounted on $mountpoint"
|
2021-09-22 02:09:06 +02:00
|
|
|
|
2021-09-22 04:32:45 +02:00
|
|
|
playershstat="$(pgrep $playersh)"
|
2021-09-22 04:40:47 +02:00
|
|
|
if [ -n "$playershstat" ]; then
|
2021-09-22 04:32:45 +02:00
|
|
|
echo "Terminating $playersh"
|
|
|
|
pkill $playersh
|
|
|
|
echo "Done!"
|
|
|
|
fi
|
2021-09-22 02:09:06 +02:00
|
|
|
|
2021-09-22 04:32:45 +02:00
|
|
|
playerstat="$(pgrep $player)"
|
2021-09-22 04:40:47 +02:00
|
|
|
if [ -n "$playerstat" ]; then
|
2021-09-22 02:09:06 +02:00
|
|
|
echo "Terminating $player"
|
|
|
|
pkill $player
|
|
|
|
echo "Done!"
|
|
|
|
fi
|
|
|
|
|
2021-09-22 01:48:08 +02:00
|
|
|
echo "Umounting $mountpoint"
|
|
|
|
sudo umount $mountpoint
|
2021-09-22 02:09:06 +02:00
|
|
|
echo "Done!"
|
2021-09-22 01:48:08 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|