-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPIConnect
executable file
·160 lines (152 loc) · 5.7 KB
/
RPIConnect
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
nbr_arg=$#
first_arg=$1
second_arg=$2
Error_CNF="Command not found"
Error_NTD="Nothing to do"
MP="0"
PULSEAUDIO="0"
BUZZ="0"
STREAM="0"
if ps -u raspberry -o pid,comm | grep -e cmus > /dev/null; then MP="1"; fi;
if ps -u raspberry -o pid,comm | grep -e pulseaudio > /dev/null; then PULSEAUDIO="1"; fi;
if ps -u raspberry -o pid,comm | grep -e Buzz > /dev/null; then BUZZ="1"; fi;
if ps -u raspberry -o pid,comm | grep -e mjpg_streamer > /dev/null; then STREAM="1"; fi;
CheckState () {
eval "$1=$(cmus-remote -Q | grep status | cut -d ' ' -f 2)"
}
FindNameRadioStation() {
eval "$1='$(cmus-remote -Q | grep title | cut -d ' ' -f 3-)'"
}
FindIPAddress(){
eval "$1=$(ifconfig eth0 | grep -w inet | tr -s ' ' | cut -d ' ' -f 3)"
}
if [[ $nbr_arg -eq 1 ]]; then
if [[ $first_arg = "-status" ]]; then
echo "$MP$PULSEAUDIO$BUZZ$STREAM$EOF"
else
echo "$Error_CNF"
fi
elif [[ $nbr_arg -eq 2 ]]; then
if [[ $first_arg = "-vol" ]]; then
if [[ $second_arg = "+" ]]; then
amixer -c 0 set PCM 5dB+ > /dev/null;
elif [[ $second_arg = "-" ]]; then
amixer -c 0 set PCM 5dB- > /dev/null;
else
echo "$Error_CNF";
fi
elif [[ $first_arg = "-mp" ]]; then
if [[ $MP = "1" ]]; then
if [[ $second_arg = "off" ]]; then
cmus-remote -C "quit";
elif [[ $second_arg = "on" ]]; then
echo "$Error_NTD";
elif [[ $second_arg = "+" ]]; then
cmus-remote -v +5;
elif [[ $second_arg = "-" ]]; then
cmus-remote -v -5;
elif [[ $second_arg = "next" ]]; then
CheckState mp_state;
if [[ $mp_state = "playing" ]]; then
cmus-remote -s;
cmus-remote -n;
cmus-remote -p;
elif [[ $mp_state = "stopped" ]]; then
cmus-remote -n;
fi;
FindNameRadioStation NameRadioStation;
if [[ $NameRadioStation ]]; then
echo $NameRadioStation | festival --tts;
fi;
elif [[ $second_arg = "prev" ]]; then
CheckState mp_state;
if [[ $mp_state = "playing" ]]; then
cmus-remote -s;
cmus-remote -r;
cmus-remote -p;
elif [[ $mp_state = "stopped" ]]; then
cmus-remote -r;
fi;
FindNameRadioStation NameRadioStation;
if [[ $NameRadioStation ]]; then
echo $NameRadioStation | festival --tts;
fi;
elif [[ $second_arg = "play_pause" ]]; then
cmus-remote -u;
CheckState mp_state;
if [[ $mp_state = "playing" ]]; then
FindNameRadioStation NameRadioStation;
if [[ $NameRadioStation ]]; then
echo $NameRadioStation | festival --tts;
fi;
fi
else
echo "$Error_CNF";
fi
elif [[ $MP = "0" ]]; then
if [[ $second_arg = "on" ]]; then
cmusd & sleep 5 && tmux detach-client -s cmus;
elif [[ $second_arg = "play_pause" ]]; then
cmusd & sleep 5 && tmux detach-client -s cmus && cmus-remote -p;
FindNameRadioStation NameRadioStation;
if [[ $NameRadioStation ]]; then
echo $NameRadioStation | festival --tts;
fi;
elif [[ $second_arg = "off" ]]; then
echo "$Error_NTD";
else
echo "$Error_CNF";
fi
fi
elif [[ $first_arg = "-pulseaudio" ]]; then
if [[ $second_arg = "on" && $PULSEAUDIO = "0" ]]; then
pulseaudio -D > /dev/null;
elif [[ $second_arg = "off" && $PULSEAUDIO = "1" ]]; then
killall pulseaudio > /dev/null;
elif [[ $second_arg = "on" || $second_arg = "off" ]]; then
echo "$Error_NTD";
else
echo "$Error_CNF";
fi
elif [[ $first_arg = "-stream" ]]; then
if [[ $second_arg = "on" && $STREAM = "0" ]]; then
mjpg_streamer -b -i "input_uvc.so" -o "output_http.so -p 8090" > /dev/null;
elif [[ $second_arg = "off" && $STREAM = "1" ]]; then
killall mjpg_streamer > /dev/null;
elif [[ $second_arg = "on" || $second_arg = "off" ]]; then
echo "$Error_NTD";
else
echo "$Error_CNF";
fi
elif [[ $first_arg = "-buzz" ]]; then
if [[ $second_arg = "on" && $BUZZ = "0" ]]; then
Buzz > /dev/null;
elif [[ $second_arg = "off" && $BUZZ = "1" ]]; then
killall Buzz > /dev/null;
elif [[ $second_arg = "on" || $second_arg = "off" ]]; then
echo "$Error_NTD";
else
echo "$Error_CNF";
fi
elif [[ $first_arg = "-talk" ]]; then
if [[ $second_arg = "ip" ]]; then
FindIPAddress IPaddr;
Vol=$(amixer -c 0 get PCM | awk '$0~/%/{print $4}' | tr -d '[]');
amixer -c 0 set PCM 100%;
echo "my i p address, is, $IPaddr"| festival --tts;
amixer -c 0 set PCM $Vol;
elif [[ $second_arg = "time" ]]; then
Vol=$(amixer -c 0 get PCM | awk '$0~/%/{print $4}' | tr -d '[]');
amixer -c 0 set PCM 100%;
echo "now is `date "+%I:%M"`"| festival --tts;
amixer -c 0 set PCM $Vol;
else
echo "$Error_CNF";
fi
else
echo "$Error_CNF";
fi
else
echo "$Error_CNF";
fi