-
Notifications
You must be signed in to change notification settings - Fork 2
/
womic.sh
executable file
·106 lines (98 loc) · 3.21 KB
/
womic.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: womic [OPTIONS]"
echo "Options:"
echo " -b - to connect via Bluetooth"
echo " -w - to connect via WiFi"
echo " -k - to disconnect"
echo " -h - help (this message)"
exit 1
fi
if [ `ls | grep ^micclient-x86_64.*$` ]; then
MICCLIENT=$(ls | grep ^micclient-x86_64.*$)
else
printf "WO Mic Appimage binary not found! Would you like to download it now? (y/n): "
read INPUT
if [ "$INPUT" == "y" ]; then
printf "\n"
wget -q --show-progress https://wolicheng.com/womic/softwares/micclient-x86_64.AppImage
if [ $? -eq 1 ]; then
curl https://wolicheng.com/womic/softwares/micclient-x86_64.AppImage -o micclient-x86_64.AppImage
fi
printf "\n"
else
printf "\nThe WO Mic Appimage binary is required in order for the script to function.\n"
printf "Either re-run the script and choose \"y\" to download the binary automatically or download it manually according to the README file.\n"
exit 1
fi
fi
function executable_check() {
if ! [ -x $MICCLIENT ]; then
chmod +x $MICCLIENT
fi
}
function module_check() {
if ! [ `lsmod | grep -o ^snd_aloop` ]; then
sudo modprobe snd-aloop
fi
}
while getopts "hbwk" OPTION; do
case $OPTION in
h)
echo "Usage: womic [OPTIONS]"
echo "Options:"
echo " -b - to connect via Bluetooth"
echo " -w - to connect via WiFi"
echo " -k - to disconnect"
echo " -h - help (this message)"
exit 0
;;
b)
if ! [[ -z $(ps aux | grep '[m]icclient-x86_64.*$' | awk '{print $2}') ]]; then
printf "WO Mic is already running!\n"
exit 1
else
executable_check
module_check
printf "(Format: xx:xx:xx:xx:xx:xx)\n"
printf "Enter device address: "
read ADDRESS
echo ""
printf "Run 'womic -k' to disconnect\n\n"
./$MICCLIENT -t Bluetooth $ADDRESS &
sleep 3
fi
;;
w)
if ! [[ -z $(ps aux | grep '[m]icclient-x86_64.*$' | awk '{print $2}') ]]; then
printf "WO Mic is already running!\n"
exit 1
else
executable_check
module_check
printf "(Example: 192.168.0.100)\n"
printf "Enter device IP: "
read IP
echo ""
printf "Run 'womic -k' to disconnect\n\n"
./$MICCLIENT -t Wifi $IP &
sleep 3
fi
;;
k)
if ! kill -2 $(ps aux | grep '[m]icclient-x86_64.*$' | awk '{print $2}') > /dev/null 2>&1; then
printf "WO Mic is not running!\n"
exit 1
else
kill -2 $(ps aux | grep '[m]icclient-x86_64.*$' | awk '{print $2}')
sleep 1
exit 0
fi
;;
*)
echo ""
echo "Run 'womic -h' for help"
exit 0
;;
esac
done