-
Notifications
You must be signed in to change notification settings - Fork 57
/
chrx-install
1020 lines (874 loc) · 30.5 KB
/
chrx-install
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
#
# chrx-install
#
# chromebook unix installer
#
CHRX_VERSION="3.0.2"
CHRX_OS_DISTRO="galliumos"
CHRX_OS_ENVIRONMENT="desktop"
CHRX_OS_RELEASE="latest"
CHRX_OS_ARCH="amd64"
CHRX_OS_MIRROR="primary"
CHRX_TARGET_DISK=""
CHRX_ADD_PKGS=
CHRX_OS="linux"
CHRX_HOSTNAME="chrx"
CHRX_USERNAME="chrx"
CHRX_LOCALE="en_US.UTF-8"
CHRX_TZ="America/New_York"
CHRX_CACHE_DIR="/var/cache/chrx"
CHRX_INSTALL_ROOT="/tmp/chrxroot"
VERBOSITY=""
VERBOSITY_APTGET="-q"
VERBOSITY_MKFS="-q"
VERBOSITY_CURL="-#"
VERBOSITY_DNF=""
VERBOSITY_INSTALL=""
CHRX_PROMPT_ENABLED=1
CHRX_NOTIFY_ENABLED=1
CHRX_CUSTOMIZATION_ENABLED=1
CHRX_CONFIGURE_GRUB_ENABLED=
USAGE="
chrx installer, version ${CHRX_VERSION}
Usage: $0 [ option ... ]
Options
-d DISTRIBUTION OS-specific distribution to install [${CHRX_OS_DISTRO}]
galliumos, ubuntu, lubuntu, xubuntu, kubuntu, edubuntu,
fedora
-e ENVIRONMENT distribution-specific environment [${CHRX_OS_ENVIRONMENT}]
galliumos: desktop
ubuntu etc: desktop, minimal, standard, server
fedora: desktop, workstation, kde, xfce, lxde, mate,
cinnamon, sugar
-r RELEASE distribution release number or name [${CHRX_OS_RELEASE}]
galliumos: latest, 3.0, bismuth, 2.0, xenon, nightly
ubuntu etc: latest, lts, dev, 16.04, 16.10, xenial, etc
fedora: latest, 23, 24, 25
-a ARCH processor architecture (i386, amd64) [${CHRX_OS_ARCH}]
-m MIRROR distribution-specific download mirror [${CHRX_OS_MIRROR}]
galliumos: ny1.us, va1.us, rb1.fr
-t TARGETDISK target disk (/dev/mmcblk1, /dev/sdb, etc) [${CHRX_TARGET_DISK}]
-p PACKAGE additional packages to install, may repeat [${CHRX_ADD_PKGS}]
kodi, minecraft, steam, etc, see chrx.org for more
(not yet supported on fedora)
-H HOSTNAME hostname for new system [${CHRX_HOSTNAME}]
-U USERNAME username of first created user [${CHRX_USERNAME}]
-L LOCALE locale for new system [${CHRX_LOCALE}]
-Z TIMEZONE timezone for new system, Eggert convention [${CHRX_TZ}]
America/San_Francisco, Europe/Amsterdam, Etc/UTC, etc
-n disable success/failure notifications
-s skip all customization, install stock OS only
-y run non-interactively, take defaults and do not confirm
-v increase output verbosity
-h show this help
Default values are shown in brackets, e.g.: [default].
If TARGETDISK is not specified, chrx will select the internal SSD.
"
ANSI_RED=$'\033[1;31m'
ANSI_YEL=$'\033[1;33m'
ANSI_GRN=$'\033[1;32m'
ANSI_VIO=$'\033[1;35m'
ANSI_BLU=$'\033[1;36m'
ANSI_WHT=$'\033[1;37m'
ANSI_RST=$'\033[0m'
echo_cmd() { echo -e "${ANSI_BLU}${@}${ANSI_RST}"; }
echo_note() { echo -e "${ANSI_YEL}${@}${ANSI_RST}"; }
echo_info() { echo -e "${ANSI_GRN}${@}${ANSI_RST}"; }
echo_prompt() { echo -e "${ANSI_WHT}${@}${ANSI_RST}"; }
echo_warn() { echo -e "${ANSI_YEL}${@}${ANSI_RST}"; }
echo_debug() { echo -e "${ANSI_VIO}${@}${ANSI_RST}"; }
echo_fail() { echo -e "${ANSI_RED}${@}${ANSI_RST}"; }
usage() { echo "${USAGE}"; exit; }
eval_try()
{
#set +e
local _cmd=$@
[ "$VERBOSE" ] && echo_cmd "$_cmd"
eval $_cmd
#set -e
}
eval_crit()
{
#set +e
local _cmd=$@
[ "$VERBOSE" ] && echo_cmd "$_cmd"
eval $_cmd
rc=$?
if [ "$rc" -ne 0 ]; then
echo_fail "fatal: return code ${rc} from command \"${_cmd}\""
exit $rc
fi
#set -e
}
prompt_if_interactive()
{
## TODO this would be better with passed (lexical) refs
PROMPT_RESPONSE=
if [ "${CHRX_PROMPT_ENABLED}" ]; then
read -e PROMPT_RESPONSE
else
echo
fi
}
ping_chrx_org()
{
msg=$1
[ "$2" ] && deviceinfo="(${2})"
CHRX_UA="chrx/${CHRX_VERSION} hw=${CHRX_HWID}${deviceinfo} sw=${CHRX_OS},${CHRX_OS_DISTRO}-${CHRX_OS_ENVIRONMENT},${CHRX_OS_RELEASE:-"-"},${CHRX_OS_VERSION:-"(tbd)"},${CHRX_OS_ARCH}"
if [ "${CHRX_NOTIFY_ENABLED}" ]; then
curl -s -m 7 -A "${CHRX_UA}" http://ping.chrx.org/${msg}
fi
}
downcase() { echo "$@" | tr '[:upper:]' '[:lower:]'; }
get_device_details() {
local hwid=$*
#cat "${CHRX_DIST_DIR}/chrx-devices" | while read line; do
cat "/usr/local/etc/chrx-devices" | while read line; do
regex="$(echo "$line" | cut -d';' -f6-)"
if [ -n "$(echo "$hwid" | egrep "$regex")" ]; then
echo $line | cut -d';' -f1-5 | sed 's/;/ /g'
break
fi
done
}
# ref1, ref2
identify_hardware()
{
local _outvar_hwid=$1
local _outvar_desc=$2
local _outvar_year=$3
local _outvar_cpuf=$4
local _outvar_prognosis=$5
local _hwid_full
local _hwid_codename
local _hwid_details
local _prognosis
local _desc
local _cpuf
local _year
local _x
CHRX_HOST_IS_CHROMEOS=$(grep "^CHROMEOS" /etc/lsb-release)
if [ -z "$CHRX_HOST_IS_CHROMEOS" ]; then
echo_warn "This does not appear to be ChromeOS!"
echo_warn "Chrx will attempt to continue, but you should expect errors."
fi
_hwid_full=$(crossystem hwid 2>/dev/null | head -1 | tr a-z A-Z)
_hwid_details=$(get_device_details $_hwid_full)
if [ -n "$_hwid_details" ]; then
set $_hwid_details
_hwid=$1 ; shift
_prognosis=$1 ; shift
_cpuf=$1 ; shift
_year=$1 ; shift
_desc=$*
else
echo_fail "No model found matching \"$_hwid_full\""
# TODO(?) attempt stem match on codename.. useful?
_hwid_codename=$(dmidecode -s system-product-name | tr a-z A-Z)
fi
## CPU family, Processor core, other distinguishing characteristic
case "$_cpuf" in
ARM) _cpuf="ARM" ;;
AMD) _cpuf="AMD" ;;
#
PNV) _cpuf="Intel Pineview" ;;
SNB) _cpuf="Intel Sandy Bridge" ;;
IVB) _cpuf="Intel Ivy Bridge" ;; # succeeds SNB
HSW) _cpuf="Intel Haswell" ;; # succeeds IVB
BDW) _cpuf="Intel Broadwell" ;; # succeeds HSW
SKL) _cpuf="Intel Skylake" ;; # succeeds BDW
KBL) _cpuf="Intel Kaby Lake" ;; # succeeds SKL
AML) _cpuf="Intel Amber Lake" ;; # succeeds KBL
WHL) _cpuf="Intel Whiskey Lake" ;; # succeeds KBL
CML) _cpuf="Intel Coffee Lake" ;; # succeeds KBL
#
BYT) _cpuf="Intel Bay Trail" ;;
BSW) _cpuf="Intel Braswell" ;; # succeeds BYT
APL) _cpuf="Intel Apollo Lake" ;; # succeeds BSW
GLK) _cpuf="Intel Gemini Lake" ;; # succeeds APL
*) _cpuf="(unrecognized)" ;;
esac
eval $_outvar_hwid=\$_hwid
eval $_outvar_desc=\$_desc
eval $_outvar_year=\$_year
eval $_outvar_cpuf=\$_cpuf
eval $_outvar_prognosis=\$_prognosis
}
get_os_version_and_core_url_dev_ubuntu()
{
release_log_fn="meta-release-development"
release_log_url="http://changelogs.ubuntu.com/${release_log_fn}"
release_log="`curl -s ${release_log_url}`"
codename=`echo "${release_log}"|grep "^Dist: "|tail -1|awk '{print $2}'`
CHRX_OS_VERSION=`echo "${release_log}"|grep "^Version: "|tail -1|awk '{print $2}'`
CHRX_OS_CORE_IMAGE_URL="http://cdimage.ubuntu.com/ubuntu-base/daily/current/${codename}-base-${CHRX_OS_ARCH}.tar.gz"
}
get_os_version_ubuntu()
{
tag=$1
release_log_fn="meta-release"
release_log_url="http://changelogs.ubuntu.com/${release_log_fn}"
version_list="`curl -s ${release_log_url} | grep '^Version: '`"
[ "$tag" = "lts" ] && version_list=`echo "${version_list}" | grep "LTS"`
CHRX_OS_VERSION=`echo "${version_list}" | tail -1 | awk '{print $2}'`
}
determine_osv_ubuntu()
{
case "${CHRX_OS_RELEASE}" in
latest) get_os_version_ubuntu $CHRX_OS_RELEASE ;;
lts) get_os_version_ubuntu $CHRX_OS_RELEASE ;;
dev) get_os_version_and_core_url_dev_ubuntu $CHRX_OS_RELEASE ;;
trusty) CHRX_OS_VERSION="14.04.6" ;; # EOL 201904
utopic) CHRX_OS_VERSION="14.10" ;; # EOL 201507
vivid) CHRX_OS_VERSION="15.04" ;; # EOL 201602
wily) CHRX_OS_VERSION="15.10" ;; # EOL 201607
xenial) CHRX_OS_VERSION="16.04.6" ;; # EOL 202104
yakkety) CHRX_OS_VERSION="16.10" ;; # EOL 201707
zesty) CHRX_OS_VERSION="17.04" ;; # EOL 201801
artful) CHRX_OS_VERSION="17.10" ;; # EOL 201807
bionic) CHRX_OS_VERSION="18.04.3" ;; # EOL 202304
cosmic) CHRX_OS_VERSION="18.10" ;; # EOL 201907
disco) CHRX_OS_VERSION="19.04" ;; # EOL 202001
eoan) CHRX_OS_VERSION="19.10" ;; # EOL 202007
focal) CHRX_OS_VERSION="20.04" ;; # EOL 202504
g*) CHRX_OS_VERSION="20.10" ;; # EOL 202107
h*) CHRX_OS_VERSION="21.04" ;; # EOL 202201
i*) CHRX_OS_VERSION="21.10" ;; # EOL 202207
j*) CHRX_OS_VERSION="22.04" ;; # EOL 202704
*) CHRX_OS_VERSION=${CHRX_OS_RELEASE} ;;
esac
local _ubuntu_corebase='base'
case "${CHRX_OS_VERSION}" in
"18.04*") ;;
"16.04*") _ubuntu_corebase='core' ;;
"14.04*") _ubuntu_corebase='core'
msg_os_version="${ANSI_YEL}(CAUTION: not well-tested!)${ANSI_RST}"
;;
"1[45678].*")
## TODO: get this from meta-release/Supported instead?
msg_os_version="${ANSI_YEL}(ERROR: no longer available!)${ANSI_RST}"
FAIL=1
;;
*)
if [ "`echo ${CHRX_OS_VERSION} | grep "^[0-9.][0-9.]*$"`" ]; then
msg_os_version="${ANSI_YEL}(CAUTION: untested!)${ANSI_RST}"
else
msg_os_version="${ANSI_RED}(invalid!)${ANSI_RST}"
FAIL=1
fi
;;
esac
if [ -z "${CHRX_OS_CORE_IMAGE_URL}" ]; then
CHRX_OS_CORE_IMAGE_URL="http://cdimage.ubuntu.com/ubuntu-base/releases/${CHRX_OS_VERSION}/release/ubuntu-base-${CHRX_OS_VERSION}-${_ubuntu_corebase}-${CHRX_OS_ARCH}.tar.gz"
fi
}
get_os_version_galliumos()
{
local _release=$1
CHRX_OS_VERSION="3.0"
}
get_mirror_url_galliumos()
{
local _mirror=$1
case "$_mirror" in
#ny1.us) CHRX_OS_MIRROR="https://galliumos.org/releases" ;;
va1.us) CHRX_OS_MIRROR="https://va1.us.mirror.galliumos.org/releases" ;;
#ca1.us) CHRX_OS_MIRROR="https://ca1.us.mirror.galliumos.org/releases" ;;
rb1.fr) CHRX_OS_MIRROR="https://rb1.fr.mirror.galliumos.org/releases" ;;
*) CHRX_OS_MIRROR="https://galliumos.org/releases" ;;
esac
echo "$CHRX_OS_MIRROR"
}
determine_osv_galliumos()
{
local _url_base=$(get_mirror_url_galliumos $CHRX_OS_MIRROR)
local _url_path
local _versions_file_url="${_url_base_primary}/VERSIONS"
#versions_file="`curl -s ${versions_file_url}`"
case "${CHRX_OS_RELEASE}" in
'1.0'|'1'|vivid) CHRX_OS_VERSION="1.0" ;;
'2.0') CHRX_OS_VERSION="2.0" ;;
'2.1'|'2'|xenon) CHRX_OS_VERSION="2.1" ;;
'3.0'|'3'|bismuth) CHRX_OS_VERSION="3.0" ;;
latest) get_os_version_galliumos $CHRX_OS_RELEASE ;;
nightly)
CHRX_OS_VERSION="nightly"
msg_os_version="${ANSI_YEL}(NOTE: nightly build!)${ANSI_RST}"
_url_path="/nightly/galliumos-generic-coreimage-bismuth-latest.tgz"
_url_path="/nightly/galliumos-generic-coreimage-xenon-latest.tgz"
CHRX_OS_CORE_IMAGE_URL="${_url_base}${_url_path}"
;;
dev|alpha|beta)
CHRX_OS_VERSION="alpha"
msg_os_version="${ANSI_YEL}(NOTE: alpha/beta build!)${ANSI_RST}"
_url_path="/nightly/galliumos-generic-coreimage-bismuth-latest.tgz"
CHRX_OS_CORE_IMAGE_URL="${_url_base}${_url_path}"
;;
*)
msg_os_version="${ANSI_YEL}(NOTE: unrecognized!)${ANSI_RST}"
CHRX_OS_VERSION=${CHRX_OS_RELEASE}
;;
esac
if [ -z "${CHRX_OS_CORE_IMAGE_URL}" ]; then
_url_path="/$CHRX_OS_VERSION/galliumos-generic-coreimage-$CHRX_OS_VERSION.tgz"
CHRX_OS_CORE_IMAGE_URL="${_url_base}${_url_path}"
fi
case "${CHRX_OS_VERSION}" in
'1.0') msg_os_version="${ANSI_YEL}(CAUTION: deprecated!)${ANSI_RST}" ;;
'2.0') msg_os_version="${ANSI_YEL}(CAUTION: deprecated!)${ANSI_RST}" ;;
'2.1') msg_os_version="${ANSI_YEL}(NOTE: newer version available)${ANSI_RST}" ;;
'3.0') ;;
esac
}
get_os_version_fedora()
{
release_log_url="http://dl.fedoraproject.org/pub/fedora/linux/releases/"
version_list=$(curl -s ${release_log_url} | grep -Eo ">[0-9][0-9]/" | grep -o "[0-9][0-9]")
CHRX_OS_VERSION=$(echo "${version_list}" | sort | tail -1)
# default to 25
if [[ $CHRX_OS_VERSION != [0-9][0-9] ]]; then
CHRX_OS_VERSION=30
fi
}
determine_osv_fedora()
{
msg_os_version="${ANSI_YEL}(CAUTION: chrx support is beta!)${ANSI_RST}"
case "${CHRX_OS_RELEASE}" in
latest)
get_os_version_fedora
;;
28,29,30)
CHRX_OS_VERSION=${CHRX_OS_RELEASE}
;;
rawhide)
CHRX_OS_VERSION=${CHRX_OS_RELEASE}
msg_os_version="${ANSI_YEL}(CAUTION: development version; may not work!)${ANSI_RST}"
;;
*)
if [[ ${CHRX_OS_RELEASE} == [0-9][0-9] ]]; then
CHRX_OS_VERSION=${CHRX_OS_RELEASE}
msg_os_version="${ANSI_YEL}(CAUTION: untested!)${ANSI_RST}"
else
msg_os_version="${ANSI_RED}(invalid!)${ANSI_RST}"
FAIL=1
fi
;;
esac
CHRX_OS_CORE_IMAGE_URL='https://download.fedoraproject.org/pub/fedora/linux/releases/30/Container/x86_64/images/Fedora-Container-Base-30-1.2.x86_64.tar.xz'
}
set_customizations_ubuntu()
{
SKEL_FILES="
etc/skel/.config/lxpanel/Lubuntu/config
etc/skel/.config/lxpanel/Lubuntu/panels/panel
etc/skel/.xbindkeysrc
etc/skel/.xsessionrc
"
CONF_FILES="
etc/modprobe.d/ath9k.conf
etc/modprobe.d/snd-hda-intel.conf
etc/udev/rules.d/10-disable-ehci.rules
etc/X11/xorg.conf
etc/X11/xorg.conf.d/20-intel-graphics.conf
etc/X11/xorg.conf.d/50-cyapa-touchpad.conf
"
EXEC_FILES="
etc/rc.local
etc/initramfs-tools/scripts/init-top/unbind_ehci
etc/pm/sleep.d/50-audio-intel-driver
etc/pm/sleep.d/89-wifi-ath9k-module
"
#etc/init.d/chrx-firstboot
APPENDED_FILES="
etc/sysctl.conf
etc/systemd/logind.conf
"
set_hidden_partitions_conf
CHRX_CONFIGURE_GRUB_ENABLED=1
}
set_customizations_galliumos()
{
set_hidden_partitions_conf
CHRX_CONFIGURE_GRUB_ENABLED=1
}
set_customizations_fedora()
{
SKEL_FILES="
etc/skel/.xbindkeysrc
etc/skel/.config/autostart/xbindkeys.desktop
etc/skel/.config/autostart/chrx_touchpad_support.desktop
"
CONF_FILES="
etc/modprobe.d/ath9k.conf
etc/modprobe.d/snd-hda-intel.conf
etc/udev/rules.d/10-disable-ehci.rules
etc/X11/xorg.conf.d/20-intel-graphics.conf
etc/X11/xorg.conf.d/50-cyapa-touchpad.conf
etc/X11/xorg.conf.d/70-synaptics.conf
etc/selinux/config
"
EXEC_FILES="
etc/rc.local
etc/initramfs-tools/scripts/init-top/unbind_ehci
etc/pm/sleep.d/50-audio-intel-driver
etc/pm/sleep.d/89-wifi-ath9k-module
etc/skel/.local/bin/chrx_touchpad_support.sh
"
APPENDED_FILES="
etc/sysctl.conf
etc/systemd/logind.conf
"
set_hidden_partitions_conf
CHRX_CONFIGURE_GRUB_ENABLED=
}
set_hidden_partitions_conf()
{
local _rootdev=$(rootdev -d -s)
case "$_rootdev" in
"/dev/mmcblk0")
CONF_FILES+="etc/udev/rules.d/99-hide-disks-mmc.rules "
if [ "$CHRX_OS_DISTRO" = "fedora" ]; then
CONF_FILES+="etc/dracut.conf.d/mmc.conf "
fi
;;
"/dev/sda")
CONF_FILES+="etc/udev/rules.d/99-hide-disks-sda.rules "
;;
"/dev/nvme0n1")
CONF_FILES+="etc/udev/rules.d/99-hide-disks-nvme.rules "
;;
*)
echo_warn "unexpected root device \"$_rootdev\""
;;
esac
}
install_customizations()
{
echo_info "\nInstalling chrx customization files for ${CHRX_OS_DISTRO_DISPLAYNAME}."
for fpath in ${CONF_FILES} ${EXEC_FILES} ${SKEL_FILES} ${APPENDED_FILES}; do
if [ ! -d "${CHRX_INSTALL_ROOT}/`dirname ${fpath}`" ]; then
#echo mkdir -p "${CHRX_INSTALL_ROOT}/`dirname ${fpath}`"
install ${VERBOSITY_INSTALL} -d "${CHRX_INSTALL_ROOT}/`dirname ${fpath}`"
fi
done
for fpath in ${SKEL_FILES}; do
install ${VERBOSITY_INSTALL} -m 644 ${CHRX_DIST_DIR}/${fpath} ${CHRX_INSTALL_ROOT}/${fpath}
done
for fpath in ${CONF_FILES}; do
install ${VERBOSITY_INSTALL} -m 644 ${CHRX_DIST_DIR}/${fpath} ${CHRX_INSTALL_ROOT}/${fpath}
done
for fpath in ${EXEC_FILES}; do
install ${VERBOSITY_INSTALL} -m 755 ${CHRX_DIST_DIR}/${fpath} ${CHRX_INSTALL_ROOT}/${fpath}
done
for fpath in ${APPENDED_FILES}; do
cat ${CHRX_DIST_DIR}/${fpath}-append >> ${CHRX_INSTALL_ROOT}/${fpath}
done
}
report_unrecognized_device()
{
dmi_sm=`dmidecode -s system-manufacturer`
dmi_pv=`dmidecode -s processor-version`
cat <<- EOMSG
... You're running an unrecognized Chrome device! That's exciting.
...
... Inspecting your hardware reveals:
... hardware-id: ${CHRX_HWID-(unknown)}
... system-manufacturer: ${dmi_sm}
... processor-version: ${dmi_pv}
...
... Please take a moment to describe your device (manufacturer,
... model, country of sale) and we will add it to the database.
...
... Example: "Google, Chromebook Pixel, US"
...
... Thank you for your help. If you've already sent your device info,
... we apologize for the repeated requests. The database should be
... updated soon!
...
... (to skip, just enter a blank line)
EOMSG
echo_prompt "Please describe your device: \c"
prompt_if_interactive
if [ "${PROMPT_RESPONSE}" ]; then
ping_chrx_org "unrecognized_device" "${dmi_sm}/${dmi_pv}/${PROMPT_RESPONSE}"
echo "Thanks! We'll add your device to the database!"
fi
}
check_support_for_legacy_boot()
# obsolete due to removal of eeprom command from mosys in ChromeOS 85
{
echo_info "Checking hardware support for legacy boot... \c"
if [ ! -x /usr/sbin/mosys ]; then
echo_fail "ERROR"
cat <<- EOMSG
${ANSI_RED}
Can't find /usr/sbin/mosys. Make sure you are running the default
developer mode Linux shell, logged in as chronos@localhost.
${ANSI_RST}
EOMSG
ping_chrx_org "fail_mosys"
exit 1
fi
if [ -z "`/usr/sbin/mosys eeprom map | grep RW_LEGACY`" ]; then
echo_fail "ERROR"
cat <<- EOMSG
${ANSI_RED}
This Chrome device does not support CTRL-L Legacy SeaBIOS booting.
You might have better luck with the old ChrUbuntu script.
${ANSI_RST}
EOMSG
ping_chrx_org "fail_rwlegacy"
exit 1
else
echo_info "OK"
fi
}
setup_and_validate_environment()
{
if [ "`initctl status powerd | grep running 2>/dev/null`" ]; then
initctl stop powerd > /dev/null 2>&1
fi
## prevent screen blanking whilst installing
## setterm --blank doesn't work in new VT2 shell, which claims xterm
#export TERM=linux ## ?
#setterm -blank 0
cat <<- EOMSG
Hardware ID: ${CHRX_HWID}
Model: ${CHRX_HWDESC-(unknown)}
Released: ${CHRX_HWYEAR-(unknown)}
CPU Family: ${CHRX_HWCPUF-(unknown)}
EOMSG
echo -e " Prognosis: \c"
case "${CHRX_HWSTATUS}" in
OK) echo_info "success likely, model is well-tested" ;;
RS) echo_info "success likely, per field reports" ;;
FS) echo_warn "success likely, ONLY IF FIRMWARE HAS BEEN UPDATED!" ;;
ES) echo_warn "success likely, but unverified" ;;
UN) echo_warn "uncertain; no field reports" ;;
EF) echo_fail "failure likely, but unverified" ;;
RF) echo_fail "failure likely, per field reports" ;;
NG) echo_fail "FAILURE! cannot possibly succeed" ;;
*) echo_warn "UNKNOWN, model is unrecognized and untested" ;;
esac
echo
if [ -z "${CHRX_HWDESC}" ]; then
report_unrecognized_device
fi
if [ "$CHRX_HOST_IS_CHROMEOS" ]; then
:
# disabled, redundant after hwid check
#check_support_for_legacy_boot
else
echo_warn "Skipping legacy boot check, because this is not ChromeOS."
fi
}
setup_storage()
{
SETUP_STORAGE_ERROR="failed"
#curl -Os -A "${CHRX_UA}" ${CHRX_WEB_ROOT}/chrx-setup-storage
#[ -r ./chrx-setup-storage ] && . ./chrx-setup-storage
. /usr/local/bin/chrx-setup-storage
if [ "${SETUP_STORAGE_ERROR}" ]; then
echo_fail "fatal error from chrx-setup-storage. exiting!"
exit 1
fi
}
validate_config()
{
## validate config
case "${CHRX_OS}" in
linux) ;;
*) msg_os="${ANSI_RED}invalid${ANSI_RST}" ; FAIL=1 ;;
esac
case "${CHRX_OS_DISTRO}" in
ubuntu)
CHRX_OS_DISTRO_DISPLAYNAME='Ubuntu'
osv_method="ubuntu"
customization_set="ubuntu"
valid_envs="minimal,standard,desktop"
;;
edubuntu)
CHRX_OS_DISTRO_DISPLAYNAME='Edubuntu'
osv_method="ubuntu"
customization_set="ubuntu"
valid_envs="server,desktop"
;;
kubuntu)
CHRX_OS_DISTRO_DISPLAYNAME='Kubuntu'
osv_method="ubuntu"
customization_set="ubuntu"
valid_envs="desktop"
;;
lubuntu)
CHRX_OS_DISTRO_DISPLAYNAME='Lubuntu'
osv_method="ubuntu"
customization_set="ubuntu"
valid_envs="desktop"
;;
xubuntu)
CHRX_OS_DISTRO_DISPLAYNAME='Xubuntu'
osv_method="ubuntu"
customization_set="ubuntu"
valid_envs="desktop"
;;
galliumos)
CHRX_OS_DISTRO_DISPLAYNAME='GalliumOS'
osv_method="galliumos"
customization_set="galliumos"
valid_envs="desktop"
;;
fedora)
CHRX_OS_DISTRO_DISPLAYNAME='Fedora'
osv_method="fedora"
customization_set="fedora"
valid_envs="desktop,workstation,kde,xfce,lxde,mate,cinnamon,sugar,minimal,basic"
;;
*)
CHRX_OS_DISTRO_DISPLAYNAME='Unix/Linux'
msg_os_dist="${ANSI_RED}invalid${ANSI_RST}"
FAIL=1
;;
esac
if [ -z "${FAIL}" -a -z "`echo ${valid_envs} | grep -w ${CHRX_OS_ENVIRONMENT}`" ]; then
msg_os_env="${ANSI_RED}invalid${ANSI_RST}, try ${valid_envs}"
FAIL=1
fi
CHRX_OS_DISTENV="${CHRX_OS_DISTRO}-${CHRX_OS_ENVIRONMENT}"
case "${osv_method}" in
ubuntu) determine_osv_ubuntu ;;
galliumos) determine_osv_galliumos ;;
fedora) determine_osv_fedora ;;
esac
case "${customization_set}" in
ubuntu) set_customizations_ubuntu ;;
galliumos) set_customizations_galliumos ;;
fedora) set_customizations_fedora ;;
esac
case "${CHRX_OS_ARCH}" in
i386|amd64) ;;
*) msg_os_arch="${ANSI_RED}invalid${ANSI_RST}" ; FAIL=1 ;;
esac
if [ "$CHRX_OS_DISTRO" != "galliumos" -a ! -z "$CHRX_OS_MIRROR" ]; then
msg_os_mirror="${ANSI_RED}unknown, will use primary${ANSI_RST}"
fi
}
confirm_config()
{
validate_config
cat <<- EOCONFIG
Installing
operating system: ${CHRX_OS} ${msg_os}
distribution (-d): ${CHRX_OS_DISTRO} ${msg_os_dist}
environment (-e): ${CHRX_OS_ENVIRONMENT} ${msg_os_env}
release (-r): ${CHRX_OS_RELEASE} ${msg_os_release}
version: ${CHRX_OS_VERSION} ${msg_os_version}
architecture (-a): ${CHRX_OS_ARCH} ${msg_os_arch}
mirror (-m): ${CHRX_OS_MIRROR} ${msg_os_mirror}
target_disk (-t): ${CHRX_TARGET_DISK}
packages (-p): ${CHRX_ADD_PKGS}${msg_os_pkgs}
System Configuration
hostname (-H): ${CHRX_HOSTNAME}
username (-U): ${CHRX_USERNAME}
locale (-L): ${CHRX_LOCALE}
timezone (-Z): ${CHRX_TZ}
EOCONFIG
if [ "${FAIL}" ]; then
echo_fail "fatal error(s) in configuration options (see above). exiting!"
exit 1
fi
if [ -z "${CHRX_CUSTOMIZATION_ENABLED}" ]; then
cat <<- EOMSG
${ANSI_YEL}\
.----------------------------------------------------------------.
| NOTE: Installing stock OS only, skipping chrx customizations. |
'----------------------------------------------------------------'
${ANSI_RST}
EOMSG
fi
echo_note "Press [enter] to confirm and continue: \c"
prompt_if_interactive
}
get_dist_files() {
CHRX_DIST_DIR=${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
mkdir -p ${CHRX_DIST_DIR}
#cd ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
curl ${VERBOSITY_CURL} ${CHRX_WEB_ROOT}/dist.tar.gz |
tar xzC ${CHRX_DIST_DIR} --no-same-owner
}
do_install()
{
start_date=`date`
start_secs=`date +%s`
if [ -z "${CHRX_OS_CORE_IMAGE_URL}" ]; then
echo_fail "fatal: cannot determine core image URL from options specified. This might be a bug!"
exit 1
fi
echo_info "\nFetching ${CHRX_OS_DISTRO_DISPLAYNAME} core image file..."
echo_info "HTTP GET ${CHRX_OS_CORE_IMAGE_URL}"
## "--retry 8 --continue-at -" opts won't help when piped to tar, and
## /tmp is only 1GB on some devices, so we have no good options here.
## TODO: add opts to other (non-piped) curl calls.
case "${osv_method}" in
galliumos|ubuntu)
curl -o - ${VERBOSITY_CURL} ${CHRX_OS_CORE_IMAGE_URL} | tar xzp -C ${CHRX_INSTALL_ROOT}
if [ ${PIPESTATUS[0]} -ne 0 -o ${PIPESTATUS[1]} -ne 0 ]; then
echo_fail "fatal: unable to download and extract core image file."
exit 1
fi
;;
fedora)
## There is no good source of images for all versions of fedora, so
## pull in a docker image and use this to install a core version
## of fedora
mkdir -p ${CHRX_INSTALL_ROOT}/fedora
curl -L -o - ${VERBOSITY_CURL} ${CHRX_OS_CORE_IMAGE_URL} | tar xJp -C ${CHRX_INSTALL_ROOT}/fedora
if [ ${PIPESTATUS[0]} -ne 0 -o ${PIPESTATUS[1]} -ne 0 ]; then
echo_fail "fatal: unable to download and extract core image file."
exit 1
fi
tar xfp ${CHRX_INSTALL_ROOT}/fedora/*/layer.tar -C ${CHRX_INSTALL_ROOT}/fedora
cat /etc/resolv.conf > ${CHRX_INSTALL_ROOT}/fedora/etc/resolv.conf
eval_crit mount -o bind /proc ${CHRX_INSTALL_ROOT}/fedora/proc
eval_crit mount -o bind /dev ${CHRX_INSTALL_ROOT}/fedora/dev
eval_crit mount -o bind /dev/pts ${CHRX_INSTALL_ROOT}/fedora/dev/pts
eval_crit mount -o bind /sys ${CHRX_INSTALL_ROOT}/fedora/sys
eval_crit mount -o bind /run ${CHRX_INSTALL_ROOT}/fedora/run
eval_crit mount -o bind ${CHRX_INSTALL_ROOT} ${CHRX_INSTALL_ROOT}/fedora/mnt
LC_OLD=${LC_ALL}
export LC_ALL=
echo_info "\nInstalling Fedora core packages..."
chroot ${CHRX_INSTALL_ROOT}/fedora /bin/bash -c "dnf ${VERBOSITY_DNF} -y --nogpgcheck --releasever=${CHRX_OS_VERSION} --setopt='module_platform_id=platform:f${CHRX_OS_VERSION}' --installroot=/mnt/ group install core"
export LC_ALL=${LC_OLD}
umount ${CHRX_INSTALL_ROOT}/fedora/mnt
umount ${CHRX_INSTALL_ROOT}/fedora/proc
umount ${CHRX_INSTALL_ROOT}/fedora/dev/pts
umount ${CHRX_INSTALL_ROOT}/fedora/dev
umount ${CHRX_INSTALL_ROOT}/fedora/sys
umount ${CHRX_INSTALL_ROOT}/fedora/run
rm -rf ${CHRX_INSTALL_ROOT}/fedora
;;
esac
eval_crit mount -o bind /proc ${CHRX_INSTALL_ROOT}/proc
eval_crit mount -o bind /dev ${CHRX_INSTALL_ROOT}/dev
eval_crit mount -o bind /dev/pts ${CHRX_INSTALL_ROOT}/dev/pts
eval_crit mount -o bind /sys ${CHRX_INSTALL_ROOT}/sys
eval_crit mount -o bind /run ${CHRX_INSTALL_ROOT}/run
if [ -f /usr/bin/old_bins/cgpt ]; then
cp /usr/bin/old_bins/cgpt ${CHRX_INSTALL_ROOT}/usr/bin/
else
cp /usr/bin/cgpt ${CHRX_INSTALL_ROOT}/usr/bin/
fi
chmod a+rx ${CHRX_INSTALL_ROOT}/usr/bin/cgpt
## The chroot needs a valid resolv.conf, so bring it over from ChromeOS.
## Sometimes /etc/resolv.conf is a dangling symlink, so fix parent dirs.
mkdir -p ${CHRX_INSTALL_ROOT}/run/resolvconf
mkdir -p ${CHRX_INSTALL_ROOT}/run/systemd/resolve
## cat in case resolv.conf is a symlink (e.g. into /run/resolvconf etc).
cat /etc/resolv.conf > ${CHRX_INSTALL_ROOT}/etc/resolv.conf
echo ${CHRX_HOSTNAME} > ${CHRX_INSTALL_ROOT}/etc/hostname
echo -e "\n127.0.0.1 ${CHRX_HOSTNAME}" >> ${CHRX_INSTALL_ROOT}/etc/hosts
if [ "${CHRX_CUSTOMIZATION_ENABLED}" ]; then
install_customizations
else
echo_warn "\n(skipping installation of chrx customization files)"
fi
## chroot
export CHRX_OS_DISTRO CHRX_OS_ENVIRONMENT CHRX_OS_DISTENV
export CHRX_CUSTOMIZATION_ENABLED
export CHRX_OS_DISTRO_DISPLAYNAME CHRX_HWCPUF
export CHRX_TZ CHRX_LOCALE CHRX_USERNAME
export CHRX_TARGET_DISK CHRX_ROOT_PARTITION CHRX_CACHE_DIR CHRX_INSTALL_ROOT
export CHRX_OS_RELEASE CHRX_ADD_PKGS CHRX_CONFIGURE_GRUB_ENABLED
export VERBOSITY VERBOSITY_APTGET VERBOSITY_CURL VERBOSITY_DNF
export ANSI_RED ANSI_YEL ANSI_GRN ANSI_VIO ANSI_BLU ANSI_WHT ANSI_RST
export -f echo_info ## this does not reach the chroot
mkdir -p ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
#install ${VERBOSITY_INSTALL} -m 755 ${CHRX_DIST_DIR}/chrx-install-chroot ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
install ${VERBOSITY_INSTALL} -m 755 /usr/local/bin/chrx-install-chroot ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
echo ">> entering chroot"
chroot ${CHRX_INSTALL_ROOT} /bin/bash -c ${CHRX_CACHE_DIR}/chrx-install-chroot
# | tee -a ${CHRX_LOGFILE}
echo "<< exiting chroot"
## set eeprom bits
#crossystem dev_boot_legacy=1 dev_boot_signed_only=1
[ "$CHRX_HOST_IS_CHROMEOS" ] && crossystem dev_boot_legacy=1
## wind up
finish_date=`date`
finish_secs=`date +%s`
elapsed_time=$(( (${finish_secs}-${start_secs})/60 ))m$(( (${finish_secs}-${start_secs})%60 ))s
cat <<- EOMSG
${ANSI_YEL}chrx installer is finished!${ANSI_RST}
started: ${start_date}
finished: ${finish_date}
elapsed: ${elapsed_time}
Installation log files will be preserved in ${CHRX_CACHE_DIR}
After reboot, at the white "OS verification is OFF" screen, press:
${ANSI_YEL}CTRL-D${ANSI_RST} to boot ChromeOS, or
${ANSI_GRN}CTRL-L${ANSI_RST} to boot ${CHRX_OS_DISTRO_DISPLAYNAME}.
Your login is:
username: ${ANSI_WHT}${CHRX_USERNAME}${ANSI_RST}
password: ${ANSI_WHT}${CHRX_USERNAME}${ANSI_RST}
${ANSI_RED}Be sure to change your password after log in!${ANSI_RST}
EOMSG
cp -r ${CHRX_CACHE0_DIR}/chrx-* ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}/
}
parse_opts()
{
## parse command line options
## TODO: lubuntu[-desktop[-latest]] should be parseable
while getopts ":d:e:r:a:m:t:p:H:U:L:Z:nsyvh" OPTION
do
case "$OPTION" in
d) CHRX_OS_DISTRO=$(downcase $OPTARG) ;;
e) CHRX_OS_ENVIRONMENT=$(downcase $OPTARG) ;;
r) CHRX_OS_RELEASE=$(downcase $OPTARG) ;;
a) CHRX_OS_ARCH=$(downcase $OPTARG) ;;
m) CHRX_OS_MIRROR=$(downcase $OPTARG) ;;
t) CHRX_TARGET_DISK=$OPTARG ;;
p) CHRX_ADD_PKGS="${CHRX_ADD_PKGS}$(downcase $OPTARG) " ;;
H) CHRX_HOSTNAME=$OPTARG ;;
U) CHRX_USERNAME=$OPTARG ;;
L) CHRX_LOCALE=$OPTARG ;;
Z) CHRX_TZ=$OPTARG ;;
n) CHRX_NOTIFY_ENABLED= ;;
s) CHRX_CUSTOMIZATION_ENABLED= ;;
y) CHRX_PROMPT_ENABLED= ;;
v) VERBOSITY="v"
VERBOSITY_APTGET=""
VERBOSITY_MKFS=""
VERBOSITY_CURL=""
VERBOSITY_DNF="-v"
VERBOSITY_INSTALL="-v"
;;
h) usage ;;
'?')
[ "$OPTARG" = "?" ] && usage
echo_fail "unrecognized option: '-${OPTARG}'" ; exit 1 ;;
esac
done
}
main()
{
parse_opts "$@"
echo_note "chrx installer, version ${CHRX_VERSION}\n"
#get_dist_files
mkdir -p ${CHRX_INSTALL_ROOT}${CHRX_CACHE_DIR}
CHRX_DIST_DIR="/usr/local/etc/chrx-files"
identify_hardware CHRX_HWID CHRX_HWDESC CHRX_HWYEAR CHRX_HWCPUF CHRX_HWSTATUS
ping_chrx_org "begin"
setup_and_validate_environment