Skip to content

Commit 8dd264c

Browse files
committed
add get-facts checks for tools
1 parent 83ceadd commit 8dd264c

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/get-facts.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ hasDoas=$(has doas)
1919
hasWget=$(has wget)
2020
hasCurl=$(has curl)
2121
hasSetsid=$(if [ "$(has setsid)" = "y" ] && setsid --wait true 2>/dev/null; then echo "y"; else echo "n"; fi)
22+
hasGrep=$(has grep)
23+
hasSystemdInhibit=$(has systemd-inhibit)
2224
hasNixOSFacter=$(command -v nixos-facter >/dev/null && echo "y" || echo "n")
2325
FACTS

src/nixos-anywhere.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ hasDoas=
5757
hasWget=
5858
hasCurl=
5959
hasSetsid=
60+
hasGrep=
61+
hasSystemdInhibit=
6062
hasNixOSFacter=
6163

6264
tempDir=$(mktemp -d)
@@ -585,7 +587,7 @@ importFacts() {
585587

586588
# Necessary to prevent Bash erroring before printing out which fact had an issue
587589
set +u
588-
for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do
590+
for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid hasGrep hasSystemdInhibit; do
589591
if [[ -z ${!var} ]]; then
590592
abort "Failed to retrieve fact $var from host"
591593
fi
@@ -915,28 +917,30 @@ SSH
915917
nixosReboot() {
916918
step Rebooting
917919
918-
# disable debug output temporarily to prevent log spam
919-
set +x
920-
921-
local inhibited
922-
inhibited=$(
923-
runSsh sh <<SSH
924-
if command -v systemd-inhibit >/dev/null && systemd-inhibit --list | grep -q 'shutdown'; then
925-
systemd-inhibit --list
926-
fi
920+
if [[ $hasSystemdInhibit == "y" ]] && [[ $hasGrep == "y" ]]; then
921+
# disable debug output temporarily to prevent log spam
922+
set +x
923+
924+
local inhibited
925+
inhibited=$(
926+
runSsh sh <<SSH
927+
if systemd-inhibit --list | grep -q 'shutdown'; then
928+
systemd-inhibit --list
929+
fi
927930
SSH
928-
)
929-
if [ -n "${inhibited}" ]; then
930-
echo "WARNING: Reboot is currently inhibited. Manual reboot may be required. Run 'systemd-inhibit --list' on the target for further details" 2>&1
931+
)
932+
if [ -n "${inhibited}" ]; then
933+
echo "WARNING: Reboot is currently inhibited. Manual reboot may be required. Run 'systemd-inhibit --list' on the target for further details" 2>&1
934+
if [[ -n ${enableDebug} ]]; then
935+
echo "${inhibited}" 2>&1
936+
fi
937+
fi
938+
931939
if [[ -n ${enableDebug} ]]; then
932-
echo "${inhibited}" 2>&1
940+
set -x
933941
fi
934942
fi
935943
936-
if [[ -n ${enableDebug} ]]; then
937-
set -x
938-
fi
939-
940944
runSsh sh <<SSH
941945
if command -v zpool >/dev/null && [ "\$(zpool list)" != "no pools available" ]; then
942946
# we always want to export the zfs pools so people can boot from it without force import

0 commit comments

Comments
 (0)