From a0369b14f4ad17b021ce4b06f97fb1081f419c44 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 10:46:29 -0400 Subject: Test the installer --- tests/install-darwin.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/install-darwin.sh (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh new file mode 100644 index 000000000000..30a3cc3d36b1 --- /dev/null +++ b/tests/install-darwin.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +cleanup() { + PLIST="/Library/LaunchDaemons/org.nixos.nix-daemon.plist" + if sudo launchctl list | grep -q nix-daemon; then + sudo launchctl unload "$PLIST" + fi + + if [ -f "$PLIST" ]; then + sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist + fi + + profiles=(/etc/profile /etc/bashrc /etc/zshrc) + for profile in "${profiles[@]}"; do + if [ -f "${profile}.backup-before-nix" ]; then + sudo mv "${profile}.backup-before-nix" "${profile}" + fi + done + + for i in $(seq 1 $(sysctl -n hw.ncpu)); do + sudo /usr/bin/dscl . -delete "/Users/nixbld$i" || true + done + sudo /usr/bin/dscl . -delete "/Groups/nixbld" || true + + + sudo rm -rf /etc/nix \ + /nix \ + /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels \ + "$USER/.nix-profile" "$USER/.nix-defexpr" "$USER/.nix-channels" +} + +verify() { + output=$(echo "nix-shell -p bash --run 'echo toow | rev'" | bash -l) + test "$output" = "woot" +} + +scratch=$(mktemp -d -t tmp.XXXXXXXXXX) +function finish { + rm -rf "$scratch" +} +trap finish EXIT + +# First setup Nix +cleanup +curl https://nixos.org/nix/install | bash +verify + + +( + nix-build ./release.nix -A binaryTarball.x86_64-darwin + cp ./result/nix-*.tar.bz2 $scratch/nix.tar.bz2 +) + +( + cd $scratch + tar -xf ./nix.tar.bz2 + + cd nix-* + + set -eux + + cat ~/.profile | grep -v nix-profile > ~/.profile-next + mv ~/.profile-next ~/.profile + + cleanup + + yes | ./install + verify + + cleanup + + yes | ./install + verify + + cleanup +) -- cgit 1.4.1 From bc647fd2991deffcc1ab400912e641ac4e4d016f Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 12:58:37 -0400 Subject: chmod --- tests/install-darwin.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/install-darwin.sh (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh old mode 100644 new mode 100755 -- cgit 1.4.1 From 61ea9e9867ad426eee064242963299553b8db9f3 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 17:10:14 -0400 Subject: Run nix-build inside a fresh bash login --- tests/install-darwin.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index 30a3cc3d36b1..4a6ab7d6471a 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -eux + cleanup() { PLIST="/Library/LaunchDaemons/org.nixos.nix-daemon.plist" if sudo launchctl list | grep -q nix-daemon; then @@ -47,7 +49,10 @@ verify ( - nix-build ./release.nix -A binaryTarball.x86_64-darwin + ( + echo "cd $(pwd)" + echo nix-build ./release.nix -A binaryTarball.x86_64-darwin + ) | bash -l cp ./result/nix-*.tar.bz2 $scratch/nix.tar.bz2 ) -- cgit 1.4.1 From 92ca93528fe7d29b8909a89b0f9c7a9e23627fd5 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 20:29:58 -0400 Subject: Clean up nix hints from the old insstaller --- tests/install-darwin.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index 4a6ab7d6471a..9084d92c23e1 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -19,6 +19,13 @@ cleanup() { fi done + for file in ~/.bash_profile ~/.bash_login ~/.profile ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin; do + cat "$file" | grep -v nix-profile > "$file.next" + mv "$file.next" "$file" + done + + + for i in $(seq 1 $(sysctl -n hw.ncpu)); do sudo /usr/bin/dscl . -delete "/Users/nixbld$i" || true done @@ -64,9 +71,6 @@ verify set -eux - cat ~/.profile | grep -v nix-profile > ~/.profile-next - mv ~/.profile-next ~/.profile - cleanup yes | ./install -- cgit 1.4.1 From 3839dda2ecc0444db1469757b4a3e1f4f776fe9d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 20:31:33 -0400 Subject: Only clean if the file exists --- tests/install-darwin.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index 9084d92c23e1..b553f710527d 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -20,8 +20,10 @@ cleanup() { done for file in ~/.bash_profile ~/.bash_login ~/.profile ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin; do - cat "$file" | grep -v nix-profile > "$file.next" - mv "$file.next" "$file" + if [ -e "$file" ]; then + cat "$file" | grep -v nix-profile > "$file.next" + mv "$file.next" "$file" + fi done -- cgit 1.4.1 From 73a57a2f22668394740e1f642573b67a1316dee7 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jul 2017 20:43:57 -0400 Subject: Cleanup and more specificity around set -e --- tests/install-darwin.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index b553f710527d..d2a7ab456ea1 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -26,14 +26,11 @@ cleanup() { fi done - - for i in $(seq 1 $(sysctl -n hw.ncpu)); do sudo /usr/bin/dscl . -delete "/Users/nixbld$i" || true done sudo /usr/bin/dscl . -delete "/Groups/nixbld" || true - sudo rm -rf /etc/nix \ /nix \ /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels \ @@ -41,7 +38,10 @@ cleanup() { } verify() { + set +e output=$(echo "nix-shell -p bash --run 'echo toow | rev'" | bash -l) + set -e + test "$output" = "woot" } @@ -58,10 +58,12 @@ verify ( + set +e ( echo "cd $(pwd)" echo nix-build ./release.nix -A binaryTarball.x86_64-darwin ) | bash -l + set -e cp ./result/nix-*.tar.bz2 $scratch/nix.tar.bz2 ) -- cgit 1.4.1 From 1c7ce2a018a081dd90dfefee6d1ca7e0c9fd66d9 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Thu, 13 Jul 2017 17:22:54 -0400 Subject: Assume yes if we have no TTY Starve the TTY of input to ensure this works, but provide yes to the current installer to handle the current broken case. --- scripts/install-darwin-multi-user.sh | 11 +++++++++++ tests/install-darwin.sh | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh index 01a0e4ffb4e1..368d9957e110 100644 --- a/scripts/install-darwin-multi-user.sh +++ b/scripts/install-darwin-multi-user.sh @@ -43,6 +43,12 @@ readonly EXTRACTED_NIX_PATH="$(dirname "$0")" readonly ROOT_HOME="/var/root" +if [ -t 0 ]; then + readonly IS_HEADLESS='no' +else + readonly IS_HEADLESS='yes' +fi + contactme() { echo "We'd love to help if you need it." echo "" @@ -173,6 +179,11 @@ failure() { ui_confirm() { _textout "$GREEN$GREEN_UL" "$1" + if [ "$IS_HEADLESS" = "yes" ]; then + echo "No TTY, assuming you would say yes :)" + return 0 + fi + local prompt="[y/n] " echo -n "$prompt" while read -r y; do diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index d2a7ab456ea1..b7f87467287c 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -53,7 +53,8 @@ trap finish EXIT # First setup Nix cleanup -curl https://nixos.org/nix/install | bash +curl -o install https://nixos.org/nix/install +yes | bash ./install verify @@ -82,7 +83,7 @@ verify cleanup - yes | ./install + echo -n "" | ./install verify cleanup -- cgit 1.4.1 From ce2281e6d86aa1b461dd27f86b2a71145e85ac8d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Thu, 13 Jul 2017 18:01:22 -0400 Subject: Ensure PINCH_ME_IM_SILLY allows a /nix/store to stick around between builds Also output in the status report that the user is very silly --- scripts/install-darwin-multi-user.sh | 8 +++----- tests/install-darwin.sh | 7 ++++++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh index 368d9957e110..b1d258e0cade 100644 --- a/scripts/install-darwin-multi-user.sh +++ b/scripts/install-darwin-multi-user.sh @@ -408,6 +408,9 @@ setup_report() { row " Build Users" "$NIX_USER_COUNT" row " Build Group ID" "$NIX_BUILD_GROUP_ID" row "Build Group Name" "$NIX_BUILD_GROUP_NAME" + if [ "${PINCH_ME_IM_SILLY:-}" != "" ]; then + row " Silliness" "Very Silly" + fi subheader "build users:" @@ -757,11 +760,6 @@ main() { exit 1 fi - if [ "${PINCH_ME_IM_SILLY:-}" != "" ]; then - exit 1 - fi - - create_build_group create_build_users create_directories diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index b7f87467287c..3f64944ef814 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -80,11 +80,16 @@ verify yes | ./install verify - cleanup echo -n "" | ./install verify + cleanup + sudo mkdir -p /nix/store + sudo touch /nix/store/.silly-hint + echo -n "" | PINCH_ME_IM_SILLY=true ./install + verify + test -e /nix/store/.silly-hint cleanup ) -- cgit 1.4.1 From 12f6bb33d2cf56e8adf482950734a9af5f78a496 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Thu, 13 Jul 2017 19:03:35 -0400 Subject: If there is no TTY, also skip verbose sudo messages --- scripts/install-darwin-multi-user.sh | 36 +++++++++++++++++++++++++++++++++--- tests/install-darwin.sh | 1 + 2 files changed, 34 insertions(+), 3 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh index b1d258e0cade..cde40a7f25e8 100644 --- a/scripts/install-darwin-multi-user.sh +++ b/scripts/install-darwin-multi-user.sh @@ -49,6 +49,14 @@ else readonly IS_HEADLESS='yes' fi +headless() { + if [ "$IS_HEADLESS" = "yes" ]; then + return 0 + else + return 1 + fi +} + contactme() { echo "We'd love to help if you need it." echo "" @@ -179,7 +187,7 @@ failure() { ui_confirm() { _textout "$GREEN$GREEN_UL" "$1" - if [ "$IS_HEADLESS" = "yes" ]; then + if headless; then echo "No TTY, assuming you would say yes :)" return 0 fi @@ -221,9 +229,10 @@ __sudo() { _sudo() { local expl="$1" shift - if __sudo "$expl" "$*"; then - sudo "$@" + if ! headless; then + __sudo "$expl" "$*" fi + sudo "$@" } @@ -620,6 +629,27 @@ EOF chat_about_sudo() { header "let's talk about sudo" + if headless; then + cat < Date: Fri, 14 Jul 2017 06:28:24 -0400 Subject: Rename PINCH_ME_IM_SILLY to ALLOW_PREEXISTING_INSTALLATION --- scripts/install-darwin-multi-user.sh | 6 +++--- tests/install-darwin.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/install-darwin.sh') diff --git a/scripts/install-darwin-multi-user.sh b/scripts/install-darwin-multi-user.sh index cde40a7f25e8..a2e120bf8625 100644 --- a/scripts/install-darwin-multi-user.sh +++ b/scripts/install-darwin-multi-user.sh @@ -417,8 +417,8 @@ setup_report() { row " Build Users" "$NIX_USER_COUNT" row " Build Group ID" "$NIX_BUILD_GROUP_ID" row "Build Group Name" "$NIX_BUILD_GROUP_NAME" - if [ "${PINCH_ME_IM_SILLY:-}" != "" ]; then - row " Silliness" "Very Silly" + if [ "${ALLOW_PREEXISTING_INSTALLATION:-}" != "" ]; then + row "Preexisting Install" "Allowed" fi subheader "build users:" @@ -777,7 +777,7 @@ main() { welcome_to_nix chat_about_sudo - if [ "${PINCH_ME_IM_SILLY:-}" = "" ]; then + if [ "${ALLOW_PREEXISTING_INSTALLATION:-}" = "" ]; then validate_starting_assumptions fi diff --git a/tests/install-darwin.sh b/tests/install-darwin.sh index eb251fa39394..c99ce84acab0 100755 --- a/tests/install-darwin.sh +++ b/tests/install-darwin.sh @@ -88,7 +88,7 @@ verify sudo mkdir -p /nix/store sudo touch /nix/store/.silly-hint - echo -n "" | PINCH_ME_IM_SILLY=true ./install + echo -n "" | ALLOW_PREEXISTING_INSTALLATION=true ./install verify test -e /nix/store/.silly-hint -- cgit 1.4.1