Skip to content

Commit 7125e73

Browse files
Mic92mergify[bot]
authored andcommitted
add a main function
1 parent 9fb92e0 commit 7125e73

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

src/nixos-anywhere.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -527,52 +527,56 @@ SSH
527527

528528
}
529529

530-
uploadSshKey
530+
main() {
531+
uploadSshKey
531532

532-
importFacts
533+
importFacts
533534

534-
if [[ ${hasTar-n} == "n" ]]; then
535-
abort "no tar command found, but required to unpack kexec tarball"
536-
fi
535+
if [[ ${hasTar-n} == "n" ]]; then
536+
abort "no tar command found, but required to unpack kexec tarball"
537+
fi
537538

538-
if [[ ${hasSetsid-n} == "n" ]]; then
539-
abort "no setsid command found, but required to run the kexec script under a new session"
540-
fi
539+
if [[ ${hasSetsid-n} == "n" ]]; then
540+
abort "no setsid command found, but required to run the kexec script under a new session"
541+
fi
541542

542-
maybeSudo=""
543-
if [[ ${hasSudo-n} == "y" ]]; then
544-
maybeSudo="sudo"
545-
elif [[ ${hasDoas-n} == "y" ]]; then
546-
maybeSudo="doas"
547-
fi
543+
maybeSudo=""
544+
if [[ ${hasSudo-n} == "y" ]]; then
545+
maybeSudo="sudo"
546+
elif [[ ${hasDoas-n} == "y" ]]; then
547+
maybeSudo="doas"
548+
fi
548549

549-
if [[ ${isOs-n} != "Linux" ]]; then
550-
abort "This script requires Linux as the operating system, but got $isOs"
551-
fi
550+
if [[ ${isOs-n} != "Linux" ]]; then
551+
abort "This script requires Linux as the operating system, but got $isOs"
552+
fi
552553

553-
if [[ ${phases[kexec]-} == 1 ]]; then
554-
runKexec
555-
fi
554+
if [[ ${phases[kexec]-} == 1 ]]; then
555+
runKexec
556+
fi
556557

557-
# Installation will fail if non-root user is used for installer.
558-
# Switch to root user by copying authorized_keys.
559-
if [[ ${isInstaller-n} == "y" ]] && [[ ${sshUser} != "root" ]]; then
560-
# Allow copy to fail if authorized_keys does not exist, like if using /etc/ssh/authorized_keys.d/
561-
runSsh "${maybeSudo} mkdir -p /root/.ssh; ${maybeSudo} cp ~/.ssh/authorized_keys /root/.ssh || true"
562-
sshConnection="root@${sshHost}"
563-
fi
558+
# Installation will fail if non-root user is used for installer.
559+
# Switch to root user by copying authorized_keys.
560+
if [[ ${isInstaller-n} == "y" ]] && [[ ${sshUser} != "root" ]]; then
561+
# Allow copy to fail if authorized_keys does not exist, like if using /etc/ssh/authorized_keys.d/
562+
runSsh "${maybeSudo} mkdir -p /root/.ssh; ${maybeSudo} cp ~/.ssh/authorized_keys /root/.ssh || true"
563+
sshConnection="root@${sshHost}"
564+
fi
564565

565-
if [[ ${phases[disko]-} == 1 ]]; then
566-
runDisko "$diskoScript"
567-
fi
566+
if [[ ${phases[disko]-} == 1 ]]; then
567+
runDisko "$diskoScript"
568+
fi
568569

569-
if [[ ${phases[install]-} == 1 ]]; then
570-
nixosInstall
571-
fi
570+
if [[ ${phases[install]-} == 1 ]]; then
571+
nixosInstall
572+
fi
572573

573-
if [[ ${phases[reboot]-} == 1 ]]; then
574-
step Waiting for the machine to become unreachable due to reboot
575-
while runSshTimeout -- exit 0; do sleep 1; done
576-
fi
574+
if [[ ${phases[reboot]-} == 1 ]]; then
575+
step Waiting for the machine to become unreachable due to reboot
576+
while runSshTimeout -- exit 0; do sleep 1; done
577+
fi
578+
579+
step "Done!"
580+
}
577581

578-
step "Done!"
582+
main

0 commit comments

Comments
 (0)