From f5da2577ddc924c0ee725fe9729cbf32b3f44808 Mon Sep 17 00:00:00 2001 From: jleeuwes Date: Sun, 5 Apr 2020 22:31:17 +0200 Subject: [PATCH] Debian 10 fixes (#51) * Fix missing curl/wget not being detected If `which curl` failed, a function `curl` would always be created, whether or not `wget` is present. So `req curl || req wget` (or even `req curl`) would never trigger `ERROR: Missing both curl and wget`. * Install curl on Debian In newer versions of Debian, wget is not installed by default and neither is curl. So install curl if wget is missing and apt-get is present. Behavior on other platforms should stay the same with this change. --- nixos-infect | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/nixos-infect b/nixos-infect index 8ce708a..9d89f9f 100755 --- a/nixos-infect +++ b/nixos-infect @@ -163,8 +163,15 @@ prepareEnv() { export USER="root" export HOME="/root" + # Nix installer tries to use sudo regardless of whether we're already uid 0 + #which sudo || { sudo() { eval "$@"; }; export -f sudo; } + # shellcheck disable=SC2174 + mkdir -p -m 0755 /nix +} + +fakeCurlUsingWget() { # Use adapted wget if curl is missing - which curl || { \ + which wget && { \ curl() { eval "wget $( (local isStdout=1 @@ -188,11 +195,6 @@ prepareEnv() { )| tr '\n' ' ' )" }; export -f curl; } - - # Nix installer tries to use sudo regardless of whether we're already uid 0 - #which sudo || { sudo() { eval "$@"; }; export -f sudo; } - # shellcheck disable=SC2174 - mkdir -p -m 0755 /nix } req() { @@ -201,10 +203,14 @@ req() { checkEnv() { # Perform some easy fixups before checking + # TODO prevent multiple calls to apt-get update which dnf && dnf install -y perl-Digest-SHA # Fedora 24 which bzcat || (which yum && yum install -y bzip2) \ || (which apt-get && apt-get update && apt-get install -y bzip2) \ || true + which curl || fakeCurlUsingWget \ + || (which apt-get && apt-get update && apt-get install -y curl) \ + || true [[ "$(whoami)" == "root" ]] || { echo "ERROR: Must run as root"; return 1; }