-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbootstrap
executable file
·1657 lines (1368 loc) · 53.2 KB
/
bootstrap
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
#
# _______ __ __
# | _ | |__.-----. .----| |--.
# |. |___| | | | | __| |
# |. __) |__|__|__| |____|__|__|
# |: |
# |::.| FreeBSD in a chroot
# `---` -------------------
#
# finch-bootstrap:
# Install, Update, Move, and Uninstall Finch FreeBSD.
#
# Created by:
# Dreamcat4 - [email protected] (C 2014). FreeBSD License.
# Please fork this repo / upload improvements to github.com.
#
# Tarball URL
tarball_url="https://github.com/dreamcat4/finch/archive/master.tar.gz"
tarball_file="finch-master.tar.gz"
# gh_api_token="0000000000000000000000000000000000000000"
# get_param_token="&access_token=$gh_api_token"
# Set counters
num_abort="0"
num_error="0"
num_warning="0"
usage ()
{
cat <<- "EOF"
Usage:
$ finch-bootstrap "command" [--options]
Example:
$ finch-bootstrap install --dir "/mnt/disk0/finch"
Commands:
install - Install a new copy of Finch FreeBSD.
uninstall - Uninstall a copy of Finch FreeBSD.
update - Update the finch command and finch scripts to the latest version.
move - Move/rename the paths/locations to this copy of finch.
Options:
-d, --dir "{realpath}"
The full installation "/path/to/finch". Defaults to "$PWD/finch".
~ if not set a new subdirectory will be created here named "finch".
Internally referred to as "$finch_realpath" - the chroot directory.
-y, --yes
Do not prompt for user confirmation before continuing. Useful
for unattended operations or launching from other scripts.
-f, --force
Do not exit when a potential problem is encountered. Continue
regardless of all warnings and errors.
-e, --dest-dir "{dest_dir}"
(move) A destination path where to move this installation.
Where the current location is specified by "--dir {realpath}".
-t, --txz-distfiles-dir "{txz_distfiles_dir}"
(install) A local folder from which to obtain the FreeBSD ".txz"
distribution files from ("distfiles"), "base.txz"... etc. With this
option *nothing* will be downloaded from ftp://ftp.freebsd.org.
You will be locally responsible for ensuring a correct set of
distribution files is present. All "*.txz" files found in the folder
will be unpacked / installed to the target directory ("--dir {dir}").
-x, --debug
Debugging output. Switches on "set -x" to echo all commands.
-h, --help
Display this message and exit.
Bugs:
Can be reported at http://dreamcat4.github.io/finch/support
Created by:
Dreamcat4, [email protected] (C 2014). FreeBSD License.
EOF
exit 1
}
parse_args ()
{
finch_command="0"
if [ "$#" -gt "0" ]; then
for arg in "$@"
do
case "$arg" in
install) finch_command=`expr $finch_command + 1`; __command="install" ;;
move) finch_command=`expr $finch_command + 1`; __command="move" ;;
update) finch_command=`expr $finch_command + 1`; __command="update" ;;
uninstall) finch_command=`expr $finch_command + 1`; __command="uninstall" ;;
-d|--dir) next_is_finch_realpath="1" ;;
-y|--yes) no_prompt="1" ;;
-f|--force) force="1" ;;
-e|--dest-dir) next_is_finch_dest_dir="1" ;;
-t|--txz-distfiles-dir) next_is_finch_txz_distfiles_dir="1" ;;
-x|--debug) finch_debug="1" ;;
-h|--help) usage ;;
*)
if [ "$next_is_finch_realpath" ]; then
finch_realpath="$arg"
unset next_is_finch_realpath
elif [ "$next_is_finch_txz_distfiles_dir" ]; then
finch_txz_distfiles_dir="$arg"
unset next_is_finch_txz_distfiles_dir
elif [ "$next_is_finch_freebsd_version" ]; then
finch_freebsd_version="$arg"
unset next_is_next_is_finch_freebsd_version
elif [ "$next_is_finch_dest_dir" ]; then
finch_dest_dir="$arg"
unset next_is_finch_dest_dir
else
echo "error (1): unrecognised command line parameter - \"$arg\". \`finch-bootsrap --help\` for more info."
exit 1
fi
;;
esac
done
else
usage;
fi
if [ "$finch_command" = "0" ]; then
echo "error (1): No command specified. \`finch-bootsrap --help\` for more info."
exit 1
fi
if [ "$finch_command" -gt "1" ]; then
echo "error (1): You must specify only ONE command at a time. \`finch-bootsrap --help\` for more info."
exit 1
fi
if [ "$finch_debug" ]; then
set -x
fi
if [ ! "$finch_realpath" ]; then
finch_realpath="$PWD/finch"
fi
if [ "$finch_realpath" != "/" ]; then
finch_realpath="${finch_realpath%/}"
fi
if [ "$finch_txz_distfiles_dir" != "/" ]; then
finch_txz_distfiles_dir="${finch_txz_distfiles_dir%/}"
fi
if [ "$finch_dest_dir" != "/" ]; then
finch_dest_dir="${finch_dest_dir%/}"
fi
}
cat_welcome_banner ()
{
cat | xargs -0 printf <<- "EOF"
\033[1;38m
-= Welcome to =-
-------------------------------------
_______ __ __
| _ | |__.-----. .----| |--.
|. |___| | | | | __| |
|. __) |__|__|__| |____|__|__|
|: |
|::.| FreeBSD in a chroot
`---` -------------------
\033[0m
EOF
}
cat_ascii_art ()
{
cat | xargs -0 printf <<- EOF
\033[1;38m
11111
11 100000000000001
1000000000001 100000000001110000001
1000000001 10001 100001 0011001 1000001
100 1001 0001 10001 01 100 00001 10001
101 1001 000 10001 001 000 0001 1100001
10000 1000 1001 1001 100 0000 10011111000000001
1000001 1001 1001 1001 1001 10001 900000000110001
1000001 000 000 1001 1001 1000 00001 101
100001 0001 1001 0001 1001 0000 0000 1001
10000 1000 001 10001 10001 10001 10001
10000 1001 10011 0001 10000000001
0000 1001 1000000000111 1001 10000000001
0000 1001 11000000000000001110001 1000 100001
1001 11 111000000000001 10001 10001
0001 0001 100000000011 10001
11 1000 1011 1000 10000111100000000001
000000111 10001 1110000001 1000 00000 11001
10000000000000000000000000000001 10001 100001
100 110000000000000111 10001 1000001
001 100000000000001
10001 100000001
100001 1001
1000001111 101 000
100000000001 1000 0001
110000001 100001 10001
10000000000000 0000
1000001110001 100001
100011 100000
10000000111000000001
0000000000000001
10000001 1001
000001 1001 10000
100001 10001 10001
10000 10001 0000 1001
0000 100011000 100001
10001 100000 10001
00000110000001 100001 1100111111111
111000000000111000000111111000000000000001
1110000000011 100001 10000001 11111001
1100000000011 00000000110000000000000000000010001
100000000001 110000011101 10011
1000011 110000001 1
100000001
1100000001
1100000011
1000011
1
\033[0m
EOF
}
warn ()
{
printf '\033[1;30;43m WARNING \033[0m\033[1;37m*********************************************************************\033[0m\n'
}
err ()
{
printf '\033[1;37;41m ERROR \033[0m\033[1;37m*********************************************************************\033[0m\n'
}
hr ()
{
printf '\033[1;37m******************************************************************************\033[0m\n'
}
wrap ()
{
# Settings
# lead_indent_first_para="1"
lead_indent_remaining_paras="1"
# preserve_lead_indent_first_para="1"
# preserve_lead_indent_remaining_paras="1"
# if [ "$lead_indent_all_paras" ]; then
# lead_indent_first_para="1"
# lead_indent_remaining_paras="1"
# fi
# if [ "$preserve_lead_indent_all_paras" ]; then
# preserve_lead_indent_first_para="1"
# preserve_lead_indent_remaining_paras="1"
# fi
set -f # Turn off shell globbing
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<- "EOF"
wrap:
Wrap text with a hanging indent.
Usage:
cat file | wrap
cat file | wrap "$width"
cat file | wrap "$width" "$indent"
Where:
default_width="78"
default_indent="0"
EOF
return 1
fi
default_width="78"
default_indent="0"
if [ "$1" ]; then
local MARGIN="$1"
shift
if [ "$1" ]; then
local INDENT="$1"
shift
else
local INDENT="$default_indent"
fi
else
local MARGIN="$default_width"
local INDENT="$default_indent"
fi
first_para="1"
local REMAINING=$MARGIN
while read line
do
if [ "$line" ]; then
if [ "$first_para" ]; then
if [ "$lead_indent_first_para" ]; then
printf "%${INDENT}s" ""
elif [ "$preserve_lead_indent_first_para" ]; then
# First line of first paragraph - preserve any existing indentation (don't auto-indent)
lead="$(echo "$line" | grep -o "[[:space:]]*")"
printf "%s" "$lead"
REMAINING=$(( $MARGIN - ${#lead} ))
fi
unset first_para
fi
for word in $line
do
if [ $(( $REMAINING - ${#word} )) -ge 0 ]; then
printf "%s " "${word}"
REMAINING=$(( $REMAINING - ${#word} - 1 ))
else
printf "\n%${INDENT}s%s " "" "$word"
REMAINING=$(( $MARGIN - ${#word} - ${INDENT} - 1 ))
fi
done
else
echo ""
echo ""
if [ "$lead_indent_remaining_paras" ]; then
# Indent the first line of all 2nd, 3rd, ... paragraphs
printf "%${INDENT}s" ""
REMAINING=$(( $MARGIN - ${INDENT} ))
elif [ "$preserve_lead_indent_remaining_paras" ]; then
# First line of 2nd, 3rd paragraph - preserve existing indentation (don't auto-indent)
lead="$(echo "$line" | grep -o "[[:space:]]*")"
printf "%s" "$lead"
REMAINING=$(( $MARGIN - ${#lead} ))
else
REMAINING=$(( $MARGIN ))
fi
fi
done
echo "" # Add trailing newline
set +f # Turn shell globbing back on
}
check_architecture ()
{
if [ `uname -m` = "i386" ]; then
echo "* The architecture of this system is: \"`uname -m`\""
echo "\"\i386\"... Phhah!"
echo ""
warn;
echo "You are on a 32-bit operating system. You're recommended to at least *try* to"
echo "reinstall FreeBSD as a 64-bit build. Your hardware *might* support it. It is"
echo "now more beneficial (in terms of software compatibility) to be running 64-bits."
echo ""
flag_warning;
elif [ ! `uname -m` = "amd64" ]; then
echo "* The architecture of this system is: \"`uname -m`\""
err;
echo "This is not a supported architecture. We were expecting \"i386\" or \"amd64\"!"
echo ""
flag_error;
fi
}
check_localtime ()
{
if [ ! -e "/etc/localtime" ]; then
echo ""
warn;
echo "You don't seem to have the file \"/etc/localtime\". It is recommended to set"
echo "your local timezone from \"/usr/share/timezone\" before installing. Example:"
echo ""
echo "cp \"/usr/share/zoneinfo/Etc/GMT\" \"/etc/localtime\""
echo ""
flag_warning;
fi
}
check_freebsd_version ()
{
major_ver=`uname -r | sed -e "s/-.*$//" -e "s/\..*$//"`
minor_ver=`uname -r | sed -e "s/-.*$//" -e "s/^.*\.//"`
_rel="$(uname -r | cut -d- -f2)"
if [ "$_rel" = "RELEASE" ]; then
if [ "`uname -iv | grep -i freenas`" ] || [ "`uname -iv | grep -i nas4free`" ]; then
if [ "$major_ver" -lt "9" ]; then
freebsd_too_old="1"
fi
if [ "$major_ver" -eq "9" ] && [ "$minor_ver" -lt "2" ]; then
freebsd_too_old="1"
fi
if [ "$freebsd_too_old" ]; then
echo "* The version of FreeBSD on this system is: \"FreeBSD-`uname -r`\""
echo ""
err;
echo "This FreeBSD RELEASE is no longer supported by this script. Reason: pkg-ng."
echo "Versions of FreeBSD prior to 9.2-RELEASE are emphatically not supported."
echo "You should first upgrade the FreeBSD version of your host system. Then retry."
echo "Newer versions of FreeBSD are publicly available. Go'on with ye, go'on I say!"
echo ""
flag_error;
fi
else
if [ "$major_ver" -lt "10" ]; then
echo "* The version of FreeBSD on this system is: \"FreeBSD-`uname -r`\""
echo ""
err;
echo "This FreeBSD RELEASE is no longer supported by Finch. Reason: out of date."
echo "Versions of FreeBSD prior to 10.0-RELEASE of GENERIC are no longer supported."
echo "You should first upgrade the FreeBSD version of your host system. Then retry."
echo "Newer versions of FreeBSD are publicly available. Go'on with ye, go'on I say!"
echo ""
flag_error;
fi
fi
elif [ "$_rel" = "STABLE" ] || [ "$_rel" = "CURRENT" ]; then
echo "* The version of FreeBSD on this system is: \"FreeBSD-`uname -r`\""
echo " Perhaps this is a beta ?"
echo ""
err;
echo "Installation onto $_rel branches of FreeBSD is not supported."
echo " * You cannot run \"freebsd-update\" (to apply binary patches)."
echo ""
echo "For testing / throw away only. Do not use for production."
echo "Upgrade your platform to a \"RELEASE\" version of FreeBSD."
echo ""
flag_error;
else
echo "* The version of FreeBSD on this system is: \"FreeBSD-`uname -r`\""
echo ""
err;
if [ ! "$finch_txz_distfiles_dir" ]; then
echo "This is not a known / recognized version of FreeBSD. So we cannot be sure"
echo "of the appropriate download URL to get the base system files (\"base.txz\")."
echo ""
fi
echo "Installation of a non-RELEASE version is not encouraged or recommended."
echo "This version cannot be easily upgraded in future with \"freebsd-update\"."
echo "If possible, upgrade your kernel version to something marked \"RELEASE\"."
echo ""
flag_error;
fi
}
check_paths ()
{
if [ ! `echo "$finch_realpath" | grep "^/"` ]; then
err;
echo "The variable \$finch_realpath must be a fully specified path (start with a \"/\")"
echo ""
flag_error;
elif [ -d "$finch_realpath" ] && [ "`ls "$finch_realpath"`" ]; then
err;
echo "The directory \"$finch_realpath\" already exists and is non-empty."
echo "It is not WISE to mixup a fresh new FreeBSD installation with other files."
echo "The better idea would be to specify an EMPTY folder and install into that."
echo ""
flag_error;
elif [ -e "$finch_realpath" ] && [ ! -d "$finch_realpath" ]; then
err;
echo "There is already a file named \"$finch_realpath\"."
echo "So we cannot use that location for our FreeBSD installation."
echo ""
flag_error;
fi
}
check_filesystem ()
{
filesystem_path="$finch_realpath"
while [ ! -e "$filesystem_path" ]
do
filesystem_path=`dirname "$filesystem_path"`
done
echo "* Querying filesystem at \"$filesystem_path\""
echo ""
filesystem=`df -m -T $filesystem_path | awk 'NR==2 {print $1}'`
fs_type=`df -m -T $filesystem_path | awk 'NR==2 {print $2}'`
size=`df -m -T $filesystem_path | awk 'NR==2 {print $3}'`
used=`df -m -T $filesystem_path | awk 'NR==2 {print $4}'`
available=`df -m -T $filesystem_path | awk 'NR==2 {print $5}'`
capacity=`df -m -T $filesystem_path | awk 'NR==2 {print $6}'`
mountpoint=`df -m -T $filesystem_path | awk 'NR==2 {print $7}'`
size_05g="5120"
size_10g="10240"
size_50g="51200"
# Check if there is enough free hdd space
if [ "$available" -lt "$size_05g" ]; then
echo "* $available Megabytes free disk space."
echo ""
warn;
echo "You don't seem to have enough disk space to install Finch FreeBSD. This is a full-blown distribution, containing kernel, src and ports tree. On our test system (FreeBSD 9.2, amd-64) a fresh install came to 4251 MB. However you currently only have \"$available\" megabytes of free space." | wrap "76"
echo ""
flag_warning;
elif [ "$available" -lt "$size_10g" ]; then
echo "* $available Megabytes free disk space."
echo ""
warn;
echo "You seem to have low disk space on the volume where you want to install."
echo "This is a full-blown distribution, containing kernel, src and ports tree."
echo "On our test system (FreeBSD 9.2, amd-64) a fresh install came to 4251 MB."
echo "Currently have a total of \"$available\" megabytes of free space."
echo ""
flag_warning;
fi
# Check that we are installing FreeBSD onto a FreeBSD supported filesystem
if [ `echo "$filesystem" | grep "/dev/md"` ]; then
echo "* Filesystem type is \"$fs_type\" for this volume."
echo ""
err;
echo "The device you have selected to install onto appears to be a RAMDISK."
echo "Perhaps you are in the wrong folder, or forgot to specify the correct"
echo "installation directory with the \"-d\" command line option?"
echo ""
flag_error;
elif [ "$fs_type" = "devfs" ]; then
echo "* Filesystem type is \"$fs_type\" for this volume."
echo ""
err;
echo "The path \"$filesystem_path\" seems to be situated on a devfs mounted path."
echo "Hey! Seriously? Thats for special block devices only! IT'S NOT WORTH IT MAN!"
echo "You need to mount a filesystem before you can specify a folder location on it."
echo ""
flag_error;
elif [ "$fs_type" = "nullfs" ]; then
echo "* Filesystem type is \"$fs_type\" for this volume."
echo ""
warn;
echo "The path \"$filesystem_path\" seems to be located on nullfs mounted folder."
echo "Therefore we cannot determine if the filesystem is valid. It should be either"
echo "UFS or ZFS - where to install FreeBSD... you might already be aware of this"
echo "requirement."
echo "You can either cd into the full real path, and rerun this installer. Or you"
echo "can specify the full real path with \"-d\" command line option."
echo ""
flag_warning;
elif [ "$fs_type" = "zfs" ]; then
echo "Filesystem type is \"$fs_type\" for this volume. FreeBSD supports installations on the zfs filesystem." | wrap "78"
echo ""
elif [ "$fs_type" = "ufs" ]; then
echo "Filesystem type is \"$fs_type\" for this volume. FreeBSD supports installations on the ufs filesystem. So long as it's not a slow usb flash drive. HDDs & SSDs only please." | wrap "78"
echo ""
else
echo "* Filesystem type is \"$fs_type\" for this volume."
echo ""
warn;
echo "You seem to be on a filesystem which isn't either UFS or ZFS. This may lead"
echo "to unknown problems occuring further down the road. FreeBSD requires that"
echo "the root filesystem (\"/\") provides cetain features, such as ACL permission"
echo "etc. etc."
echo "Perhaps you are aware of possible issues but would like to continue regardless."
echo ""
flag_warning;
fi
}
check_root ()
{
echo "Checking access privileges..."
if [ `id -u` = 0 ]; then
echo "Ok."
echo ""
else
echo ""
err;
echo "User \"`id -n -u`\" - your UID isnt \"0\" (insufficient permissions)."
echo "You must be the root user (su or sudo) to run this installer script."
echo ""
flag_error;
fi
}
check_users ()
{
echo "Checking administrator accounts..."
wheel_users="`pw group show -n wheel | cut -d ":" -f 4 | sed -e "s/,/ /g"`"
wheel_users="`echo $wheel_users | sed -e "s/^root *//" | sed -e "s/ root//g"`"
if [ ! "`uname -iv | grep -i nas4free`" ] && [ ! "`uname -iv | grep -i pfsense`" ]; then
# root isn't always printed by $ pw group show cmd, so we ensure to insert it manually
wheel_users="root $wheel_users"
fi
if [ "`uname -iv | grep -i pfsense`" ]; then
wheel_users=""
fi
for user in $wheel_users
do
# echo "$user"
user_shell=`pw user show $user | cut -d ":" -f 10`
if [ "${user_shell%bash}" = "$user_shell" ] && [ "${user_shell%/sh}" = "$user_shell" ]; then
if [ ! "$____first_newline_printed" ]; then
echo "" # in for loop - messy spacing
____first_newline_printed="1"
fi
if [ "${user_shell%/csh}" = "$user_shell" ]; then
warn;
echo "Admin user: \"$user\" - the shell: \"$user_shell\" may not be supported by Finch."
else
warn;
echo "Admin user: \"$user\" - the shell: \"$user_shell\" is not supported by Finch."
fi
echo ""
echo "The Finch login profile requires a POSIX.2 or Bourne-type compatible shell."
echo "Please use Bash (or FreeBSD's /bin/sh). Those are the shells we test with."
echo ""
if [ "`uname -iv | grep -i nas4free`" ] || [ "`uname -iv | grep -i freenas`" ]; then
echo "Full instructions to change $user's login shell can be found at:"
echo "* http://dreamcat4.github.io/finch/install/#toc_12"
echo ""
else
echo "You can change $user's shell with the following command:"
echo ""
if [ -x "/usr/local/bin/bash" ]; then
echo " $ \"pw user mod $user -s /usr/local/bin/bash\""
else
echo "pw user mod $user -s /bin/sh"
fi
echo ""
fi
if [ "${user_shell%/csh}" = "$user_shell" ]; then
echo "Alternatively, your shell *might* have a POSIX.2 / Bourne shell compatibility"
echo "mode. Then that mode should be enabled. In addition, the file /etc/profile"
echo "must be sourced during shell login. PLease refer to the shell's documentation."
echo ""
fi
flag_warning;
fi
done
if [ ! `id -u` = 0 ]; then
# echo "Ok."
# echo ""
# else
if [ ! "$____first_newline_printed" ]; then
echo "" # in for loop - messy spacing
____first_newline_printed="1"
fi
err;
echo "User \"`id -n -u`\" - your UID isnt \"0\" (insufficient permissions)."
echo "You must be the root user (su or sudo) to run this installer script."
echo ""
flag_error;
fi
echo "Done."
echo ""
}
flag_error ()
{
num_error=`expr $num_error + 1`
num_abort=`expr $num_abort + 1`
}
flag_warning ()
{
num_warning=`expr $num_warning + 1`
num_abort=`expr $num_abort + 1`
}
check_required_programs()
{
echo "Checking for required programs..."
if [ ! -x "/usr/local/bin/sudo" ]; then
echo ""
err;
echo "Could not find \`sudo\`. We looked for \"/usr/local/bin/sudo\"."
echo "You must install sudo onto your system BEFORE installing finch."
echo ""
flag_error;
fi
if [ ! -x "/usr/local/bin/bash" ]; then
echo ""
err;
echo "Could not find \`bash\`. We looked for \"/usr/local/bin/bash\"."
echo "You should install the bash shell before installing finch."
echo ""
flag_error;
fi
if [ -x "/usr/local/bin/sudo" ] && [ -x "/usr/local/bin/bash" ]; then
echo "Done."
fi
}
preflight_checks ()
{
echo "Running preflight checks..."
echo ""
check_paths;
check_architecture;
check_freebsd_version;
check_filesystem;
check_localtime;
check_users;
if [ ! "`uname -iv | grep -i freenas`" ] && [ ! "`uname -iv | grep -i nas4free`" ] && [ ! "`uname -iv | grep -i pfsense`" ]; then
freebsd_major_ver=`uname -r | sed -e "s/-.*$//" -e "s/\..*$//"`
if [ "$freebsd_major_ver" -lt "10" ]; then
check_required_programs;
fi
fi
}
print_installer_actions ()
{
hr;
echo "Installation folders & files"
hr;
echo "Is this your desired configuration ?"
echo ""
echo " * What we are going to install: \"FreeBSD-`uname -r`\""
echo ""
if [ "$finch_txz_distfiles_dir" ]; then
echo " * Distfiles will be taken from: \"$finch_txz_distfiles_dir\""
echo ""
else
echo " * Distfiles will be taken from: \"ftp://ftp.freebsd.org\""
echo ""
fi
echo " * FreeBSD will be installed to: \"$finch_realpath\""
echo ""
if [ "`uname -iv | grep -i nas4free`" ] || [ "`uname -iv | grep -i pfsense`" ]; then
if [ "`uname -iv | grep -i nas4free`" ]; then
_platform="NAS4Free"
fi
if [ "`uname -iv | grep -i pfsense`" ]; then
_platform="pfSense"
fi
printf '\033[1;37;44m NOTICE \033[0m\033[1;37m**********************************************************************\033[0m\n'
echo "Finch will automatically set your root shell to be BASH."
echo ""
echo "We prefer to leave this decision to the user but $_platform does not let you configure your root account. The Finch login profile requires a POSIX.2 compliant shell so we set your root shell to be BASH from now onwards. Apologies for any inconvenience." | wrap "72"
echo ""
fi
if [ "$finch_debug" ]; then
# Print the list of files to be installed eg
# $finch_realpath/usr/local/man/man8/finch.8.gz
# $finch_realpath/finch/etc/postinit
echo "* In the next step we will create the following files:"
echo ""
export finch_realpath="$finch_realpath" # For awk ENVIRON[] to work
SSL_NO_VERIFY_PEER=YES fetch -q -o - "$tarball_url" | tar -tzf - | grep --only-matching -e "/chroot.*[^/]$" | grep --only-matching -e "[^^/chroot].*" | awk '{ print " "ENVIRON["finch_realpath"]"/"$1}'
# And list any distfiles that will be copied into there
if [ "$finch_txz_distfiles_dir" ]; then
for txz_distfile in "$finch_txz_distfiles_dir/"*.txz
do
echo " $finch_realpath/var/distfiles/finch/${txz_distfile#$finch_txz_distfiles_dir/}"
done
fi
echo ""
fi
hr;
echo "READY TO INSTALL FINCH SCRIPTS ?"
hr;
echo "This will prepare the target installation folder with essential FINCH scripts."
if [ "$finch_txz_distfiles_dir" ]; then
echo "And copy the local distfiles folder."
fi
echo ""
echo " * Finch Download URL:"
echo " $tarball_url"
echo ""
echo "OK to proceed ?"
echo ""
}
press_any_key ()
{
if [ "$no_prompt" ]; then
echo "Continuing..."
else
printf "Press any key to continue..."
OLDSTTY=`stty -g`
stty -icanon -echo
dd bs=1 count=1 2>/dev/null
stty $OLDSTTY
# printf "\n"
fi
}
prompt_and_continue ()
{
if [ "$no_prompt" ]; then
echo "Continuing..."
echo ""
else
read -p "Press [ENTER] to continue (or CTRL^C to abort): " input < /dev/tty
echo ""
fi
}
gh_fetch ()
{
file="$1"
query="$2"
SSL_NO_VERIFY_PEER=YES fetch -q -o "$file" "https://api.github.com/${query}${get_param_token}" 2> /dev/null
if [ ! -e "$file" ]; then
echo "finch-bootstrap: Github API Fetch failed. Probably Github API limit exceeded."
echo "You are allowed up to 60 API requests / hour so try again in 1 hour."
exit 1
fi
}
download_unpack_files ()
{
mkdir -p "$finch_realpath/var/db/finch"
echo "SSL_NO_VERIFY_PEER=YES fetch -o \"/tmp/$tarball_file\" \"$tarball_url\"" | wrap "78"
SSL_NO_VERIFY_PEER=YES fetch -o "/tmp/$tarball_file" "$tarball_url" 2> /dev/null
printf "Unpacking files... "
# echo "tar --strip-components 2 --include \"*/chroot/*\" -zxvf \"/tmp/$tarball_file\" -C \"$finch_realpath\""
tar --strip-components 2 --include "*/chroot/*" -zxf "/tmp/$tarball_file" -C "$finch_realpath" --no-same-owner 2> /dev/null
echo "Done."
# update the timestamp
latest_update="$(stat -f %m "/tmp/$tarball_file")"
echo "$latest_update" > "$finch_realpath/var/db/finch/last_update"
rm "/tmp/$tarball_file"
if [ "$finch_txz_distfiles_dir" ]; then
if [ "`ls "$finch_txz_distfiles_dir/"*.txz`" ]; then
echo "Copying distfiles..."
mkdir -p "$finch_realpath/var/distfiles/finch/"
for txz_distfile in "$finch_txz_distfiles_dir/"*.txz
do
echo "$txz_distfile"
cp "$txz_distfile" "$finch_realpath/var/distfiles/finch/"
done
echo "Done."
echo ""
else
echo ""
err;
echo "We could not find any .txz files in \"$finch_txz_distfiles_dir\"."
echo ""
flag_error;
fi
fi
echo ""
}
cat_rc_conf_frag ()
{
cat <<- EOF
# finch ! DO NOT EDIT THESE LINES ! *BEGIN* - Added by Finch FreeBSD @ "$finch_dest_dir"
${realpath_namified_rcvar}_enable="YES"
# finch ! DO NOT EDIT THESE LINES ! **END** - Added by Finch FreeBSD @ "$finch_dest_dir"
EOF
}
print_next_steps ()
{
printf '\033[1;37;44m NEXT STEPS \033[0m\033[1;37m******************************************************************\033[0m\n'
if [ "`uname -iv | grep -i nas4free`" ] || [ "`uname -iv | grep -i freenas`" ] || [ "`uname -iv | grep -i pfsense`" ]; then
cat | xargs -0 printf <<- EOF
* You must now follow the "Post Install Steps" as shown on the Finch website.
\033[1;30m>>>\033[0m http://dreamcat4.github.io/finch/install/#toc_12 \033[1;30m<<<\033[0m
EOF
else
cat | xargs -0 printf <<- EOF
READY TO INSTALL FREEBSD IN A CHROOT ?
\033[1;37m******************************************************************************\033[0m
* Installation will take anywhere from 20 minutes up to 1 hour.
* Further messages regarding installation progress will NOT appear there.
To check progress login with another terminal and type:
tail -99999 -f $finch_realpath/var/log/finch/install.log
OK to proceed ?
YOU MAY NOT CLOSE OR EXIT THIS TERMINAL WINDOW UNTIL INSTALLATION HAS COMPLETED
EOF
fi
if [ "`uname -iv | grep -i freenas`" ]; then
_freenas_root_email=`cat "/etc/aliases" | grep -e "^[^\#]*root:" | cut -d " " -f 2`
_smartd_email_to=`cat "/usr/local/etc/smartd.conf" | grep -o -e "-m.*" | cut -d " " -f 2`
if [ "$_freenas_root_email" ]; then
_email_to="$_freenas_root_email"
elif [ "$_smartd_email_to" ]; then
_email_to="$_smartd_email_to"
fi
_host="FreeNAS"
fi
if [ "`uname -iv | grep -i nas4free`" ]; then
_n4f_config="/conf/config.xml"
if [ `command -v xml` ] && [ -e "$_n4f_config" ]; then
# Is smartd email report enabled?
_smartd_email_to=$(/usr/local/bin/xml sel -t -v "//smartd/email/to" $_n4f_config)
_email_from=$(/usr/local/bin/xml sel -t -v "//email/from" $_n4f_config)
# This feature only works if a "to address" is setup in smartd monitoring.
if [ "$_email_from" ] && [ "$_smartd_email_to" ]; then
_email_to="$_smartd_email_to" # <--- until theres a general "to address" email setting in nas4free
fi
fi
_host="NAS4Free"
fi
if [ "`uname -iv | grep -i pfsense`" ]; then
_email_to="$(pfsense_email_to)"
_host="pfSense"
fi
if [ "$_email_to" ]; then
printf '\033[1;37;44m EMAIL NOTIFICATION \033[0m\033[1;37m**********************************************************\033[0m\n'
echo ""
if [ "$_smartd_email_to" ]; then
_txt_frag="$_host \"smartd\" email settings"