forked from JeffCurless/argoneon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargonone-ir.sh
executable file
·325 lines (285 loc) · 8.06 KB
/
argonone-ir.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/bash
CHECKPLATFORM="Others"
# Check if Raspbian
grep -q -F 'Raspbian' /etc/os-release &> /dev/null
if [ $? -eq 0 ]
then
CHECKPLATFORM="Raspbian"
fi
echo "-----------------------------"
echo " Argon IR Configuration Tool"
echo "------------------------------"
echo "WARNING: This only supports NEC"
echo " protocol only."
echo -n "Press Y to continue:"
read -n 1 confirm
echo
if [ "$confirm" = "y" ]
then
confirm="Y"
fi
if [ "$confirm" != "Y" ]
then
echo "Cancelled"
exit
fi
echo "Thank you."
get_number () {
read curnumber
if [ -z "$curnumber" ]
then
echo "-2"
return
elif [[ $curnumber =~ ^[+-]?[0-9]+$ ]]
then
if [ $curnumber -lt 0 ]
then
echo "-1"
return
elif [ $curnumber -gt 100 ]
then
echo "-1"
return
fi
echo $curnumber
return
fi
echo "-1"
return
}
irexecrcfile=/etc/lirc/irexec.lircrc
irexecshfile=/etc/argon/argonirexec
irdecodefile=/etc/argon/argonirdecoder
kodiuserdatafolder="$HOME/.kodi/userdata"
kodilircmapfile="$kodiuserdatafolder/Lircmap.xml"
remotemode=""
needinstallation=0
loopflag=1
while [ $loopflag -eq 1 ]
do
echo
echo "Select remote control to configure:"
echo " 1. Configure Remote ON/OFF Button"
if [ "$CHECKPLATFORM" = "Raspbian" ]
then
echo " 2. Configure Other Remote Buttons"
if [ ! -f "$irexecshfile" ]
then
echo " 3. Cancel"
echo -n "Enter Number (1-3):"
newmode=$( get_number )
if [[ $newmode -ge 1 && $newmode -le 3 ]]
then
loopflag=0
if [ $newmode -eq 3 ]
then
newmode=4
fi
fi
else
echo " 3. Uninstall Other Remote Buttons"
echo " 4. Cancel"
echo -n "Enter Number (1-4):"
newmode=$( get_number )
if [[ $newmode -ge 1 && $newmode -le 4 ]]
then
loopflag=0
fi
fi
else
echo " 2. Cancel"
echo -n "Enter Number (1-2):"
newmode=$( get_number )
if [[ $newmode -ge 1 && $newmode -le 2 ]]
then
loopflag=0
if [ $newmode -eq 2 ]
then
newmode=4
fi
fi
fi
done
echo
if [ $newmode -eq 3 ]
then
irtmpconfigfile=/dev/shm/argonirconfig.txt
sudo systemctl stop irexec.service
sudo systemctl disable irexec.service
sudo pip3 uninstall lirc -y
sudo apt-get -y remove lirc
sudo rm $irexecshfile
sudo rm $irdecodefile
sudo cat /boot/config.txt | grep -v 'dtoverlay=gpio-ir,gpio_pin=23' > $irtmpconfigfile
cat $irtmpconfigfile | sudo tee /boot/config.txt 1> /dev/null
sudo rm $irtmpconfigfile
echo "Uninstall Completed"
echo "Please reboot for changes to take effect"
exit
elif [ $newmode -eq 1 ]
then
loopflag=1
while [ $loopflag -eq 1 ]
do
echo
echo "Select remote control to configure:"
echo " 1. Use Argon Remote ON/OFF Button"
echo " 2. Use Custom Remote ON/OFF Button"
echo " 3. Cancel"
echo -n "Enter Number (1-3):"
newmode=$( get_number )
if [[ $newmode -ge 1 && $newmode -le 4 ]]
then
loopflag=0
fi
done
if [ $newmode -eq 3 ]
then
echo "Cancelled"
exit
elif [ $newmode -eq 1 ]
then
remotemode="resetpower"
elif [ $newmode -eq 2 ]
then
remotemode="power"
fi
elif [ $newmode -eq 2 ]
then
echo "-----------------------------"
echo " Argon IR Configuration Tool"
echo "-----------------------------"
echo "WARNING: This will install LIRC"
echo " and related libraries."
echo -n "Press Y to agree:"
read -n 1 confirm
echo
if [ "$confirm" = "y" ]
then
confirm="Y"
fi
if [ "$confirm" != "Y" ]
then
echo "Cancelled"
exit
fi
echo "Thank you."
needinstallation=1
loopflag=1
while [ $loopflag -eq 1 ]
do
echo
echo "Select remote control to configure:"
echo " 1. Use Argon Remote Buttons"
echo " 2. Use Custom Remote Buttons"
echo " 3. Cancel"
echo -n "Enter Number (1-3):"
newmode=$( get_number )
if [[ $newmode -ge 1 && $newmode -le 4 ]]
then
loopflag=0
fi
done
if [ $newmode -eq 3 ]
then
echo "Cancelled"
exit
elif [ $newmode -eq 1 ]
then
remotemode="default"
elif [ $newmode -eq 2 ]
then
remotemode="custom"
fi
else
echo "Cancelled"
exit
fi
needrestart=0
if [ $needinstallation -eq 1 ]
then
if [ ! -f "$irexecshfile" ]
then
needrestart=1
sudo apt-get -y update
sudo apt-get -y install lirc
sudo pip3 install lirc
echo "dtoverlay=gpio-ir,gpio_pin=23" | sudo tee -a /boot/config.txt 1> /dev/null
sudo /usr/share/lirc/lirc-old2new
sudo systemctl daemon-reload
sudo systemctl enable irexec.service
sudo systemctl start irexec.service
echo "" | sudo tee $irexecrcfile 1> /dev/null
for keyname in UP DOWN LEFT RIGHT BACK PLAYPAUSE MENU HOME OK MUTE VOLUMEUP VOLUMEDOWN
do
echo 'begin' | sudo tee -a $irexecrcfile 1> /dev/null
echo ' remote=argon' | sudo tee -a $irexecrcfile 1> /dev/null
echo ' prog=irexec' | sudo tee -a $irexecrcfile 1> /dev/null
echo ' button=KEY_'$keyname | sudo tee -a $irexecrcfile 1> /dev/null
echo ' config='$irexecshfile' "'$keyname'"' | sudo tee -a $irexecrcfile 1> /dev/null
echo 'end' | sudo tee -a $irexecrcfile 1> /dev/null
done
echo "#!/bin/bash" | sudo tee $irexecshfile 1> /dev/null
echo '' | sudo tee -a $irexecshfile 1> /dev/null
echo 'if [ -z "$1" ]' | sudo tee -a $irexecshfile 1> /dev/null
echo 'then' | sudo tee -a $irexecshfile 1> /dev/null
echo ' exit' | sudo tee -a $irexecshfile 1> /dev/null
echo 'fi' | sudo tee -a $irexecshfile 1> /dev/null
echo '' | sudo tee -a $irexecshfile 1> /dev/null
echo '# Handlers for different key codes' | sudo tee -a $irexecshfile 1> /dev/null
echo '# Key codes: UP DOWN LEFT RIGHT BACK PLAYPAUSE MENU HOME OK MUTE VOLUMEUP VOLUMEDOWN' | sudo tee -a $irexecshfile 1> /dev/null
echo '' | sudo tee -a $irexecshfile 1> /dev/null
echo 'amixerdevice=$(/usr/bin/amixer scontrols | sed -n "s/^.*'"'\(.*\)'"'.*$/\1/p")' | sudo tee -a $irexecshfile 1> /dev/null
echo 'if [ $1 == "VOLUMEUP" ]' | sudo tee -a $irexecshfile 1> /dev/null
echo 'then' | sudo tee -a $irexecshfile 1> /dev/null
echo ' /usr/bin/amixer set $amixerdevice -- $[$(/usr/bin/amixer get $amixerdevice|grep -o [0-9]*%|sed '"'s/%//'"')+5]%' | sudo tee -a $irexecshfile 1> /dev/null
echo 'elif [ $1 == "VOLUMEDOWN" ]' | sudo tee -a $irexecshfile 1> /dev/null
echo 'then' | sudo tee -a $irexecshfile 1> /dev/null
echo ' /usr/bin/amixer set $amixerdevice -- $[$(/usr/bin/amixer get $amixerdevice|grep -o [0-9]*%|sed '"'s/%//'"')-5]%' | sudo tee -a $irexecshfile 1> /dev/null
echo 'elif [ $1 == "MUTE" ]' | sudo tee -a $irexecshfile 1> /dev/null
echo 'then' | sudo tee -a $irexecshfile 1> /dev/null
echo ' /usr/bin/amixer set $amixerdevice toggle' | sudo tee -a $irexecshfile 1> /dev/null
echo 'fi' | sudo tee -a $irexecshfile 1> /dev/null
echo '' | sudo tee -a $irexecshfile 1> /dev/null
sudo chmod 755 $irexecshfile
fi
fi
if [ ! -f "$irdecodefile" ]
then
sudo wget https://download.argon40.com/argonone-irdecoder.py -O $irdecodefile --quiet
fi
sudo python3 $irdecodefile $remotemode
if [ ! -d $kodiuserdatafolder ]
then
if [ ! -d "$HOME/.kodi" ]
then
mkdir "$HOME/.kodi"
fi
mkdir $kodiuserdatafolder
fi
if [ -d $kodiuserdatafolder ]
then
echo "<lircmap>" | tee $kodilircmapfile 1> /dev/null
echo ' <remote device="argon">' | tee -a $kodilircmapfile 1> /dev/null
echo ' <left>KEY_LEFT</left>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <right>KEY_RIGHT</right>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <up>KEY_UP</up>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <down>KEY_DOWN</down>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <select>KEY_OK</select>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <start>KEY_HOME</start>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <rootmenu>KEY_MENUBACK</rootmenu>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <volumeplus>KEY_VOLUMEUP</volumeplus>' | tee -a $kodilircmapfile 1> /dev/null
echo ' <volumeminus>KEY_VOLUMEDOWN</volumeminus>' | tee -a $kodilircmapfile 1> /dev/null
echo ' </remote>' | tee -a $kodilircmapfile 1> /dev/null
echo '</lircmap>' | tee -a $kodilircmapfile 1> /dev/null
fi
echo
echo "Thank you."
if [ $needrestart -eq 1 ]
then
echo "Changes should take after reboot."
elif [ $needinstallation -eq 1 ]
then
sudo systemctl restart lircd.service
sudo systemctl restart irexec.service
fi