mirror of
https://github.com/nix-community/nixos-anywhere.git
synced 2024-10-05 20:27:20 +03:00
fix bashism
[[ ]] is not available in POSIX sh, and test -o is not well defined either. Move the facts-gathering script out so it can be tested with shellcheck.
This commit is contained in:
parent
88a60aa8b8
commit
3170c45be4
@ -37,13 +37,13 @@ stdenv.mkDerivation {
|
|||||||
src = ./..;
|
src = ./..;
|
||||||
nativeBuildInputs = [ makeWrapper ];
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
install -D -m 0755 src/nixos-anywhere.sh $out/bin/nixos-anywhere
|
install -D --target-directory=$out/libexec/nixos-anywhere/ -m 0755 src/*.sh
|
||||||
|
|
||||||
# We prefer the system's openssh over our own, since it might come with features not present in ours:
|
# We prefer the system's openssh over our own, since it might come with features not present in ours:
|
||||||
# https://github.com/nix-community/nixos-anywhere/issues/62
|
# https://github.com/nix-community/nixos-anywhere/issues/62
|
||||||
#
|
#
|
||||||
# We also prefer system rsync to prevent crashes between rsync and ssh.
|
# We also prefer system rsync to prevent crashes between rsync and ssh.
|
||||||
wrapProgram $out/bin/nixos-anywhere \
|
makeShellWrapper $out/libexec/nixos-anywhere/nixos-anywhere.sh $out/bin/nixos-anywhere \
|
||||||
--prefix PATH : ${lib.makeBinPath runtimeDeps} --suffix PATH : ${lib.makeBinPath [ openssh ]}
|
--prefix PATH : ${lib.makeBinPath runtimeDeps} --suffix PATH : ${lib.makeBinPath [ openssh ]}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
20
src/get-facts.sh
Executable file
20
src/get-facts.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -efu "${enable_debug:-}"
|
||||||
|
has() {
|
||||||
|
command -v "$1" >/dev/null && echo "y" || echo "n"
|
||||||
|
}
|
||||||
|
is_nixos=$(if test -f /etc/os-release && grep -q ID=nixos /etc/os-release; then echo "y"; else echo "n"; fi)
|
||||||
|
cat <<FACTS
|
||||||
|
is_os=$(uname)
|
||||||
|
is_arch=$(uname -m)
|
||||||
|
is_kexec=$(if test -f /etc/is_kexec; then echo "y"; else echo "n"; fi)
|
||||||
|
is_nixos=$is_nixos
|
||||||
|
is_installer=$(if [ "$is_nixos" = "y" ] && grep -q VARIANT_ID=installer /etc/os-release; then echo "y"; else echo "n"; fi)
|
||||||
|
is_container=$(if [ "$(has systemd-detect-virt)" = "y" ]; then systemd-detect-virt --container; else echo "none"; fi)
|
||||||
|
has_tar=$(has tar)
|
||||||
|
has_sudo=$(has sudo)
|
||||||
|
has_doas=$(has doas)
|
||||||
|
has_wget=$(has wget)
|
||||||
|
has_curl=$(has curl)
|
||||||
|
has_setsid=$(has setsid)
|
||||||
|
FACTS
|
@ -62,6 +62,7 @@ step() {
|
|||||||
echo "### $* ###"
|
echo "### $* ###"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
here=$(dirname "${BASH_SOURCE[0]}")
|
||||||
kexec_url=""
|
kexec_url=""
|
||||||
enable_debug=""
|
enable_debug=""
|
||||||
maybe_reboot="sleep 6 && reboot"
|
maybe_reboot="sleep 6 && reboot"
|
||||||
@ -321,29 +322,7 @@ done
|
|||||||
|
|
||||||
import_facts() {
|
import_facts() {
|
||||||
local facts filtered_facts
|
local facts filtered_facts
|
||||||
if ! facts=$(
|
if ! facts=$(ssh_ -o ConnectTimeout=10 enable_debug=$enable_debug sh -- <"$here"/get-facts.sh); then
|
||||||
ssh_ -o ConnectTimeout=10 sh -- <<SSH
|
|
||||||
set -efu ${enable_debug}
|
|
||||||
has(){
|
|
||||||
command -v "\$1" >/dev/null && echo "y" || echo "n"
|
|
||||||
}
|
|
||||||
is_nixos=\$(if test -f /etc/os-release && grep -q ID=nixos /etc/os-release; then echo "y"; else echo "n"; fi)
|
|
||||||
cat <<FACTS
|
|
||||||
is_os=\$(uname)
|
|
||||||
is_arch=\$(uname -m)
|
|
||||||
is_kexec=\$(if test -f /etc/is_kexec; then echo "y"; else echo "n"; fi)
|
|
||||||
is_nixos=\$is_nixos
|
|
||||||
is_installer=\$(if [[ "\$is_nixos" == "y" ]] && grep -q VARIANT_ID=installer /etc/os-release; then echo "y"; else echo "n"; fi)
|
|
||||||
is_container=\$(if [[ "\$(has systemd-detect-virt)" == "y" ]]; then systemd-detect-virt --container; else echo "none"; fi)
|
|
||||||
has_tar=\$(has tar)
|
|
||||||
has_sudo=\$(has sudo)
|
|
||||||
has_doas=\$(has doas)
|
|
||||||
has_wget=\$(has wget)
|
|
||||||
has_curl=\$(has curl)
|
|
||||||
has_setsid=\$(has setsid)
|
|
||||||
FACTS
|
|
||||||
SSH
|
|
||||||
); then
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
filtered_facts=$(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+')
|
filtered_facts=$(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+')
|
||||||
@ -510,13 +489,13 @@ export PATH="\$PATH:/run/current-system/sw/bin"
|
|||||||
# needed for installation if initrd-secrets are used
|
# needed for installation if initrd-secrets are used
|
||||||
mkdir -p /mnt/tmp
|
mkdir -p /mnt/tmp
|
||||||
chmod 777 /mnt/tmp
|
chmod 777 /mnt/tmp
|
||||||
if [[ ${copy_host_keys-n} == "y" ]]; then
|
if [ ${copy_host_keys-n} = "y" ]; then
|
||||||
# NB we copy host keys that are in turn copied by kexec installer.
|
# NB we copy host keys that are in turn copied by kexec installer.
|
||||||
mkdir -m 755 -p /mnt/etc/ssh
|
mkdir -m 755 -p /mnt/etc/ssh
|
||||||
for p in /etc/ssh/ssh_host_*; do
|
for p in /etc/ssh/ssh_host_*; do
|
||||||
# Skip if the source file does not exist (i.e. glob did not match any files)
|
# Skip if the source file does not exist (i.e. glob did not match any files)
|
||||||
# or the destination already exists (e.g. copied with --extra-files).
|
# or the destination already exists (e.g. copied with --extra-files).
|
||||||
if [ ! -e "\$p" -o -e "/mnt/\$p" ]; then
|
if [ ! -e "\$p" ] || [ -e "/mnt/\$p" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
cp -a "\$p" "/mnt/\$p"
|
cp -a "\$p" "/mnt/\$p"
|
||||||
|
Loading…
Reference in New Issue
Block a user