kvs-linuxmint-dloadx/wine_serial_fix.sh

42 lines
1016 B
Bash
Raw Permalink Normal View History

2021-01-31 11:41:38 +00:00
#!/bin/bash
USERNAME="$1" # Provided by service file
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
if [ -z "$1" ]; then
echo "No arguments were supplied."
exit 1
fi
function doTheThang
{
# Wait for USB device to initialize
sleep 1
# TTY is empty if no serial device is detected
TTY=$(setserial -g /dev/ttyUSB[0-9] | awk -F"," '{print $1}')
2021-02-03 19:01:41 +00:00
if [ ! -z "$TTY" ]; then #configure wine to use serial device
2021-01-31 11:41:38 +00:00
echo -e "\e[1;32mUsing serial device: $TTY\e[0m"
2021-02-01 16:29:33 +00:00
ln -sfn $TTY /home/$USERNAME/.wine/dosdevices/com1 &&
chown $USERNAME /home/$USERNAME/.wine/dosdevices/com1 &&
2021-01-31 11:41:38 +00:00
ls -l /home/$USERNAME/.wine/dosdevices/ | grep $TTY
else
echo -e "\e[1;31mNo serial device\e[0m"
fi
}
doTheThang
LSUSB=$(lsusb)
while :
2021-02-03 19:01:41 +00:00
do #look for usb
2021-01-31 11:41:38 +00:00
if [ "$LSUSB" != "$(lsusb)" ]; then
LSUSB=$(lsusb)
echo "=======USB Change detected======="
2021-02-03 19:01:41 +00:00
doTheThang #usb found, run function
2021-01-31 11:41:38 +00:00
fi
sleep 1
done