|
48 | 48 | isArch= |
49 | 49 | isInstaller= |
50 | 50 | isContainer= |
| 51 | +isRoot= |
51 | 52 | hasIpv6Only= |
52 | 53 | hasTar= |
53 | 54 | hasCpio= |
@@ -519,20 +520,31 @@ importFacts() { |
519 | 520 | fi |
520 | 521 | filteredFacts=$(echo "$facts" | grep -E '^(has|is)[A-Za-z0-9_]+=\S+') |
521 | 522 | if [[ -z $filteredFacts ]]; then |
522 | | - 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" |
523 | 524 | fi |
524 | 525 | # make facts available in script |
525 | 526 | # shellcheck disable=SC2046 |
526 | 527 | export $(echo "$filteredFacts" | xargs) |
527 | 528 |
|
528 | 529 | # Necessary to prevent Bash erroring before printing out which fact had an issue |
529 | 530 | set +u |
530 | | - for var in isOs isArch isInstaller isContainer hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do |
| 531 | + for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do |
531 | 532 | if [[ -z ${!var} ]]; then |
532 | 533 | abort "Failed to retrieve fact $var from host" |
533 | 534 | fi |
534 | 535 | done |
535 | 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 |
536 | 548 | } |
537 | 549 |
|
538 | 550 | checkBuildLocally() { |
@@ -579,7 +591,6 @@ checkBuildLocally() { |
579 | 591 | } |
580 | 592 |
|
581 | 593 | generateHardwareConfig() { |
582 | | - local maybeSudo="$maybeSudo" |
583 | 594 | mkdir -p "$(dirname "$hardwareConfigPath")" |
584 | 595 | case "$hardwareConfigBackend" in |
585 | 596 | nixos-facter) |
@@ -703,9 +714,6 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr |
703 | 714 | # After kexec we explicitly set the user to root@ |
704 | 715 | sshConnection="root@${sshHost}" |
705 | 716 |
|
706 | | - # TODO: remove this after we reimport facts post-kexec and set this as a fact |
707 | | - maybeSudo="" |
708 | | -
|
709 | 717 | # waiting for machine to become available again |
710 | 718 | until runSsh -o ConnectTimeout=10 -- exit 0; do sleep 5; done |
711 | 719 |
|
@@ -872,13 +880,6 @@ main() { |
872 | 880 | abort "no setsid command found, but required to run the kexec script under a new session" |
873 | 881 | fi |
874 | 882 |
|
875 | | - maybeSudo="" |
876 | | - if [[ ${hasSudo-n} == "y" ]]; then |
877 | | - maybeSudo="sudo" |
878 | | - elif [[ ${hasDoas-n} == "y" ]]; then |
879 | | - maybeSudo="doas" |
880 | | - fi |
881 | | -
|
882 | 883 | if [[ ${isOs} != "Linux" ]]; then |
883 | 884 | abort "This script requires Linux as the operating system, but got $isOs" |
884 | 885 | fi |
|
0 commit comments