-
Notifications
You must be signed in to change notification settings - Fork 1
/
udoo-config-zenity.sh
executable file
·1298 lines (1041 loc) · 27 KB
/
udoo-config-zenity.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/bash
####################
#
# UDOO Config zenity
#
####################
## Ettore Chimenti @ 2014/04
TITLE="UDOO Configuration Tool"
D="zenity"
PRINTENV="fw_printenv"
SETENV="fw_setenv"
[[ -f /etc/udoo-config.conf ]] && . /etc/udoo-config.conf
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/udoo-functions.sh
error(){
TEXT=$1
[[ -z $TEXT ]] && TEXT="A fatal error has occoured!"
$D --title="$TITLE" --error --text="$TEXT"
exit 1
}
alert(){
TEXT=$1
[[ -z $TEXT ]] && TEXT="An error has occoured! Warning!"
$D --title="$TITLE" --warning --text="$TEXT"
return 0
}
question(){
TEXT=$1
[[ -z $TEXT ]] && TEXT="An error has occoured!"
$D --title="$TITLE" --question --text="$TEXT"
return $?
}
ok(){
TEXT=$1
[[ -z $TEXT ]] && TEXT="Success!"
(( $QUIET )) || $D --title="$TITLE" --info --text="$TEXT"
return 0
}
zdaemonctl(){
local DAEMON
local DAEMONS
local DAEMON_CHOOSE_
local LINE
local DAEMON_CHOOSE
local DAEMON_COMPARE
declare -a DAEMON_CHOOSE DAEMON_COMPARE
# while read LINE
# do
# DAEMON=`echo $LINE | cut -d" " -f1`
#
# if echo $LINE | grep -q on$
# then
# DAEMONS="$DAEMONS TRUE $DAEMON"
# #APPEND TO DAEMON_COMPARE ARRAY
# DAEMON_COMPARE[$I]=$DAEMON
# else
# DAEMONS="$DAEMONS FALSE $DAEMON"
# fi
#
# done < <( daemonctl | sort -V | grep 0 -v )
#SEMPLIFIED VERSION
##
#LIST DAEMONS
##
local QUIET=1 #no "success" message
local I=1
for DAEMON in ${DAEMON_LIST[@]}
do
echo DAE $DAEMON #DEBUG
LINE=`daemonctl $DAEMON`
echo LINE $LINE #DEBUG
echo LINE# ${LINE#* } #DEBUG
if [[ "${LINE#* }" =~ "on" ]]
then
DAEMONS="$DAEMONS TRUE $DAEMON"
#APPEND TO DAEMON_COMPARE ARRAY
DAEMON_COMPARE[$I]=$DAEMON
let I++
echo on_!
elif [[ "${LINE#* }" =~ "off" ]]
then
echo off_!
DAEMONS="$DAEMONS FALSE $DAEMON"
fi
done
echo DAEMONS $DAEMONS #DEBUG
DAEMON_CHOOSE_=`$D --title="$TITLE" \
--width=400 \
--height=300 \
--list \
--checklist \
--hide-header \
--print-column="ALL" \
--column="Checkbox" \
--column="Daemon" \
--text="Check the daemons you want to enable/disable" \
$DAEMONS \
`
#NO CHOICE
(( $? )) && exit 0
#FILL CHOOSED DAEMON ARRAY
#case 1 element
DAEMON_CHOOSE_="$DAEMON_CHOOSE_|"
echo $DAEMON_CHOOSE_ #DEBUG
I=1
DAEMON_CHOOSE[$I]=`echo $DAEMON_CHOOSE_ | cut -d\| -f$I`
while [[ -n ${DAEMON_CHOOSE[$I]} ]]
do
let I++
DAEMON_CHOOSE[$I]=`echo $DAEMON_CHOOSE_ | cut -d\| -f$I`
done
echo LST_ ${DAEMON_LIST[@]} #DEBUG
echo CMP_ ${DAEMON_COMPARE[@]} #DEBUG
echo CHO_ ${DAEMON_CHOOSE[@]} #DEBUG
# A B ACTION
# Y Y Do nothing CMP++ CHO++ LST++
# Y N Turn off CMP++ LST++
# N Y Turn on CHO++ LST++
# N N Do nothing LST++
local LST=0
local CMP=1
local CHO=1
local A
local B
while [[ -n ${DAEMON_LIST[$LST]} ]]
do
echo LST ${DAEMON_LIST[$LST]} #DEBUG
echo CMP ${DAEMON_COMPARE[$CMP]} #DEBUG
echo CHO ${DAEMON_CHOOSE[$CHO]} #DEBUG
#A
if [[ ${DAEMON_LIST[$LST]} == ${DAEMON_COMPARE[$CMP]} ]]
then
A=Y
let CMP++
else
A=N
fi
#B
if [[ ${DAEMON_LIST[$LST]} == ${DAEMON_CHOOSE[$CHO]} ]]
then
B=Y
let CHO++
else
B=N
fi
echo FLG $A $B #DEBUG
[[ $A != $B ]] && if [[ $A == "Y" ]]
then
daemonctl ${DAEMON_LIST[$LST]} off
else
daemonctl ${DAEMON_LIST[$LST]} on
fi
let LST++
done
unset A B
unset QUIET
ok
}
zch_vncpasswd(){
## ch_vncpasswd
local PASSWD
local PASSWR
[[ ! -f $VNCPASSWD ]] && error "$VNCPASSWD not found! Is the VNC server installed?"
PASSWD=`$D --title="$TITLE" --entry --text="Enter new password for remote desktop access" --hide-text`
(( $? )) && exit 1
[[ -z $PASSWD ]] && error "Password cannot be empty"
## DOUBLE CHECK
PASSWR=`$D --title="$TITLE" --entry --text="Re-enter password" --hide-text`
[[ $PASSWD != $PASSWR ]] && error 'Sorry, passwords do not match'
ch_vncpasswd $PASSWD
}
zch_passwd(){
## ch_passwd
local PASSWD
local PASSWR
PASSWD=`$D --title="$TITLE" --entry --text="Enter new user password" --hide-text`
(( $? )) && exit 1
[[ -z $PASSWD ]] && error "Password cannot be empty"
## DOUBLE CHECK
PASSWR=`$D --title="$TITLE" --entry --text="Re-enter password" --hide-text`
[[ $PASSWD != $PASSWR ]] && error 'Sorry, passwords do not match'
ch_passwd $UDOO_USER $PASSWD
}
zch_host(){
local UDOO_OLD=`cat /etc/hostname`
local UDOO_NEW
UDOO_NEW=`$D --title="$TITLE" --entry --text="Enter hostname (current: $UDOO_OLD)" `
(( $? )) && exit 1
UDOO_NEW=`echo $UDOO_NEW | tr -d " \t\n\r" `
[[ -z $UDOO_NEW ]] && error "Hostname cannot be empty"
xhost +
ch_host $UDOO_NEW
}
zntpdate_rtc(){
ntpdate_rtc
}
zch_keyboard(){
#local UDOO_OLD=`grep XKBLAYOUT $KBD_DEFAULT | cut -d = -f 2 | tr -d \"`
local UDOO_OLD=`setxkbmap -query | sed -e 's/^layout:\ *\(\w*\)/\1/p' -n`
local UDOO_NEW
local CURRENT
take_locales(){
#take_locales($current)
#parser
local flag=false
local line
local current=$1
while read line
#read RULES lines
do
#check flag
if [[ $flag != "true" ]]
then
#trash every line until !layout comes
[[ $line =~ '! layout' ]] && \
flag=true
else
#end reading
[[ $line == '' ]] && return
#process line
line=`echo $line | sed -e 's/ \s*/ \"/' -e 's/$/\" /'`
#if line is current layout say TRUE
if [[ ${line% *} == $current ]]
#mark current for sorting
then echo 1_TRUE $line
else echo FALSE $line
fi
fi
done < <(cat $KBD_RULES)
#named pipe
}
UDOO_NEW=`take_locales $UDOO_OLD | sort | sed -e 's/1_//' | \
xargs $D \
--title="$TITLE" \
--list \
--text="Enter new keyboard locale" \
--width=400 \
--height=300 \
--radiolist \
--hide-header \
--print-column=2 \
--column="Checkbox" \
--column="Keycode" \
--column="Locale" \
`
(( $? )) && exit 1
unset take_locales
[[ $UDOO_NEW == $UDOO_OLD ]] && exit 1
#UDOO_NEW=`echo $UDOO_NEW | tr -d " \t\n\r" `
[[ -z $UDOO_NEW ]] && error "LOCALE cannot be empty"
ch_keyboard $UDOO_NEW
}
zch_timezone(){
local UDOO_NEW
local CONTINENT
local ZONE
#current
if [[ -L $ZONEFILE ]]
then
local UDOO_OLD=`readlink $ZONEFILE | cut -d/ -f5-`
elif [[ -f $ZONEFILE ]]
then
local UDOO_OLD=`cat $ZONEFILE | cut -d/ -f2-`
else
local UDOO_OLD=""
fi
local CONT_OLD=${UDOO_OLD%/*}
local ZONE_OLD=${UDOO_OLD#*/}
take_continents()
{
#take_continents($OLD)
local CURRENT=$1
local CONT
for CONT in ${ZONECONTINENTS[@]}
do
if [[ $CONT == $CURRENT ]]
then
echo TRUE \"$CONT\"
else
echo FALSE \"$CONT\"
fi
done
}
CONTINENT=`take_continents $CONT_OLD | xargs $D \
--title="$TITLE" \
--list \
--text="Enter your local zone" \
--width=400 \
--height=300 \
--radiolist \
--hide-header \
--column="Checkbox" \
--column="Keycode" \
`
(( $? )) && exit 1
take_zone()
{
#take_continents($CONTINENT $OLD)
local CONTINENTS=$1
local CURRENT=$2
local CONT
[[ -z $CONTINENTS ]] && error "CONTINENT cannot be empty"
OIFS=$IFS
IFS=$'\n'
for CONT in `ls -1 ${ZONEINFO}${CONTINENTS}`
do
if [[ $CONT == $CURRENT ]]
then
echo TRUE \"$CONT\"
else
echo FALSE \"$CONT\"
fi
done
IFS=$OIFS
}
ZONE=`take_zone $CONTINENT $ZONE_OLD | sed -e 's/_/ /g' | xargs $D \
--title="$TITLE" \
--list \
--text="Enter your local zone" \
--width=400 \
--height=300 \
--radiolist \
--hide-header \
--column="Checkbox" \
--column="Keycode" \
`
(( $? )) && exit 1
UDOO_NEW=`echo $CONTINENT/$ZONE | sed -e 's/\ /_/g' | tr -d "\t\n\r" `
unset take_zone
unset take_continents
[[ -z $UDOO_NEW ]] && error "LOCALE cannot be empty"
ch_timezone $UDOO_NEW
}
expand_fs(){
( [[ -b $MMC ]] && [[ -b $PART ]] ) || error "I can't open $MMC / $PART . Check and edit /etc/udoo-config.conf"
PARTSIZE=`parted $MMC -ms p | grep \^1 | cut -f 3 -d: `
$D --question \
--text="The root filesystem ($PARTSIZE) is going to be resized to SD card maximum available capacity.
This has the potential to cause loss of data.
You are advised to backup your data before proceeding." || exit 1
FIRSTSECT=`parted $MMC -ms unit s p | grep \^1 | cut -f 2 -d: | tr s \ `
LASTSECT_PART=`parted $MMC -ms unit s p | grep \^1 | cut -f 3 -d: | tr s \ `
LASTSECT_MMC=`parted $MMC -ms unit s p | grep $MMC | cut -f 2 -d: | tr s \ `
[[ -f /etc/init.d/resize2fs_once ]] && error "You need to reboot. Now. I keep an eye on you."
if (( $LASTSECT_PART == $LASTSECT_MMC - 1 ))
then
$D --warning --text="The root filesystem ($PART - $PARTSIZE) is already resized to SD card maximum available capacity on the partition table. Trying to do a real resize."
EXPAND=`resize2fs $PART`
(( $? )) && error "$EXPAND"
ok
exit 0
fi
EXPAND=`fdisk $MMC <<FDISK
d
1
n
p
1
$FIRSTSECT
w
FDISK`
EX=$?
(( $EX )) && (( $EX != 1 )) && error "$EXPAND"
# now set up an init.d script from https://github.com/asb/raspi-config
cat <<EOF > /etc/init.d/resize2fs_once
#!/bin/sh
### BEGIN INIT INFO
# Provides: resize2fs_once
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5 S
# Default-Stop:
# Short-Description: Resize the root filesystem to fill partition
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "\$1" in
start)
log_daemon_msg "Starting resize2fs_once" &&
resize2fs $PART &&
rm /etc/init.d/resize2fs_once &&
update-rc.d resize2fs_once remove &&
log_end_msg \$?
;;
*)
echo "Usage: \$0 start" >&2
exit 3
;;
esac
EOF
chmod +x /etc/init.d/resize2fs_once
update-rc.d resize2fs_once defaults
PARTSIZE=`parted $MMC -ms p | grep \^1 | cut -f 3 -d: `
ok "Root partition has been resized in the partition table ($PARTSIZE).\nThe filesystem will be enlarged upon the next reboot."
}
zboot_vram(){
local UDOO_ENV
local GPUMEM
declare -i GPUMEM
UDOO_ENV=`$PRINTENV memory 2>&1`
case $? in
1) error "$UDOO_ENV \nTry resetting the uboot environment" ;;
127) error "$PRINTENV not found" ;;
esac
GPUMEM=`echo $UDOO_ENV | sed -n -e 's/.*gpu_memory\=\([0-9]*\)M.*/\1/p'`
(( $GPUMEM )) || GPUMEM=128
current_video() {
#current_video($OLD)
local CURRENT=$1
local i=0
local src
#from 0 to lenght-1
for src in ${SRC[@]}
do
if [[ $CURRENT == $src ]]
then
echo TRUE $src \"${DESC[$i]}\"
else
echo FALSE $src \"${DESC[$i]}\"
fi
let i++
done
}
local DESC=("1M" "8M" "16M" "32M" "64M" "128M (default)" "256M")
local SRC=(1 8 16 32 64 128 256)
GPUMEM=`current_video $GPUMEM | xargs $D --title="$TITLE" \
--width=400 \
--height=300 \
--list \
--radiolist \
--hide-header \
--hide-column=2 \
--column="Checkbox" \
--column="Number" \
--column="Option" \
--text="Choose a memory value for video card reserved memory:" \
`
(( $? )) && exit 1
unset current_video
boot_vram $GPUMEM
}
zboot_printenv(){
boot_printenv | $D --width=600 --height=500 --title="$TITLE" --text-info --font="monospace,9"
}
zboot_mmcvars(){
local MMCPART
local MMCROOT
local -a DESC=('Partition 1 (default)' \
'Partition 2' \
'Partition 3' \
'Partition 4')
local parts=0
MMCPART=`$PRINTENV mmcpart 2>&1`
(( $? )) && error "$MMCPART"
MMCPART=`echo -n $MMCPART | tail -c1`
#part discovery in /dev/mmcblkp*
[[ -b $MMC ]] || error "$MMC is not a valid MMC device file. Please check your configuration"
local dev
for dev in `ls ${MMC}?* 2>/dev/null`
do
let parts++
[[ $parts -eq 4 ]] && break
done
unset dev
[[ $parts == 0 ]] && error "No partition found on $MMC, check configuration"
if [[ $parts == 1 ]]
then
#set automatically, don't ask
MMCPART=1
else
current_mmc()
{
#current_mmc($CURRENT)
local CURRENT=$1
local part
local i=0
#from 0 to lenght-1
for part in `seq $parts`
do
if [[ $CURRENT == $part ]]
then
echo TRUE $part \"${DESC[$i]}\"
else
echo FALSE $part \"${DESC[$i]}\"
fi
let i++
done
}
MMCPART=`current_mmc $MMCPART | xargs $D \
--title="Choose your MMC boot partition" \
--width=400 \
--height=300 \
--list \
--text="Choose your MMC boot partition" \
--radiolist \
--hide-header \
--hide-column=2 \
--column="Checkbox" \
--column="Number" \
--column="Option"`
(( $? )) && exit 1
unset current_mmc
[[ -z $MMCPART ]] && error "MMCPART cannot be empty"
fi
boot_mmcvars $MMCPART
}
zboot_satavars(){
local SATAPART
local SATAROOT
local SATA
local parts=0
local -a DESC=('Partition 1 (default)' \
'Partition 2' \
'Partition 3' \
'Partition 4')
#Take only the ata- drive (one supported) and read the link
SATA=( `ls ${SATADRIVES}* -1 2>/dev/null | grep "part" -v` )
if [[ ${#SATA[@]} == 1 ]]
then
SATA="/dev/$(readlink $SATA | cut -d/ -f 3)"
elif [[ ${#SATA[@]} > 1 ]]
then
#CHOOSE
local i
for i in ${SATA[@]} ; do echo FALSE $i ; done
local CHOOSE=`$D \
--title="Choose your SATA boot drive" \
--width=400 \
--height=300 \
--list \
--text="It seems you've connected multiple ata devices.
Choose the one you want to configure (if you have a usb device, exit and disconnect it)" \
--radiolist \
--hide-header \
--hide-column=2 \
--column="Checkbox" \
--column="Device" \
--column="Desc" \
$(for i in ${SATA[@]} ; do echo FALSE $i ${i##*ata-} ; done)`
(( $? )) && exit 1
SATA="/dev/$(readlink $CHOOSE | cut -d/ -f 3)"
fi
echo $SATA #DEBUG
#CURRENT
SATAPART=`$PRINTENV satapart 2>&1`
(( $? )) && error "$SATAPART"
SATAPART=`echo -n $SATAPART | tail -c1`
if [[ -b $SATA ]]
then
#part discovery in /dev/sda* if exist
local dev
for dev in `ls ${SATA}? 2>/dev/null`
do
let parts++
[[ $parts -eq 4 ]] && break
done
unset dev
fi
#or choose between 4 possible partition if
if [[ $parts == 0 ]]
then
if [[ -b $SATA ]]
then
#no partitions
parts=4
question "No partition found on $SATA, check configuration.
Be careful on next step. Do you want to continue anyway?"
(( $? )) && exit 1
else
#no drives
parts=4
question "No ata drive found, check configuration.
Be careful on next step. Do you want to continue anyway?"
(( $? )) && exit 1
fi
fi
if [[ $parts == 1 ]]
then
#set automatically
SATAPART=1
question "Found 1 partition on $SATA. Selecting it as the boot partition.
Is this correct?"
(( $? )) && exit 1
else
#or choose
current_sata()
{
#current_sata($CURRENT)
local CURRENT=$1
local part
local i=0
#from 0 to lenght-1
for part in `seq $parts`
do
if [[ $CURRENT == $part ]]
then
echo TRUE $part \"${DESC[$i]}\"
else
echo FALSE $part \"${DESC[$i]}\"
fi
let i++
done
}
SATAPART=`current_sata $SATAPART | xargs $D \
--title="Choose your SATA boot partition" \
--width=400 \
--height=300 \
--list \
--text="Choose your SATA boot partition" \
--radiolist \
--hide-header \
--hide-column=2 \
--column="Checkbox" \
--column="Number" \
--column="Option"`
(( $? )) && exit 1
unset current_sata
fi
[[ -z $SATAPART ]] && error "SATAPART cannot be empty"
boot_satavars $SATAPART
}
zboot_netvars(){
local IPADDR
local SERVERIP
local NFSROOT
local GET_CMD
local BOOT
IPADDR=`$PRINTENV ipaddr 2>&1`
(( $? )) && error "$IPADDR"
IPADDR=`echo $IPADDR | cut -d= -f2`
SERVERIP=`$PRINTENV serverip 2>&1`
(( $? )) && error "$SERVERIP"
SERVERIP=`echo $SERVERIP | cut -d= -f2`
NFSROOT=`$PRINTENV nfsroot 2>&1`
(( $? )) && error "$NFSROOT"
NFSROOT=`echo $NFSROOT | cut -d= -f2`
GET_CMD=`$PRINTENV get_cmd 2>&1`
(( $? )) && error "$GET_CMD"
GET_CMD=`echo $GET_CMD | cut -d= -f2`
FORM=`$D --forms --title="$TITLE" \
--text="Set the environment values for netboot" \
--add-entry="UDOO IP Address (current: $IPADDR) [leave blank for DHCP]" \
--add-entry="NTP Server IP Address (current: $SERVERIP)" \
--add-entry="NTP File System Location (current: $NFSROOT)" \
`
(( $? )) && exit 1
# Test IP address for validity
valid_ip() {
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
#check
local ALERT
local i=0
#IPADDR
IPADDR_OLD=$IPADDR
IPADDR=`echo $FORM | cut -d \| -f 1 | tr -d " "`
if [[ -z "$IPADDR" ]]
then
ALERT[$i]="IP Address will be obtained via DHCP"
let i++
IPADDR="dhcp"
elif ! valid_ip $IPADDR
then
ALERT[$i]="IP Address is not valid, setting previous ($IPADDR_OLD)"
let i++
IPADDR=$IPADDR_OLD
fi
#SERVERIP
SERVERIP_OLD=$SERVERIP
SERVERIP=`echo $FORM | cut -d \| -f 2 | tr -d " "`
if [[ -z "$SERVERIP" ]]
then
ALERT[$i]="SERVERIP cannot be empty, setting previous ($SERVERIP_OLD)"
let i++
SERVERIP=$SERVERIP_OLD
elif ! valid_ip $SERVERIP
then
ALERT[$i]="SERVERIP is not valid, setting previous ($SERVERIP_OLD)"
let i++
SERVERIP=$SERVERIP_OLD
fi
#NFSROOT
NFSROOT_OLD=$NFSROOT
NFSROOT=`echo $FORM | cut -d \| -f 3`
if [[ -z "$NFSROOT" ]]
then
ALERT[$i]="NFSROOT cannot be empty, setting previous ($NFSROOT_OLD)" && \
let i++
NFSROOT=$NFSROOT_OLD
elif [[ "$NFSROOT" =~ [^/a-zA-Z0-9] ]]
then
ALERT[$i]="The specified directory is not valid. \
\nOnly alphanumeric characters are allowed in directories names. \
\nSetting previous ($NFSROOT_OLD)"
let i++
NFSROOT=$NFSROOT_OLD
fi
unset valid_ip
i=0
#Print alerts if any
if [[ -n ${ALERT[@]} ]]
then
question \
"$(for i in `seq 0 ${#ALERT[@]}`; do echo ${ALERT[$i]} ; done )
\nAre you sure?"
(( $? )) && exit 0
fi
local DESC=('DHCP' "TFTP" "NTP")
local SRC=('dhcp' 'tftp' 'ntp')
current_getcmd()
{
#current_getcmd($CURRENT)
local CURRENT=$1
local get_cmd
local i=0
#from 0 to lenght-1
for get_cmd in ${SRC[@]}
do
if [[ $CURRENT == $get_cmd ]]
then
echo TRUE $get_cmd \"${DESC[$i]}\"
else
echo FALSE $get_cmd \"${DESC[$i]}\"
fi
let i++
done
}
GET_CMD=`current_getcmd $GET_CMD | xargs $D \
--title="$TITLE" \
--text="uImage Retrival Method (current: $GET_CMD)" \
--width=400 \
--height=300 \
--list \
--radiolist \
--hide-header \
--print-column=2 \
--hide-column=2 \
--column="Checkbox" \
--column="Method" \
--column="Description" \
`
(( $? )) && exit 1
unset current_getcmd
[[ -z $GET_CMD ]] && error "You have to specify a retrival method"
boot_netvars $IPADDR $SERVERIP $NFSROOT $GET_CMD
}
zboot_default(){
local BOOTSRC
local BOOT
local SRC=('mmc' 'sata' 'net')
local DESC=('MicroSD Card' 'SATA Drive' 'Network FileSystem')
BOOT=`$PRINTENV src 2>&1`
(( $? )) && error "$BOOT"
#remove "src=" from string
BOOT=`echo $BOOT | cut -d= -f2`
current_default()
{
#current_default($CURRENT)
local CURRENT=$1
local i=0
local src
#from 0 to lenght-1
for src in ${SRC[@]}
do
if [[ $CURRENT == $src ]]
then
echo TRUE $src \"${DESC[$i]}\"
else
echo FALSE $src \"${DESC[$i]}\"
fi
let i++
done
}
BOOTSRC=`current_default $BOOT | xargs $D \
--title="Default Boot Drive" \
--width=400 \
--height=300 \
--list \
--text="Choose a default boot drive.
U-Boot will try first to boot up the system from there." \
--radiolist \
--hide-header \
--hide-column=2 \
--column="Checkbox" \
--column="Number" \
--column="Option"`
(( $? )) && exit 1
unset current_default
#set variables
zboot_${BOOTSRC}vars
(( $? )) && exit 1
if [[ -n $BOOTSRC ]]
then
QUIET=1
boot_default $BOOTSRC
unset QUIET
else
exit
fi
}
zboot_script(){
#not useful now
local BOOT
local SCRIPT
local FORM
BOOT=`$PRINTENV src 2>&1`