-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-snuglinux.func
989 lines (903 loc) · 28.5 KB
/
install-snuglinux.func
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
#! /bin/bash
BASE_NAME="install-snuglinux"
CONFIG_FILE=/etc/install-snuglinux.conf
INSTALL_PREFIX=/usr
PO_DIR=${INSTALL_PREFIX}/share/snuglinux
DIR_CHROOT=/mnt
TMP_DIR=/tmp/snuglinux
YN="yn"
# Loading message file
if [ -f "${PO_DIR}/$BASE_NAME.messages" ]; then
. "${PO_DIR}/$BASE_NAME.messages"
else
case $lang in
ru) echo -e "\e[31mОшибка:\e[0m не найден файл $BASE_NAME.messages в '${PO_DIR}'!!!";;
uk) echo -e "\e[31mПомилка:\e[0m не знайдений файл $BASE_NAME.messages у '${PO_DIR}'!!!";;
*) echo -e "\e[31mError:\e[0m file $BASE_NAME.messages not found in '${PO_DIR}'!!!";;
esac
exit 1
fi
if ! [ -f $CONFIG_FILE ]; then
show_message NOT_FOUND_CONFIG $CONFIG_FILE
exit 1
else
source "$CONFIG_FILE"
fi
# To determine in pacman yes
YES_CHAR="$(pacman -Syddw bash --noconfirm | grep '? \[' | cut -d"[" -f2 | cut -d"/" -f1)"
if [ -z "$PROTOCOL_TYPE" ]; then
PROTOCOL_TYPE='https'
fi
#=======================================
ignore_error() {
"$@" 2>/dev/null
return 0
}
#=======================================
system_language() {
local PATH_FILE UP_LANG_SELECT LANG_UTF8 STR_READ
PATH_FILE=$1
if ! [ -f ~/.config/lang.conf ]; then
while [ "${LIST_LANG}" = "${LIST_LANG#*$LANG_SELECT}" ] ; do
STR_READ=`echo "$(tput bold)$(tput setaf 2)Specify the required language: $(tput setaf 1) ${LIST_LANG} $(tput sgr0)"`
read -p "${STR_READ}" LANG_SELECT
if [ "${LIST_LANG}" = "${LIST_LANG#*$LANG_SELECT}" ]; then
echo "Incorrect value"
else
echo -e "LANG_SELECT=${LANG_SELECT}" > ~/.config/lang.conf
echo "OK"
fi
done
fi
source ~/.config/lang.conf
#UP_LANG_SELECT=`echo "${LANG_SELECT^^}"`
#LANG_UTF8=${LANG_SELECT}"_"${UP_LANG_SELECT}.UTF-8
if [ "${LANG_SELECT}" == "en" ]; then
LANG_UTF8="en_US.UTF-8"
elif [ "${LANG_SELECT}" == "uk" ]; then
LANG_UTF8="uk_UA.UTF-8"
elif [ "${LANG_SELECT}" == "ru" ]; then
LANG_UTF8="ru_RU.UTF-8"
fi
if [ -z "${PATH_FILE}" ]; then
#loadkeys ${LANG_SELECT}
export LANG=${LANG_UTF8}
setfont cyr-sun16
if [ $? != 0 ]; then
show_message CONTINUE_PRESS_ANY_KEY
read
return 1
fi
clear
else
#chroot ${PATH_FILE} loadkeys ${LANG_SELECT}
# in chroot setfont throws an error
#chroot ${PATH_FILE} setfont cyr-sun16
chroot ${PATH_FILE} localectl set-keymap us ${LANG_SELECT} --no-convert
if [ $? != 0 ]; then
show_message CONTINUE_PRESS_ANY_KEY
read
return 1
fi
echo -e "LANG=${LANG_UTF8}" > ${PATH_FILE}/etc/locale.conf
echo -e "KEYMAP=${LANG_SELECT}\nFONT=cyr-sun16\nFONT_MAP=" > ${PATH_FILE}/etc/vconsole.conf
sed -i ${PATH_FILE}/etc/locale.gen -e "s|#\(en_US.UTF-8 UTF-8\)|\1|"
sed -i ${PATH_FILE}/etc/locale.gen -e "s|#\(${LANG_UTF8} UTF-8\)|\1|"
#sed -i ${PATH_FILE}/etc/locale.gen -e 's|#\(ru_RU.UTF-8 UTF-8\)|\1|'
chroot ${PATH_FILE} locale-gen
if [ $? != 0 ]; then
show_message CONTINUE_PRESS_ANY_KEY
read
return 1
fi
fi
}
#=======================================
download_updates_func(){
if ! [ -d "$TMP_DIR" ]; then
mkdir "$TMP_DIR"
fi
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/install-snuglinux.func -P $TMP_DIR -nc 2>/dev/null
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/install-partition.func -P $TMP_DIR -nc 2>/dev/null
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/install-video.func -P $TMP_DIR -nc 2>/dev/null
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/install-snuglinux.messages -P $TMP_DIR -nc 2>/dev/null
if [ -f $TMP_DIR/install-snuglinux.func -a -f $TMP_DIR/install-partition.func -a -f $TMP_DIR/install-video.func -a -f $TMP_DIR/install-snuglinux.messages ]; then
PO_DIR=$TMP_DIR
source ${PO_DIR}/install-snuglinux.func
source ${PO_DIR}/install-partition.func
source ${PO_DIR}/install-video.func
source ${PO_DIR}/install-snuglinux.messages
fi
}
#========================
set_options(){
INSTALL_ARCH=`uname -m`
while [ ! -z "$1" ]; do
case $1 in
-v)
show_message CURRENT_VERSION
exit 0
;;
-a)
show_message INSTALL_VERSION_ARM
INSTALL_ARCH="arm"
;;
-h|--help)
show_message SHOW_USAGE
exit 0
;;
*) show_message UNKNOWN_ARG $1
exit 1
;;
esac
shift
done
}
#=======================================
ping_server() {
show_message PING_SERVER $SNUG_SERVER
res=1
/bin/ping ${SNUG_SERVER} -c 3 > /dev/null 2>&1 && res=0
if [ ${res} -ne 0 ]; then
show_message NOT_ACCESS_SERVER $SNUG_SERVER
exit 1
else
show_message OK
fi
}
#=======================================
# Example: install_sevice "1" "2"
# 1 - name sevice
# 2 - do not ask questions (noconfirm)
install_sevice(){
local INSTALLSYSTEMD SERVICE STR_READ
SERVICE="$1"
NOCONFIRM="$2"
if [ "${SERVICE}" == "" ]; then
return 1
fi
echo "${SERVICE}" | grep service > /dev/null
if [ $? != 0 ]; then
echo "${SERVICE}" | grep .socket > /dev/null
if [ $? != 0 ]; then
SERVICE="${SERVICE}.service"
fi
fi
if [ "${NOCONFIRM}" = "y" ]; then
INSTALLSYSTEMD="y"
else
STR_READ=`show_message ADD_DAEMON_AUTOSTART "${SERVICE}"`
while [ "$YN" = "${YN#*$INSTALLSYSTEMD}" ] ; do
read -p "${STR_READ}" INSTALLSYSTEMD
done
fi
if [ "$INSTALLSYSTEMD" == "y" ]; then
echo "${SERVICE}" | grep .socket. > /dev/null
if [ $? == 0 ]; then
chroot $DIR_CHROOT systemctl enable --now "${SERVICE}"
if [ $? = 0 ]; then
show_message DEMON_AUTOSTART ${SERVICE}
else
show_message CONTINUE_PRESS_ANY_KEY
read
return 1
fi
else
chroot $DIR_CHROOT systemctl enable "${SERVICE}"
if [ $? = 0 ]; then
show_message DEMON_AUTOSTART ${SERVICE}
else
show_message CONTINUE_PRESS_ANY_KEY
read
return 1
fi
fi
fi
return 0
}
#=======================================
not_installed_pkg() {
# Example: not_installed_pkg "1" "2"
# 1 - list name pkg
# 2 - path chroot
local list_pkg inst_list path_chroot
inst_list=""
list_pkg=$1
path_chroot=$2
for i in ${list_pkg[@]} ; do
if [ -z "${path_chroot}" ]; then
pkg=`pacman -Qsq "${i}" | grep -x "${i}"`;
else
pkg=`chroot "${path_chroot}" pacman -Qsq "${i}" | grep -x "${i}"`;
fi
if [ -z "${pkg}" ]; then
inst_list="${inst_list} ${i}"
fi
done
echo ${inst_list}
}
#=======================================
# Determines if the package is installed on the operating system
installed_pkg() {
local NAME_PKG PATH_CHROOT INSTALL_PKG
NAME_PKG=$1
PATH_CHROOT=$2
if [ -z "${PATH_CHROOT}" ]; then
INSTALL_PKG=`pacman -Qsq "${NAME_PKG}" | grep -x "${NAME_PKG}"`;
else
INSTALL_PKG=`chroot "${PATH_CHROOT}" pacman -Qsq "${NAME_PKG}" | grep -x "${NAME_PKG}"`;
fi
if [ -z "${INSTALL_PKG}" ]; then
return 0
else
return 1
fi
}
#=======================================
download_pkg(){
local FILE_LISTS TMP_DOWN TYPE PKG_NAME
PKG_NAME=$1
TMP_DOWN="$TMP_DIR/install/types"
FILE_LISTS=${TMP_DOWN}"/lists"
ADD_PACKAGES=
ADD_SEVICES=
ADD_SEVICES_NOCONFIRM=
TYPE=`sed -n ${SELECT_TYPE}p $FILE_LISTS`;
if [ -f ${TMP_DOWN}/${TYPE}/pack/${PKG_NAME} ]; then
rm -f ${TMP_DOWN}/${TYPE}/pack/${PKG_NAME}
fi
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/${TYPE}/pack/${PKG_NAME} -P ${TMP_DOWN}/${TYPE}/pack 2>/dev/null
if [ $? = 0 ]; then
if [ -f ${TMP_DOWN}/${TYPE}/pack/${PKG_NAME} ]; then
source ${TMP_DOWN}/${TYPE}/pack/${PKG_NAME}
fi
fi
}
#=======================================
pacman_install() {
local LIST_PKG
LIST_PKG=$*
LIST_PKG=`echo ${LIST_PKG} | tr ' ' '\n'`
pacinstall --cachedir=${DIR_CHROOT}/var/cache/pacman/pkg/ --sysroot=${DIR_CHROOT} ${LIST_PKG} --yolo
}
#=======================================
# Example: install_pkg "1" "2" "3"
# 1 - name package
# 2 - do not ask questions (noconfirm)
# 3 - systemd service name
install_pkg() {
local INSTALL INSTALL_PKG SYSTEMD STR_READ AMSURE PACMAN_CMD
INSTALL_PKG=$(not_installed_pkg "$1" "$DIR_CHROOT")
NOCONFIRM="$2"
SYSTEMD=$3
INSTALL=0
INSTALL_PKG="${INSTALL_PKG#"${INSTALL_PKG%%[![:space:]]*}"}"
#"
if [ -z "${INSTALL_PKG}" ] ; then
show_message PACKAGE_WAS_PREVIOUSLY_INSTALLED "$1"
return 0
fi
if [ "${NOCONFIRM}" != "y" ]; then
STR_READ=`show_message WANT_INSTALL_PACKAGE "${INSTALL_PKG}"`
while [ "$YN" = "${YN#*$AMSURE}" ] ; do
read -p "${STR_READ}" AMSURE
done
else
show_message INSTALL_PACKAGE "${INSTALL_PKG}"
AMSURE="y"
fi
if [ "${AMSURE}" = "y" ]; then
download_pkg "${INSTALL_PKG}"
pacman_install ${INSTALL_PKG} ${ADD_PACKAGES}
if [ $? = 0 ]; then
show_message SUCCESSFULLY_INSTALLED_PACKAGE "${INSTALL_PKG}"
INSTALL=1
SYSTEMD=`echo ${SYSTEMD} | tr ' ' '\n'`
for s in ${SYSTEMD[@]} ; do
install_sevice "${s}"
done
ADD_SEVICES=`echo ${ADD_SEVICES} | tr ' ' '\n'`
for s in ${ADD_SEVICES[@]} ; do
install_sevice "${s}"
done
ADD_SEVICES_NOCONFIRM=`echo ${ADD_SEVICES_NOCONFIRM} | tr ' ' '\n'`
for s in ${ADD_SEVICES_NOCONFIRM[@]} ; do
install_sevice "${s}" "y"
done
else
show_message FAILED_INSTALL_PACKAGE "${INSTALL_PKG}"
INSTALL=0
show_message CONTINUE_PRESS_ANY_KEY
read
fi
fi
if [ $INSTALL = 0 ]; then
return 1
else
return 0
fi
}
#=======================================
install_network_manager(){
local ARRAY AMSURE INSTALL_X TYPE
installed_pkg "xorg-server" "$DIR_CHROOT"
INSTALL_X="$?"
TMP_DOWN="$TMP_DIR/install/types"
TYPE=`sed -n ${SELECT_TYPE}p $FILE_LISTS`;
FILE_NETWORK="${TMP_DOWN}/${TYPE}/network_manager"
if [ -f $FILE_NETWORK ]; then
if [ -s $FILE_NETWORK ]; then
source $FILE_NETWORK
return 1
fi
fi
ARRAY="0123"
show_message SPECIFY_NETWORK_MANAGER
show_message DO_NOT_INSTALL 0
show_message SYSTEMD_NETWORKD 1
show_message DHCPCD 2
show_message NETWORK_MANAGER 3
show_message WICD 4
STR_READ=`show_message CHOOSE_INSTALLATION_OPTION`
OK=0
while [ "${OK}" = 0 ] ; do
read -p "${STR_READ}" AMSURE
if [ "$ARRAY" = "${ARRAY#*$AMSURE}" ]; then
show_message NOT_RIGHT_VALUE
continue
else
OK=1
fi
done
if [ "$AMSURE" = "0" ]; then
return 0
elif [ "$AMSURE" = "1" ]; then
install_sevice "systemd-networkd.service" "y"
elif [ "$AMSURE" = "2" ]; then
install_pkg "dhcpcd" "y"
install_sevice "dhcpcd.service" "y"
return 1
elif [ "$AMSURE" = "3" ]; then
install_pkg "networkmanager" "y"
install_sevice "NetworkManager-dispatcher" "y"
install_sevice "NetworkManager" "y"
if [ "${INSTALL_X}" = "1" ] ; then
install_pkg "network-manager-applet" "y"
install_pkg "networkmanager-openvpn" "y"
install_pkg "networkmanager-pptp" "y"
install_pkg "networkmanager-vpnc" "y"
install_pkg "networkmanager-openconnect" "y"
fi
install_pkg "bluez"
install_pkg "modemmanager" "n" "ModemManager"
# install_pkg "openresolv" "resolv.conf управления конф. (resolvconf) пакет (openresolv)"
# install_pkg "ppp" "Реализует Point-to-Point протокол для удаленного доступа (ppp)"
return 1
elif [ "$AMSURE" = "4" ]; then
install_pkg "wicd" "y"
install_sevice "wicd" "y"
if [ "${INSTALL_X}" = "1" ] ; then
install_pkg "wicd-gtk" "y"
fi
return 1
fi
}
#=======================================
edit_pacman_conf(){
local PATH_FILE FILE F
PATH_FILE="$1";
FILE="${PATH_FILE}/pacman.conf";
show_message MAKING_CHANGES_TO_FILE "${FILE}"
if [ "$INSTALL_ARCH" = "x86_64" ] ; then
grep "#\[multilib]" $FILE > /dev/null
if [ "$?" = 0 ]; then
F=`sed -n '/\#\[multilib]/{=}' $FILE`
let "F = $F + 1"
sed -i $FILE -e 's|\#\[multilib\]|\[multilib\]|g'
sed -i $FILE -e "$F s|\#Include = \/etc\/pacman.d\/mirrorlist|Include = \/etc\/pacman.d\/mirrorlist|g"
fi
fi
grep "\[snuglinux-core]" $FILE > /dev/null
if [ $? = 1 ]; then
F=`sed -n '/after the header, and they will be used before the default mirrors./{=}' $FILE`
let "F = $F + 1"
sed -i $FILE -e $F"a\[snuglinux-core]"
let "F = $F + 1"
sed -i $FILE -e $F"a\SigLevel = Optional TrustAll"
let "F = $F + 1"
sed -i $FILE -e $F"a\Server = $PROTOCOL_TYPE://${SNUG_SERVER}/repo/core/"'$arch'"\n"
fi
}
#=======================================
edit_pacman_mirrorlist(){
local PATH_FILE
PATH_FILE="$1";
sed -i 's/^# Server/Server/' "${PATH_FILE}/pacman.d/mirrorlist"
}
#=======================================
generating_fstab(){
show_message GENERATING_FSTAB
if [ -f $DIR_CHROOT/etc/fstab ]; then
rm $DIR_CHROOT/etc/fstab
#rename $DIR_CHROOT/etc/fstab $DIR_CHROOT/etc/fstab_old
fi
genfstab -L -p $DIR_CHROOT >> $DIR_CHROOT/etc/fstab
if [ $? != 0 ]; then
show_message FAILED_EXECUTE_COMMAND "genfstab -L -p $DIR_CHROOT >> $DIR_CHROOT/etc/fstab"
exit 1
fi
}
#=======================================
fix_mkinitcpio_conf(){
local hooks_file
hooks_file="hooks-udev.conf";
#hooks_file="hooks-systemd.conf";
if ! [ -d "$TMP_DIR/mkinitcpio" ]; then
mkdir "$TMP_DIR/mkinitcpio"
fi
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/mkinitcpio/$hooks_file -P $TMP_DIR/mkinitcpio -nc 2>/dev/null
cp $TMP_DIR/mkinitcpio/$hooks_file $DIR_CHROOT/etc/mkinitcpio.conf.d/$hooks_file
if ! [ $? = 0 ]; then
show_message FAILED_COPY_FILE "«$hooks_file»";
exit 1;
fi
#show_message MAKING_CHANGES_TO_FILE $DIR_CHROOT/etc/mkinitcpio.conf
#sed -i $DIR_CHROOT/etc/mkinitcpio.conf -e "s|consolefont block filesystems|consolefont block encrypt lvm2 filesystems|"
}
#=======================================
creating_bootable_ram_disk(){
fix_mkinitcpio_conf
show_message CREATING_BOOTABLE_RAM_DISK
run_command_chroot "mkinitcpio -p linux$LINUX_VER"
}
#=======================================
enter_localtime(){
local LOCALTIME NOT_INSTALL_PKG
LOCALTIME="Europe/Kiev"
show_message ENTER_LOCALTIME
NOT_INSTALL_PKG=$(not_installed_pkg "tzdata" "$DIR_CHROOT")
if [ -n "${NOT_INSTALL_PKG}" ] ; then
show_message PACKAGE_NOT_INSTALLED "${NOT_INSTALL_PKG}"
exit 1;
fi
if [ -f $DIR_CHROOT/etc/localtime ]; then
rm $DIR_CHROOT/etc/localtime
fi
ln -s /usr/share/zoneinfo/${LOCALTIME} $DIR_CHROOT/etc/localtime
#chroot $DIR_CHROOT timedatectl set-timezone Europe/Kiev
#chroot $DIR_CHROOT timedatectl set-ntp true
if [ $? != 0 ]; then
show_message FAILED_SET_TIMEZONE
return 1
fi
return 0
}
#=======================================
enter_hostname(){
local STR_READ LOCALHOST
LOCALHOST=""
STR_READ=`show_message ENTER_HOST_NAME`
read -p "${STR_READ}" LOCALHOST
if [ -n "${LOCALHOST}" ]; then
echo -e "${LOCALHOST}" > "$DIR_CHROOT/etc/hostname"
if [ $? != 0 ]; then
show_message FAILED_SET_HOSTNAME
return 1
fi
fi
return 0
}
#=======================================
set_password_user() {
local STR_READ OK USERNAME
USERNAME="$1"
if [ "${USERNAME}" = "" ] ; then
show_message NOT_RIGHT_VALUE
return 1
fi
OK=0;
while [ "$OK" = 0 ] ; do
show_message ENTER_USER_PASSWORD "${USERNAME}"
chroot $DIR_CHROOT passwd "${USERNAME}"
if [ $? = 0 ]; then
OK=1;
else
show_message FAILED_CREATE_PASSWORD
fi
done
}
#=======================================
change_username(){
local STR_READ STR_USER_NAME
USERNAME=$1
if [ "${USERNAME}" = "" ] ; then
return 1
fi
STR_READ=`show_message CHANGE_USERNAME`
read -p "${STR_READ}" STR_USER_NAME
if [ -n "${STR_USER_NAME}" ]; then
chroot $DIR_CHROOT chfn -f "${STR_USER_NAME}" "${USERNAME}"
if [ $? != 0 ]; then
show_message FAILED_CHANGE_FULL_USERNAME
return 1
fi
fi
return 0
}
#=======================================
add_user(){
local STR_READ OK USERNAME
USERNAME="$1"
if [ "${USERNAME}" = "" ] ; then
show_message NOT_RIGHT_VALUE
return 1
fi
chroot $DIR_CHROOT useradd -m -g users -G "audio,games,lp,optical,power,scanner,storage,video,wheel,disk,uucp,dbus" -s /bin/bash "${USERNAME}"
if [ $? != 0 ]; then
show_message FAILED_CREATE_USER "${USERNAME}"
return 1
fi
installed_pkg "xfce4-session" "$DIR_CHROOT"
if [ $? = 1 ]; then
if [ "${USERNAME}" == "root" ]; then
echo -e '#!/bin/sh'"\n\nexec startxfce4" > "$DIR_CHROOT/${USERNAME}/.xinitrc"
else
echo -e '#!/bin/sh'"\n\nexec startxfce4" > "$DIR_CHROOT/home/${USERNAME}/.xinitrc"
fi
fi
change_username "${USERNAME}"
set_password_user "${USERNAME}"
return 0
}
#=======================================
add_users(){
local STR_READ OK USERNAME
show_message CREATING_SYSTEM_USERS
OK=0;
while [ "$OK" = 0 ] ; do
STR_READ=`show_message NEW_USER_LOGIN`
read -p "${STR_READ}" USERNAME
if [ "${USERNAME}" = "i" ]; then
OK=1;
return 0
fi
if [ "${USERNAME}" = "" ] ; then
show_message NOT_RIGHT_VALUE
continue
fi
add_user "${USERNAME}"
done
return 0
}
#=======================================
download_type(){
local STR_N FILE_LISTS TMP_DOWN TYPE ARCH_ARM
if [ "$INSTALL_ARCH" == "arm" ] ; then
ARCH_ARM="-arm"
else
ARCH_ARM=""
fi
show_message LOADING_DATA_SERVER ${SNUG_SERVER}
TMP_DOWN="$TMP_DIR/install/types"
FILE_LISTS=$TMP_DOWN"/lists"
rm -fr $TMP_DOWN
mkdir -p $TMP_DOWN
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/lists$ARCH_ARM -O $TMP_DOWN/lists 2>/dev/null
if [ $? != 0 ]; then
show_message FAILED_LOAD_FILE $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/lists
exit 1;
fi
while read line ; do
let STR_N=$STR_N+1;
TYPE=`sed -n ${STR_N}p $FILE_LISTS`;
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/$TYPE/lang/$LANG_SELECT -P $TMP_DOWN/$TYPE/lang 2>/dev/null
if [ $? != 0 ]; then
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/$TYPE/lang/en -P $TMP_DOWN/$TYPE/lang 2>/dev/null
fi
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/$TYPE/packages -P $TMP_DOWN/$TYPE 2>/dev/null
if [ $? != 0 ]; then
show_message FAILED_LOAD_FILE $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/$TYPE/packages
fi
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/types/$TYPE/network_manager -P $TMP_DOWN/$TYPE 2>/dev/null
done < $FILE_LISTS
}
#=======================================
select_type() {
local STR_N TYPE OK STR_READ TMP_DOWN
select_arm_type
download_type
TMP_DOWN="$TMP_DIR/install/types"
FILE_LISTS=${TMP_DOWN}"/lists"
if ! [ -f ${FILE_LISTS} ]; then
show_message FILE_NOT_FOUND ${FILE_LISTS}
exit 1;
fi
STR_N=0;
while read line ; do
let STR_N=${STR_N}+1;
echo -e "${FC_6}${STR_N}${FC_0} ${FC_3}${line}${FC_0}";
TYPE=`sed -n ${STR_N}p ${FILE_LISTS}`;
if [ -f ${TMP_DOWN}/${TYPE}/lang/${LANG_SELECT} ]; then
cat ${TMP_DOWN}/${TYPE}/lang/${LANG_SELECT}
elif [ -f ${TMP_DOWN}/${TYPE}/lang/en ]; then
cat ${TMP_DOWN}/${TYPE}/lang/en
else
show_message DESCRIPTION_NOT_EXIST
fi
done < ${FILE_LISTS}
OK=0;
STR_READ=`show_message SELECT_TYPE`
while [ "${OK}" = 0 ] ; do
read -p "${STR_READ}" SELECT_TYPE
if [[ "${SELECT_TYPE}" != *[[:digit:]]* ]]; then
show_message NOT_RIGHT_VALUE
continue
fi
TYPE=`sed -n ${SELECT_TYPE}p $FILE_LISTS`;
if ! [ -f $TMP_DOWN/$TYPE/packages ]; then
show_message FILE_NOT_FOUND "$TMP_DOWN/$TYPE/packages"
elif [[ $SELECT_TYPE -le $STR_N && $SELECT_TYPE -ne 0 ]] ; then
OK=1;
else
show_message NOT_RIGHT_VALUE
fi
done
}
#=======================================
install_devices_pkg(){
local TMP_DOWN
if [ "$INSTALL_ARCH" == "arm" ]; then
TMP_DOWN="$TMP_DIR/install/devices"
mkdir -p ${TMP_DOWN}
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/devices/${ARM_MODEL} -O ${TMP_DOWN}/${ARM_MODEL} 2>/dev/null
if [ $? = 0 ]; then
if [ -f ${TMP_DOWN}/${ARM_MODEL} ]; then
source ${TMP_DOWN}/${ARM_MODEL}
fi
fi
fi
}
#=======================================
install_type_pkg() {
local TYPE STR_PKG FILE_PKG VARS IFS_OLD TMP_DOWN
TMP_DOWN="$TMP_DIR/install/types"
TYPE=`sed -n ${SELECT_TYPE}p $FILE_LISTS`;
if ! [ -f ${TMP_DOWN}/${TYPE}/packages ]; then
show_message FILE_NOT_FOUND "${TMP_DOWN}/${TYPE}/packages"
exit 1;
fi
IFS_OLD=$IFS
IFS=$'\n'
FILE_PKG=${TMP_DOWN}/${TYPE}/packages
for line in $(cat ${FILE_PKG}); do
if [ "${line:0:1}" = "#" ]; then
continue
fi
VARS=$(echo $line | tr " " "\n");
STR_PKG=( ${VARS} )
install_pkg "${STR_PKG[0]}" "${STR_PKG[1]}" "${STR_PKG[2]}"
done
IFS=$IFS_OLD
}
#=======================================
run_command_chroot(){
local STR_READ OK COMMAND CONFIRM
OK=0; CONFIRM=0;
COMMAND=$@;
while [ "$OK" = 0 ] ; do
if [ "${COMMAND: -9}" == "confirm=y" ]; then
COMMAND=${COMMAND::${#COMMAND}-9};
CONFIRM=1;
fi
chroot ${DIR_CHROOT} bash -c "${COMMAND}"
if [ ${CONFIRM}==1 ]; then
OK=1;
break;
fi
if ! [ $? = 0 ]; then
AMSURE=
show_message FAILED_EXECUTE_COMMAND ${COMMAND};
STR_READ=`show_message RUN_COMMAND_AGAIN ${COMMAND}`;
read -p "${STR_READ}" AMSURE
if [ ${AMSURE} == "y" ]; then
OK=0;
elif [ ${AMSURE} == "n" ]; then
OK=1;
fi
else
OK=1;
fi
done
}
#=======================================
fix_system_chroot(){
if [[ "$INSTALL_ARCH" == "arm" ]] && [[ $(uname -m) == "x86_64" ]] ; then
# что бы работать под другой архитектурой в chroot нужно скопировать qemu-arm-static в chroot/usr/bin
if ! [ -f "$DIR_CHROOT/usr/bin" ]; then
sudo cp /usr/bin/qemu-arm-static $DIR_CHROOT/usr/bin
if ! [ $? = 0 ]; then
show_message FAILED_COPY_FILE "«qemu-arm-static»";
exit 1;
fi
fi
# что бы в chroot заработал DNS
sudo rm $DIR_CHROOT/etc/resolv.conf
sudo cp -a /etc/resolv.conf $DIR_CHROOT/etc/resolv.conf
LINUX_VER="-$ARM_ARCH";
fi
system_language "$DIR_CHROOT";
edit_pacman_conf "$DIR_CHROOT/etc";
edit_pacman_mirrorlist "$DIR_CHROOT/etc";
pacman_key_init_chroot;
}
#=======================================
pacman_key_init_chroot(){
show_message INITIALIZE_PACMAN_KEY
run_command_chroot "pacman-key --init"
if [ "$INSTALL_ARCH" == "arm" ]; then
run_command_chroot "pacman-key --populate archlinuxarm"
else
run_command_chroot "pacman-key --populate archlinux"
fi
run_command_chroot "pacman -Syu --noconfirm"
}
#=======================================
pacman_key_init(){
show_message INITIALIZE_PACMAN_KEY
killall gpg-agent > /dev/null 2>&1
pacman-key --init && pacman-key --populate archlinux
pacinstall archlinux-keyring --yolo
}
#=======================================
install_basic_packages(){
show_message INSTALLING_BASIC_PACKAGES
if [ "$INSTALL_ARCH" == "arm" ]; then
download_rootfs;
unzip_rootfs;
else
pacstrap $DIR_CHROOT base
if [ "$?" != 0 ]; then
show_message FAILED_INSTALL_PACKAGE "base"
exit 1;
fi
fi
}
#=======================================
unzip_rootfs(){
local STR_READ AMSURE
show_message UNZIP_ROOTFS
cd $TMP_DIR
if [ -f ArchLinuxARM-$ARM_ARCH-latest.tar.gz ]; then
bsdtar -xvpf ArchLinuxARM-$ARM_ARCH-latest.tar.gz -C "$DIR_CHROOT"
if ! [ $? = 0 ]; then
show_message ARCHIVE_UNZIPPING_ERROR "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz»";
AMSURE=
STR_READ=` show_message DELETE_CORRUPTED_FILE "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz»"`;
while [ "$YN" = "${YN#*$AMSURE}" ] ; do
read -p $STR_READ AMSURE
done
if [ $AMSURE == "y" ]; then
rm "ArchLinuxARM-$ARM_ARCH-latest.tar.gz";
if ! [ $? = 0 ]; then
show_message FAILED_DELETE_FILE "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz»";
exit 1;
fi
fi
exit 1;
fi
fi
}
#=======================================
download_rootfs(){
show_message DOWNLOAD_ROOTFS
cd $TMP_DIR
if ! [ -f ArchLinuxARM-$ARM_ARCH-latest.tar.gz.md5 ]; then
wget http://de4.mirror.archlinuxarm.org/os/ArchLinuxARM-$ARM_ARCH-latest.tar.gz.md5 -O ArchLinuxARM-$ARM_ARCH-latest.tar.gz.md5 2>/dev/null
if ! [ $? = 0 ]; then
show_message FAILED_LOAD_FILE "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz.md5»";
exit 1;
fi
fi
if ! [ -f ArchLinuxARM-$ARM_ARCH-latest.tar.gz ]; then
wget http://de4.mirror.archlinuxarm.org/os/ArchLinuxARM-$ARM_ARCH-latest.tar.gz -O ArchLinuxARM-$ARM_ARCH-latest.tar.gz 2>/dev/null
if ! [ $? = 0 ]; then
show_message FAILED_LOAD_FILE "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz»";
exit 1;
fi
fi
md5sum --status -c ArchLinuxARM-$ARM_ARCH-latest.tar.gz.md5
if ! [ $? = 0 ]; then
show_message FAILED_CHECK_MD5SUM_FILE "«ArchLinuxARM-$ARM_ARCH-latest.tar.gz»";
exit 1;
fi
}
#=======================================
download_file_list(){
local FILE_LISTS TMP_DOWN DOWN_FILE
DOWN_FILE=$1;
TMP_DOWN="$TMP_DIR/install"
FILE_LISTS="$TMP_DOWN/$DOWN_FILE"
mkdir -p $TMP_DOWN
wget --quiet --tries=3 -c $PROTOCOL_TYPE://${SNUG_SERVER}/install/$DOWN_FILE -O $FILE_LISTS 2>/dev/null
if [ $? != 0 ]; then
show_message FAILED_LOAD_FILE $PROTOCOL_TYPE://${SNUG_SERVER}/install/$DOWN_FILE
exit 1;
fi
}
#=======================================
# Функция для выбора ARM устройства
select_arm_type() {
local STR_N STR STR_READ FILE_LISTS OK SELECT_TYPE TMP_DOWN
ARM_MODEL=
ARM_ARCH=
if [ "$INSTALL_ARCH" != "arm" ] ; then
return
fi
download_file_list "list-arm-devices";
TMP_DOWN="$TMP_DIR/install"
FILE_LISTS=${TMP_DOWN}"/list-arm-devices"
if ! [ -f ${FILE_LISTS} ]; then
show_message FILE_NOT_FOUND ${FILE_LISTS}
exit 1;
fi
STR_N=0;
while read line ; do
let STR_N=${STR_N}+1;
printf "${FC_6}%-3s${FC_3}%-5s${FC_0} \n" "$STR_N" "${line%% *}"
done < ${FILE_LISTS}
OK=0;
STR_READ=`show_message SELECT_TYPE`
while [ "${OK}" = 0 ] ; do
read -p "${STR_READ}" SELECT_TYPE
if [[ "${SELECT_TYPE}" != *[[:digit:]]* ]]; then
show_message NOT_RIGHT_VALUE
continue
fi
STR=`sed -n ${SELECT_TYPE}p $FILE_LISTS`;
ARM_MODEL=${STR%% *};
ARM_ARCH=${STR##* };
if [[ $SELECT_TYPE -le $STR_N && $SELECT_TYPE -ne 0 ]] ; then
OK=1;
else
show_message NOT_RIGHT_VALUE
fi
done
}
#=======================================
checking_installed_packages(){
local ARM_PKG NOT_INSTALL_PKG
pacman -Sy
if [[ "$INSTALL_ARCH" == "arm" ]] && [[ $(uname -m) == "x86_64" ]] ; then
ARM_PKG="binfmt-qemu-static-sl";
fi
NOT_INSTALL_PKG=$(not_installed_pkg "arch-install-scripts wget sed $ARM_PKG")
if [ -n "$NOT_INSTALL_PKG" ] ; then
pacman -Sy arch-install-scripts wget sed $ARM_PKG;
if [ "$?" = 1 ]; then
show_message PACKAGE_NOT_INSTALLED "$NOT_INSTALL_PKG"
exit 1;
fi
fi
}
#=======================================
clean_install_files(){
if [[ "$INSTALL_ARCH" == "arm" ]] ; then
run_command_chroot "userdel -r alarm"
fi
if [[ "$INSTALL_ARCH" == "arm" ]] && [[ $(uname -m) == "x86_64" ]] ; then
rm $DIR_CHROOT/usr/bin/qemu-arm-static
fi
run_command_chroot "pacman -Scc --noconfirm"
}
#=======================================
system_reboot(){
local KEY AMSURE STR_READ
KEY="qr"
STR_READ=`show_message SYSTEM_REBOOT`
while [ "$KEY" = "${KEY#*$AMSURE}" ] ; do
read -p "${STR_READ}" AMSURE
done
if [ $AMSURE == "r" ]; then
reboot
fi
}