-
Notifications
You must be signed in to change notification settings - Fork 1
/
i.sh
executable file
·1550 lines (1241 loc) · 41.6 KB
/
i.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Install Arch Linux as described in official wiki
# Optional: Create partition for torrents and mount to /mnt/data
# Run this script for install and configure Kodi
# Boot XBMCbuntu, CTRL+ALT+F1, login and run:
# wget https://raw.githubusercontent.com/pfzim/xbmc-config/master/i.sh
# chmod a+rx i.sh
# sudo ./i.sh
# --wget http://hencvik.googlecode.com/files/i.sh
# --./i.sh 2>&1 | tee i.log
back_title="XBMC 18.5 post installation configuration script v0.09.02 (c) pfzim"
fg_title="XBMC configuration"
DIALOG=whiptail
idir=$(pwd)
dm=fluxbox
user_name=xbmc
user_home=/home/xbmc
required_commands="awk sed ${DIALOG} grep getent networkctl systemctl pacman wpa_supplicant wpa_cli"
ask() {
while :
do
read -p "$1" $2
if [ -n "$(eval "echo \$$2")" ] ; then
break
fi
if [ $# -gt 2 -a -n "$3" ] ; then
eval "$2=\$3"
break
fi
done
}
a_msgbox() {
${DIALOG} --backtitle "${back_title}" --clear --title "${fg_title}" --msgbox "$1" 10 75
}
# text result default
a_yesno() {
defval=" --defaultno"
if [ "$3" = "yes" ] ; then
defval=""
fi
${DIALOG} --backtitle "${back_title}" --clear --title "${fg_title}"${defval} --yesno "$1" 22 75
if [ $? -eq 0 ] ; then
eval "$2=Y"
else
eval "$2=N"
fi
}
# text result=default value
a_input() {
while :
do
temp_result=`mktemp 2>/dev/null` || temp_result=/tmp/test$$
eval "${DIALOG} --backtitle \"${back_title}\" --clear --title \"${fg_title}\"${defval} --inputbox \"$1\" 10 75 \"\${$2}\" 2>$temp_result"
exit_code=$?
result=`cat $temp_result`
rm -f $temp_result
if [ $exit_code -eq 0 ] ; then
eval "$2=\$result"
break
else
a_yesno "Interrupt installation?" result "no"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
exit 1
fi
fi
done
}
# text result
a_passwd0() {
while :
do
temp_result=`mktemp 2>/dev/null` || temp_result=/tmp/test$$
${DIALOG} --backtitle "${back_title}" --clear --title "${fg_title}"${defval} --passwordbox "$1" 10 75 2>$temp_result
exit_code=$?
result=`cat $temp_result`
rm -f $temp_result
if [ $exit_code -eq 0 ] ; then
eval "$2=\$result"
break
else
#eval "$2=\"$3\""
a_yesno "Interrupt installation?" result "no"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
exit 1
fi
fi
done
}
a_passwd() {
while :
do
temp_passwd1=""
temp_passwd2=""
a_passwd0 "$1" temp_passwd1
a_passwd0 "Enter password again:" temp_passwd2
if [ -n "$temp_passwd1" -a "$temp_passwd1" = "$temp_passwd2" ] ; then
eval "$2=\"$temp_passwd1\""
break
fi
done
}
# ask user name for run xbmc
c_user_pre() {
while :
do
a_input "Enter username for run XBMC (must be exist):" user_name
user_name=$(echo $user_name | sed -e 's/ //')
user_info=$(getent passwd $user_name)
if [ $? -eq 0 ] ; then
user_home=$(echo $user_info | cut -d: -f6)
break
else
a_yesno "User '$user_name' does not exist\n\nCreate this user?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
useradd -m $user_name
passwd $user_name
#break
fi
fi
done
# useradd -m -G wheel,sudo xbmc
# useradd -m xbmc
# passwd xbmc
}
# set timezone
############################
c_tz() {
timedatectl set-ntp true
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime
hwclock --systohc
}
# update arch
############################
i_update() {
pacman -Syu --noconfirm
}
# Configure wireless interface
##############################
ask_settings_ip() {
while :
do
a_input "Enter IP address [$1]:" $1
a_input "Enter network prefix [$2]:" $2
a_input "Enter gateway [$3]:" $3
a_input "Enter DNS1 [$4]:" $4
a_input "Enter DNS2 [$5]:" $5
a_input "Enter Metric [$6]:" $6
eval "a_yesno \"Network settings:\\n\\nIP: \$$1\nMask: \$$2\\nGateway: \$$3\\nDNS1: \$$4\\nDNS2: \$$5\\nMetric: \$$6\\n\\nEntered data correct?\" result"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
ask_settings_pass() {
while :
do
a_passwd "Enter password for wireless network:" p1
if [ "${#p1}" -ge 8 -a "${#p1}" -le 63 ] ; then
eval "$1=$p1"
break
else
a_msgbox "Passphrase must be 8..63 characters"
fi
done
}
c_net_pre() {
pacman -S --noconfirm --needed wpa_supplicant
systemctl start systemd-networkd
fg_title="Network configuration"
while :
do
# list_items=<interface>;net_type=<type>
list_items=$(networkctl --no-legend list | awk '{ print $2 ";net_type=" $3 }')
# list_menu=<interface> <type>
list_menu=$(echo "${list_items}" | sed -e "s/^\([^;]\+\);net_type=\(.*\)\$/\1 \2/")
#list_menu="${list_menu}\nrescan \"Find new networks...\""
#list_menu="${list_menu}\nback \"Back to previous menu\""
#echo $list_menu
#exit 0
if [ -z "${list_menu}" ] ; then
a_msgbox "ERROR: Something gone wrong..."
break
fi
tempfile=`mktemp 2>/dev/null` || tempfile=/tmp/test$$
#trap "rm -f $tempfile" 0 1 2 5 15
eval ${DIALOG} --backtitle \"${back_title}\" --clear --title \"Network configuration\" --menu \"Select network inteface\" 20 75 13 ${list_menu} 2>$tempfile
if [ $? -ne 0 ] ; then
rm -f $tempfile
break
fi
net_if=$(cat $tempfile)
rm -f $tempfile
if [ "${net_if}" = "rescan" ] ; then
continue
fi
if [ "${net_if}" = "exit" ] ; then
break
fi
eval $(echo "${list_items}" | grep "^${net_if};" | sed -e "s/^[^;]\+;//")
if [ "${net_type}" = "loopback" ] ; then
continue
fi
net_metric="20"
if [ "${net_type}" = "wlan" ] ; then
net_metric="50"
#ifconfig ${net_if} up
[ -f /etc/wpa_supplicant/wpa_supplicant.conf ] || cat > /etc/wpa_supplicant/wpa_supplicant.conf <<- EOF
ctrl_interface=/run/wpa_supplicant
#update_config=1
EOF
wpa_supplicant -B -i${net_if} -c/etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli -i${net_if} scan
echo "Wait for 7 seconds. Scanning WiFi..."
sleep 7
# list_items = <SSID>;ap_type=<WPA|WEP|OPEN>
list_items=$(wpa_cli -i${net_if} scan_results | awk '{
if(NR > 1)
{
if(match($4, /WEP|WPA/, m))
{
print $5 ";ap_etype=" m[0];
}
else
{
print $5 ";ap_etype=OPEN";
}
}
}')
list_menu=$(echo "${list_items}" | sed -e "s/^\([^;]\+\);ap_etype=\(.*\)\$/\1 \2/")
#list_menu="${list_menu}\nrescan \"Find new networks...\""
#list_menu="${list_menu}\nback \"Back to previous menu\""
#echo $list_menu
#exit 0
#echo "*** RESULT ***"
#echo "${list_items}"
#echo "*** RESULT ***"
#echo "*** RESULT ***"
#echo "${list_menu}"
#echo "*** RESULT ***"
if [ -z "${list_items}" ] ; then
a_msgbox "No one WiFi networks found. Try scan again"
continue
fi
eval ${DIALOG} --backtitle \"${back_title}\" --clear --title \"Wireless network configuration\" --menu \"Select WiFi accesspoint\" 20 75 13 ${list_menu} 2>$tempfile
if [ $? -ne 0 ] ; then
rm -f $tempfile
continue
fi
sel_item=$(cat $tempfile)
rm -f $tempfile
if [ "${sel_item}" = "back" ] ; then
continue
fi
eval $(echo "${list_items}" | grep "^${sel_item};" | sed -e "s/^[^;]\+;//")
ap_essid=$sel_item
#echo "AP_INFO: ${ap_info}"
#echo "MAC: ${ap_mac}"
#echo "ESSID: ${ap_essid}"
#echo "ENC-TYPE: ${ap_etype}"
if [ "${ap_etype}" = "WPA" ] ; then
ask_settings_pass ap_pass
wpa_cfg=$(wpa_passphrase "${ap_essid}" "${ap_pass}")
elif [ "${ap_etype}" = "WEP" ] ; then
ask_settings_pass ap_pass
wpa_cfg=$(cat <<- END
ssid="${ap_essid}"
key_mgmt=NONE
wep_key0="${ap_pass}"
wep_tx_keyidx=0
END
)
else
wpa_cfg=$(cat <<- END
ssid="${ap_essid}"
key_mgmt=NONE
END
)
fi
else
net_mac=$(cat /sys/class/net/${net_if}/address)
link_cfg=$(cat <<- END
[Match]
MACAddress=${net_mac}
[Link]
NamePolicy=keep kernel database onboard slot path
MACAddressPolicy=persistent
WakeOnLan=magic
END
)
a_yesno "/etc/systemd/network/90-wired-${net_if}.link\n${link_cfg}\n\nEnable Wake on LAN?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
echo -ne "$link_cfg" > "/etc/systemd/network/90-wired-${net_if}.link"
fi
fi
a_yesno "Use DHCP?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
a_input "Enter Metric [${net_metric}]:" net_metric
net_cfg=$(cat <<- END
[Match]
Name=${net_if}
[Network]
DHCP=yes
[DHCPv4]
RouteMetric=${net_metric}
[DHCPv6]
RouteMetric=${net_metric}
END
)
else
net_ip="192.168.1.100"
net_prefix="24"
net_gw="192.168.1.1"
net_dns1="192.168.1.1"
net_dns2=""
ask_settings_ip net_ip net_prefix net_gw net_dns1 net_dns2 net_metric
net_dns=""
if [ -n "${net_dns1}" -o -n "${net_dns2}" ] ; then
if [ -n "${net_dns1}" ] ; then
net_dns="DNS=${net_dns1}\n"
fi
if [ -n "${net_dns2}" ] ; then
net_dns="${net_dns}DNS=${net_dns2}\n"
fi
fi
net_cfg=$(cat <<- END
[Match]
Name=${net_if}
[Network]
DHCP=ipv6
${net_dns}
[DHCPv6]
RouteMetric=${net_metric}
[Address]
Address=${net_ip}/${net_prefix}
[Route]
Gateway=${net_gw}
Metric=${net_metric}
END
)
fi
if [ "${net_type}" = "wlan" ] ; then
a_yesno "/etc/wpa_supplicant/wpa_supplicant-${net_if}.conf:\n${wpa_cfg}\n\nSave this configuration?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
echo -ne "$wpa_cfg" > "/etc/wpa_supplicant/wpa_supplicant-${net_if}.conf"
systemctl enable "wpa_supplicant@${net_if}"
fi
fi
a_yesno "/etc/systemd/network/90-network-${net_if}.network:\n${net_cfg}\n\nSave this configuration?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
echo -ne "$net_cfg" > "/etc/systemd/network/90-network-${net_if}.network"
systemctl enable systemd-networkd
systemctl enable systemd-resolved
fi
a_yesno "${net_res}\nConnect NOW using this configuration?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
if [ "${net_type}" = "wlan" ] ; then
systemctl restart "wpa_supplicant@${net_if}"
fi
systemctl restart systemd-networkd
systemctl restart systemd-resolved
fi
done
}
# install NetworkManager
############################
#read -p "Install Network Manager [Y/n]?" result
i_nm() {
pacman -S --noconfirm --needed networkmanager
#sed -i "s/\(\\s*managed\\s*=\\s*\)false/\\1true/" /etc/NetworkManager/NetworkManager.conf
#echo "\nnm-applet --sm-disable &" >> ~/.fluxbox/startup
}
# configure DDNS
############################
ask_settings_noip() {
while :
do
#echo "DDNS no-ip.com settings:"
a_input "Enter login: " $1
a_passwd "Enter password: " $2
a_input "Enter host: " $3
eval "a_yesno \"no-ip.com DDNS service settings:\\n\\nLogin: \$$1\\nPassword: *hidden*\\nHost: \$$3\\n\\nEntered data correct?\" result \"yes\""
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
#read -p "Configure DDNS no-ip.com script [Y/n]?" result
c_ddns_pre() {
noip_user=""
noip_passwd=""
noip_host="youname.no-ip.org"
fg_title="DDNS no-ip.com settings"
ask_settings_noip noip_user noip_passwd noip_host
}
c_ddns() {
pacman -S --noconfirm --needed cronie curl
systemctl enable cronie
systemctl start cronie
crontab -u $user_name -l > .crontab
cat >> .crontab <<- EOF
# curl version
*/15 * * * * curl --silent --basic --user "${noip_user}:${noip_passwd}" --user-agent "curl based script/0.01 pfzim@mail.ru" "http://dynupdate.no-ip.com/nic/update?hostname=${noip_host}" --output /dev/null
# wget version
# */15 * * * * wget --quiet --delete-after --auth-no-challenge --user="${noip_user}" --password="${noip_passwd}" --user-agent="wget based script/0.01 pfzim@mail.ru" "http://dynupdate.no-ip.com/nic/update?hostname=${noip_host}"
EOF
crontab -u $user_name .crontab
}
# install console tools
############################
i_mc() {
pacman -S --noconfirm --needed mc man bash-completion sudo cronie vim ethtool
[ -f "/root/.inputrc" ] || cat > "/root/.inputrc" <<- END
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[1~": beginning-of-line
"\e[4~": end-of-line
END
[ -f "${user_home}/.inputrc" ] || cat > "${user_home}/.inputrc" <<- END
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[1~": beginning-of-line
"\e[4~": end-of-line
END
}
# install xbmc plugins
############################
#read -p "Install XBMC plugins (Advanced Launcher) [Y/n]?" result
i_plugins() {
echo SKIP
#wget http://mirrors.xbmc.org/addons/dharma/plugin.program.executor/plugin.program.executor-0.2.5.zip
#wget http://mirrors.xbmc.org/addons/dharma/plugin.program.launcher/plugin.program.launcher-1.10.2.zip
#unzip plugin.program.executor-0.2.5.zip -d /home/xbmc/.xbmc/addons/
#unzip plugin.program.launcher-1.10.2.zip -d /home/xbmc/.xbmc/addons/
# Eden
#wget http://mirrors.xbmc.org/addons/eden/plugin.program.advanced.launcher/plugin.program.advanced.launcher-1.7.6.zip
#unzip plugin.program.advanced.launcher-1.7.6.zip -d /home/xbmc/.xbmc/addons/
#wget http://mirrors.xbmc.org/addons/eden/skin.confluence-vertical/skin.confluence-vertical-2.1.1.zip
#unzip skin.confluence-vertical-2.1.1.zip -d /home/xbmc/.xbmc/addons/
#wget http://mirrors.xbmc.org/addons/eden/plugin.program.rtorrent/plugin.program.rtorrent-1.11.7.zip
#unzip plugin.program.rtorrent-1.11.7.zip -d /home/xbmc/.xbmc/addons/
#wget http://mirrors.xbmc.org/addons/eden/script.transmission/script.transmission-0.7.1.zip
#unzip script.transmission-0.7.1.zip -d /home/xbmc/.xbmc/addons/
# Frodo
#wget http://mirrors.xbmc.org/addons/frodo/plugin.program.advanced.launcher/plugin.program.advanced.launcher-1.7.6.zip
#unzip plugin.program.advanced.launcher-1.7.6.zip -d /home/xbmc/.xbmc/addons/
# wget http://www.gwenael.org/Repository/repository.angelscry.xbmc-plugins/repository.angelscry.xbmc-plugins-1.2.2.zip
# unzip repository.angelscry.xbmc-plugins-1.2.2.zip -d /home/xbmc/.xbmc/addons/
# wget http://www.gwenael.org/Repository/plugin.program.advanced.launcher/plugin.program.advanced.launcher-2.0.10.zip
# unzip plugin.program.advanced.launcher-2.0.10.zip -d /home/xbmc/.xbmc/addons/
#wget http://mirrors.xbmc.org/addons/eden/skin.confluence-vertical/skin.confluence-vertical-2.1.1.zip
#unzip skin.confluence-vertical-2.1.1.zip -d /home/xbmc/.xbmc/addons/
# wget http://mirrors.xbmc.org/addons/frodo/plugin.program.rtorrent/plugin.program.rtorrent-1.11.7.zip
# unzip plugin.program.rtorrent-1.11.7.zip -d /home/xbmc/.xbmc/addons/
# wget http://mirrors.xbmc.org/addons/frodo/script.transmission/script.transmission-0.7.1.zip
# unzip script.transmission-0.7.1.zip -d /home/xbmc/.xbmc/addons/
#wget
#unzip -d /home/xbmc/.xbmc/addons/
#wget
#unzip -d /home/xbmc/.xbmc/addons/
}
# install transmission-daemon
##############################
torrent_media="/mnt/data/torrents"
torrent_sess="/mnt/data/transmission"
i_tbt_pre() {
fg_title="transmission-daemon settings"
while :
do
a_input "Enter path where you want save torrent download" torrent_media
a_input "Enter path where you want save torrent session data" torrent_sess
torrent_media=`echo ${torrent_media} | sed -e "s/\\/*\$//"`
torrent_sess=`echo ${torrent_sess} | sed -e "s/\\/*\$//"`
a_yesno "transmission-daemon settings:\n\nDownloads path: ${torrent_media}\nSession path: ${torrent_sess}\n\nEntered data correct?" result "yes"
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
i_tbt() {
pacman -S --noconfirm --needed transmission-cli
systemctl start transmission
transmission_home=$(getent passwd transmission | cut -d: -f6)
config="${transmission_home}/.config/transmission-daemon/settings.json"
if [ ! -d "${torrent_sess}" ] ; then
mkdir -p "${torrent_sess}"
fi
if [ ! -d "${torrent_sess}/_control" ] ; then
mkdir -p "${torrent_sess}/_control"
chmod a+rwx "${torrent_sess}/_control"
fi
if [ ! -d "${torrent_sess}/resume" ] ; then
mkdir -p "${torrent_sess}/resume"
chmod 755 "${torrent_sess}/resume"
chown -R transmission:transmission "${torrent_sess}/resume"
fi
if [ ! -d "${torrent_sess}/torrents" ] ; then
mkdir -p "${torrent_sess}/torrents"
chmod 755 "${torrent_sess}/torrents"
chown -R transmission:transmission "${torrent_sess}/torrents"
fi
if [ ! -d "${torrent_media}" ] ; then
mkdir -p "${torrent_media}"
chmod a+rwx "${torrent_media}"
fi
mv -fT ${transmission_home}/.config/transmission-daemon/resume "${torrent_sess}/resume"
mv -fT ${transmission_home}/.config/transmission-daemon/torrents "${torrent_sess}/torrents"
rm -rf ${transmission_home}/.config/transmission-daemon/resume
rm -rf ${transmission_home}/.config/transmission-daemon/torrents
ln -sf "${torrent_sess}/resume/" ${transmission_home}/.config/transmission-daemon/resume
ln -sf "${torrent_sess}/torrents/" ${transmission_home}/.config/transmission-daemon/torrents
torrent_media_esc=`echo ${torrent_media} | sed -e "s/\([\\/\\+\\.\\\$]\)/\\\\\\\\\\1/g"`
torrent_sess_esc=`echo ${torrent_sess} | sed -e "s/\([\\/\\+\\.\\\$]\)/\\\\\\\\\\1/g"`
sed -i "s/^\(\\s*{\)/\\1\\n \"watch-dir\": \"${torrent_sess_esc}\\/_control\",\\n \"watch-dir-enabled\": true,/" $config
sed -i "s/\"download-dir\": [^,]*/\"download-dir\": \"${torrent_media_esc}\"/" $config
sed -i "s/\"rpc-authentication-required\": [^,]*/\"rpc-authentication-required\": false/" $config
systemctl enable transmission
systemctl reload transmission
}
# install onboard
############################
#read -p "Install on screen keyboard (onboard) [Y/n]?" result
i_onboard() {
pacman -S --noconfirm --needed onboard
}
# install firefox
############################
#read -p "Install firefox [Y/n]?" result
i_ffox() {
pacman -S --noconfirm --needed firefox
if [ ! -d "${user_home}/scripts" ] ; then
mkdir "${user_home}/scripts"
chmod a+rx "${user_home}/scripts"
fi
if [ ! -f "${user_home}/scripts/firefox.sh" ] ; then
cat > "${user_home}/scripts/firefox.sh" <<- EOF
#!/bin/sh
#${dm} &
#nm-applet --sm-disable &
firefox
#killall -9 ${dm}
EOF
chmod a+rx "${user_home}/scripts/firefox.sh"
fi
}
# install chromium
############################
i_chrome() {
pacman -S --noconfirm --needed chromium
if [ ! -d "${user_home}/scripts" ] ; then
mkdir "${user_home}/scripts"
chmod a+rx "${user_home}/scripts"
fi
if [ ! -f "${user_home}/scripts/chrome.sh" ] ; then
cat > "${user_home}/scripts/chrome.sh" <<- EOF
#!/bin/sh
#${dm} &
#nm-applet --sm-disable &
chromium-browser
#killall -9 ${dm}
EOF
chmod a+rx "${user_home}/scripts/chrome.sh"
fi
}
# configure bluetooth
############################
c_bluez() {
pacman -S --noconfirm --needed bluez bluez-utils
#modprobe hidp
#cat /etc/modules | grep -q -e "^\\s*hidp\\s*\$" || echo "hidp" >> /etc/modules
#/etc/init.d/bluetooth restart
#hci_device="hci0"
systemctl enable bluetooth
systemctl start bluetooth
config="/etc/bluetooth/main.conf"
sed -i -e "/^\\s*AutoEnable\\s*=/ s/^/#/" $config
sed -i -e "/^\\s*\\[Policy\\]/a AutoEnable=true" $config
while :
do
list_items=$(bluetoothctl list | grep -e "^Controller\\s*\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\}\\s" | sed -e "s/^Controller\\s*\(\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\}\)\\s.*\$/\\1/" |
(
n=1
while read line
do
echo "\"${line}\" \"Bluetooth interface ${n}\""
n=$((n+1))
done
echo "rescan \"Scan again for bluetooth adapters...\""
)
)
if [ -z "${list_items}" ] ; then
break
fi
tempfile=`mktemp 2>/dev/null` || tempfile=/tmp/test$$
#trap "rm -f $tempfile" 0 1 2 5 15
eval ${DIALOG} --backtitle \"${back_title}\" --clear --title \"Bluetooth HID device configuration\" --menu \"Select bluetooth inteface\" 20 75 13 ${list_items} 2>$tempfile
if [ $? -ne 0 ] ; then
rm -f $tempfile
break
fi
hci_device=$(cat $tempfile)
rm -f $tempfile
if [ "${hci_device}" != "rescan" ] ; then
#cat >> /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config << EOF
#mode connectable
#modeon connectable
#discovto 0
#pairto 0
#EOF
bluetoothctl -- select ${hci_device}
bluetoothctl power on
#${DIALOG} --backtitle "${back_title}" --clear --title "XBMC configuration" --msgbox "Initialise pairing mode on connected device and press Enter..." 10 75
a_msgbox "Initialise pairing mode on connected device and press Enter..."
#read -p "Initialise pairing mode on connected device and press Enter..." result
echo -ne "\n\nSomtimes bluetooth daemon crash. Then you need switch to other console Alt+F2 and run daemon again 'systemctl start bluetooth' for continue setup.\n\nScanning for bluetooth devices...\n"
{ echo -e "scan on"
sleep 5
echo -e "\nscan off"
echo -e "quit"
} | bluetoothctl
# > /dev/null
bluetoothctl agent on
bluetoothctl default-agent
list_items=$(bluetoothctl devices | sed -e "s/^Device\\s\+//" |
(
n=1
while read line
do
#echo "${n} \"${line}\""
echo $line | sed -e "s/^\\s*\([^ ]\+\)\\s\+\(.*\)\$/\"\\1\" \"\\2\"/"
n=$((n+1))
done
)
)
if [ -n "${list_items}" ] ; then
tempfile=`mktemp 2>/dev/null` || tempfile=/tmp/test$$
eval ${DIALOG} --backtitle \"${back_title}\" --clear --title \"Bluetooth HID device configuration\" --menu \"Select HID device\" 20 75 13 ${list_items} 2>$tempfile
if [ $? -eq 0 ] ; then
dev_addr=$(cat $tempfile)
if [ "${dev_addr}" != "rescan" ] ; then
echo -ne "\n\nSomtimes bluetooth daemon crash. Then you need switch to other console Alt+F2 and run daemon again 'systemctl start bluetooth' for continue setup.\n\nPairing device ${dev_addr}...\n"
bluetoothctl -- pair ${dev_addr}
echo -ne "Trusting...\n"
bluetoothctl -- trust ${dev_addr}
echo -ne "Connecting...\n"
bluetoothctl -- connect ${dev_addr}
fi
fi
rm -f $tempfile
fi
fi
done
}
# configure console
############################
i_cyrillic() {
config="/etc/vconsole.conf"
sed -i -e "/^\\s*KEYMAP\\s*=/ s/^/#/" $config
sed -i -e "/^\\s*FONT\\s*=/ s/^/#/" $config
echo -ne "\nKEYMAP=ru\nFONT=pancyrillic.f16\n" >> $config
}
# install apache and php
############################
i_httpd() {
pacman -S --noconfirm --needed apache php php-apache
}
# install proftpd
############################
# install rutorrent
############################
# install webmin
############################
# install iptables
############################
i_frw() {
systemctl enable iptables
systemctl start iptables
iptables -A PREROUTING -t mangle -p tcp --sport 0:1024 -j TOS --set-tos Minimize-Delay
iptables -A PREROUTING -t mangle -p tcp --sport 1025:65535 -j TOS --set-tos Maximize-Throughput
iptables -A OUTPUT -t mangle -p tcp --dport 0:1024 -j TOS --set-tos Minimize-Delay
iptables -A OUTPUT -t mangle -p tcp --dport 1025:65535 -j TOS --set-tos Maximize-Throughput
iptables-save > /etc/iptables/iptables.rules
#if ! eval "cat /etc/network/interfaces | grep -v -e \"^\\\\s*#\" | grep -q -e \"/etc/iptables.up.rules\"" ; then
# sed -i "/iface\\s*lo/a\\\\tpost-up iptables-restore < /etc/iptables.up.rules" /etc/network/interfaces
#fi
}
# install torrent control through mail
############################
pop3_server="pop.yandex.ru"
pop3_port="995"
pop3_login="username"
pop3_passwd=""
smtp_server="smtp.yandex.ru"
smtp_port="587"
smtp_mail="username@yandex.ru"
smtp_login="username"
smtp_passwd=""
torrent_dir="${torrent_sess}/_control"
ask_settings_fdm_torrent_dir() {
while :
do
a_input "Enter directory for save torrents: " $1
eval "a_yesno \"Directory watched by transmission daemon:\\n\$$1\\n\\nEntered data correct?\" result \"yes\""
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
ask_settings_fdm() {
while :
do
#echo "Mailbox for receive remote commands configuration:"
a_input "Enter POP3S server address [pop.yandex.ru]: " $1
a_input "Enter POP3S server port [995]: " $2
a_input "Enter login for POP3S (user): " $3
a_passwd "Enter password for POP3S: " $4
eval "a_yesno \"Mailbox for receive remote commands configuration:\\nServer: \$$1\\nPort: \$$2\\nLogin: \$$3\\nPassword: *hidden*\\n\\nEntered data correct?\" result \"yes\""
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
ask_settings_msmtp() {
while :
do
#echo "Sendmail settings:"
a_input "Enter SMTP server address [smtp.yandex.ru]: " $1
a_input "Enter SMTP server port [465]: " $2
a_input "Enter mail address for SMTP (username@yandex.ru): " $5
a_input "Enter login for SMTP (username): " $3
a_passwd "Enter password for SMTP: " $4
eval "a_yesno \"Sendmail settings:\\nServer: \$$1\\nPort: \$$2\\nMail: \$$5\\nLogin: \$$3\\nPassword: *hidden*\\n\\nEntered data correct?\" result \"yes\""
if [ "$result" = "Y" -o "$result" = "y" ] ; then
break
fi
done
}
i_fdm_pre() {
fg_title="FDM settings for remote control through mail (POP3/SMTP)"
ask_settings_fdm_torrent_dir torrent_dir
ask_settings_fdm pop3_server pop3_port pop3_login pop3_passwd
ask_settings_msmtp smtp_server smtp_port smtp_login smtp_passwd smtp_mail
torrent_dir=`echo ${torrent_dir} | sed -e "s/\\/*\$//"`
}
i_fdm() {
pacman -S --noconfirm --needed fdm msmtp s-nail cronie
pacman -U --noconfirm --needed mpack-1.6-4-x86_64.pkg.tar.xz
systemctl enable cronie
systemctl start cronie
if [ ! -d "${user_home}/scripts" ] ; then
mkdir "${user_home}/scripts"
chmod a+rx "${user_home}/scripts"
fi
if [ ! -f "${user_home}/scripts/control-reply.sh" ] ; then
cat > "${user_home}/scripts/control-reply.sh" << EOF
#!/bin/sh
if [ "\$#" -ne 1 ] ; then
exit 1
fi
from=\`sed -e "/^.\\\$/q" | grep "^From:" | sed -n -e "s/^From: [^<]*<\(.*\)>\\\$/\1/p;s/^From: \([^<>]\+\)\\\$/\1/p" | head -n 1\`
cc=
if [ -n "\${from}" ] ; then
echo \${from} | grep -qi "^${smtp_mail}"
if [ \$? -ne 0 ] ; then
cc=" -b \"${smtp_mail}\""
fi
else
from="${smtp_mail}"
fi
eval "(\$1) | mailx -s \"Operation result\"\${cc} \"\${from}\""
EOF
chmod 700 "${user_home}/scripts/control-reply.sh"
chown "${user_name}:${user_name}" "${user_home}/scripts/control-reply.sh"
fi
if [ ! -f "${user_home}/.fdm.conf" ] ; then
cat > "${user_home}/.fdm.conf" << EOF
set maximum-size 10M
set delete-oversized
set queue-high 1
set queue-low 0
set purge-after 10
set unmatched-mail keep
action "drop" drop
action "keep" keep
action "inbox" maildir "%h/Mail/INBOX"
action "torrent-add" pipe "munpack -f -q -C ${torrent_dir}/ ; for i in ${torrent_dir}/*.torrent ; do chmod a+r \\\$i ; done"
action "torrent-add-audio" pipe "munpack -f -q -C ${torrent_dir}/audio/ ; for i in ${torrent_dir}/audio/*.torrent ; do chmod a+r \\\$i ; done"
action "torrent-add-video" pipe "munpack -f -q -C ${torrent_dir}/video/ ; for i in ${torrent_dir}/video/*.torrent ; do chmod a+r \\\$i ; done"
action "torrent-list" pipe "${user_home}/scripts/control-reply.sh \"df -h ; transmission-remote -si -st -l\""
action "torrent-alt-on" exec "transmission-remote --alt-speed"
action "torrent-alt-off" exec "transmission-remote --no-alt-speed"
action "poweroff" exec "sudo /usr/bin/shutdown -P +1"
account "xbmc"
pop3s
server "${pop3_server}"
port ${pop3_port}
user "${pop3_login}"
pass "${pop3_passwd}"
new-only