@@ -46,9 +46,9 @@ envPassword=n
46
46
# Facts set by get-facts.sh
47
47
isOs=
48
48
isArch=
49
- isKexec=
50
49
isInstaller=
51
50
isContainer=
51
+ isRoot=
52
52
hasIpv6Only=
53
53
hasTar=
54
54
hasCpio=
@@ -520,17 +520,31 @@ importFacts() {
520
520
fi
521
521
filteredFacts=$( echo " $facts " | grep -E ' ^(has|is)[A-Za-z0-9_]+=\S+' )
522
522
if [[ -z $filteredFacts ]]; then
523
- abort " Retrieving host facts via ssh failed. Check with --debug for the root cause, unless you have done so already"
523
+ abort " Retrieving host facts via SSH failed. Check with --debug for the root cause, unless you have done so already"
524
524
fi
525
525
# make facts available in script
526
526
# shellcheck disable=SC2046
527
527
export $( echo " $filteredFacts " | xargs)
528
528
529
- for var in isOs isArch isKexec isInstaller isContainer hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do
529
+ # Necessary to prevent Bash erroring before printing out which fact had an issue
530
+ set +u
531
+ for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do
530
532
if [[ -z ${! var} ]]; then
531
533
abort " Failed to retrieve fact $var from host"
532
534
fi
533
535
done
536
+ set -u
537
+
538
+ if [[ ${isRoot} == " y" ]]; then
539
+ maybeSudo=
540
+ elif [[ ${hasSudo} == " y" ]]; then
541
+ maybeSudo=sudo
542
+ elif [[ ${hasDoas} == " y" ]]; then
543
+ maybeSudo=doas
544
+ else
545
+ # shellcheck disable=SC2016
546
+ abort ' Unable to find a command to use to escalate privileges: Could not find `sudo` or `doas`'
547
+ fi
534
548
}
535
549
536
550
checkBuildLocally () {
@@ -577,7 +591,6 @@ checkBuildLocally() {
577
591
}
578
592
579
593
generateHardwareConfig () {
580
- local maybeSudo=" $maybeSudo "
581
594
mkdir -p " $( dirname " $hardwareConfigPath " ) "
582
595
case " $hardwareConfigBackend " in
583
596
nixos-facter)
@@ -618,7 +631,7 @@ generateHardwareConfig() {
618
631
}
619
632
620
633
runKexec () {
621
- if [[ ${isKexec} == " y " ]] || [[ ${ isInstaller} == " y" ]]; then
634
+ if [[ ${isInstaller} == " y" ]]; then
622
635
return
623
636
fi
624
637
@@ -701,11 +714,14 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
701
714
# After kexec we explicitly set the user to root@
702
715
sshConnection=" root@${sshHost} "
703
716
704
- # TODO: remove this after we reimport facts post-kexec and set this as a fact
705
- maybeSudo=" "
706
-
707
717
# waiting for machine to become available again
708
718
until runSsh -o ConnectTimeout=10 -- exit 0; do sleep 5; done
719
+
720
+ importFacts
721
+
722
+ if [[ ${isInstaller} == " n" ]]; then
723
+ abort " Failed to kexec into NixOS installer"
724
+ fi
709
725
}
710
726
711
727
runDisko () {
@@ -864,13 +880,6 @@ main() {
864
880
abort " no setsid command found, but required to run the kexec script under a new session"
865
881
fi
866
882
867
- maybeSudo=" "
868
- if [[ ${hasSudo-n} == " y" ]]; then
869
- maybeSudo=" sudo"
870
- elif [[ ${hasDoas-n} == " y" ]]; then
871
- maybeSudo=" doas"
872
- fi
873
-
874
883
if [[ ${isOs} != " Linux" ]]; then
875
884
abort " This script requires Linux as the operating system, but got $isOs "
876
885
fi
0 commit comments