Mercurial > crates > nonstick
comparison testharness/install-test-harness.sh @ 165:c4b1e280463c
Make test script really work across platforms (?).
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Mon, 14 Jul 2025 18:56:55 -0400 |
| parents | d0bba0117456 |
| children | 77470e45e397 |
comparison
equal
deleted
inserted
replaced
| 164:d0bba0117456 | 165:c4b1e280463c |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 set -exo pipefail | 3 set -ex |
| 4 | 4 |
| 5 LINUX_BSD_CONF="/etc/pam.d/nonstick-testharness" | 5 LINUX_BSD_CONF="/etc/pam.d/nonstick-testharness" |
| 6 | 6 |
| 7 pam_library_path() { | 7 patch_pam_conf() { |
| 8 SRC="$1" | |
| 9 DST="$2" | |
| 10 LIB="$3" | |
| 11 sed "s#pam_testharness\.so#$LIB#" <"$SRC" >"$DST" | |
| 12 } | |
| 13 | |
| 14 setup_pam_conf() { | |
| 15 SRC="$1" | |
| 8 case "$(uname -s)" in | 16 case "$(uname -s)" in |
| 9 "Linux" | "SunOS") | 17 "Linux" | *BSD) |
| 10 echo "/usr/lib/security" | 18 # For Linux-PAM and OpenPAM, PAM is configured with the per-service files |
| 19 # in /etc/pam.d/... | |
| 20 sudo cp "$SRC" "$LINUX_BSD_CONF" | |
| 11 ;; | 21 ;; |
| 12 *BSD) | 22 "SunOS") |
| 13 echo "/usr/lib" | 23 # On SunOS, PAM has just the one configuration file, |
| 24 # with the service prepended to each line. | |
| 25 sudo cp /etc/pam.conf /etc/pam.conf.bak | |
| 26 sed 's/^\([^#]\)/nonstick-testharness \1/' <"$SRC" \ | |
| 27 | sudo tee -a /etc/pam.conf >/dev/null | |
| 14 ;; | 28 ;; |
| 15 *) | 29 *) |
| 16 echo "UNKNOWN OS!!!" | 30 echo "UNKNOWN OS!!!" |
| 17 return 1 | 31 return 1 |
| 18 ;; | 32 ;; |
| 19 esac | 33 esac |
| 20 } | 34 } |
| 21 | 35 |
| 22 setup_pam_conf() { | |
| 23 case "$(uname -s)" in | |
| 24 "Linux" | *BSD) | |
| 25 sudo cp nonstick_testharness.conf "$LINUX_BSD_CONF" | |
| 26 ;; | |
| 27 "SunOS") | |
| 28 sudo cp /etc/pam.conf /etc/pam.conf.bak | |
| 29 sed 's/^\([^#]\)/nonstick-testharness \1/' <./nonstick_testharness.conf \ | |
| 30 | sudo tee -a /etc/pam.conf >/dev/null | |
| 31 ;; | |
| 32 *) | |
| 33 echo "UNKNOWN OS!!!" | |
| 34 return 1 | |
| 35 ;; | |
| 36 esac | |
| 37 } | |
| 38 cleanup_pam_conf() { | 36 cleanup_pam_conf() { |
| 39 case "$(uname -s)" in | 37 case "$(uname -s)" in |
| 40 "Linux" | *BSD) | 38 "Linux" | *BSD) |
| 41 sudo rm "$LINUX_BSD_CONF" | 39 sudo rm "$LINUX_BSD_CONF" |
| 42 ;; | 40 ;; |
| 47 } | 45 } |
| 48 | 46 |
| 49 HERE="$(dirname -- "$0")" | 47 HERE="$(dirname -- "$0")" |
| 50 cd "$HERE" | 48 cd "$HERE" |
| 51 cargo build --release | 49 cargo build --release |
| 52 PAM_LIBRARY="$(pam_library_path)/pam_testharness.so" | |
| 53 | 50 |
| 54 cleanup() { | 51 cleanup() { |
| 55 sudo rm "$PAM_LIBRARY" | 52 rm -r "$MY_TEMP" |
| 53 sudo rm -r "$ROOT_TEMP" | |
| 56 cleanup_pam_conf | 54 cleanup_pam_conf |
| 57 } | 55 } |
| 58 | 56 |
| 57 MY_TEMP="$(mktemp -d -t nonstick-user-XXXXXX)" | |
| 58 ROOT_TEMP="$(sudo mktemp -d -t nonstick-root-XXXXXX)" | |
| 59 sudo chmod a+rx "$ROOT_TEMP" | |
| 60 PAM_LIBRARY="$ROOT_TEMP/pam_nonstick.so" | |
| 59 sudo cp ../target/release/libnonstick_testharness.so "$PAM_LIBRARY" | 61 sudo cp ../target/release/libnonstick_testharness.so "$PAM_LIBRARY" |
| 60 setup_pam_conf | 62 patch_pam_conf ./nonstick_testharness.conf "$MY_TEMP/nonstick-testharness" "$PAM_LIBRARY" |
| 63 setup_pam_conf "$MY_TEMP/nonstick-testharness" | |
| 61 trap cleanup EXIT | 64 trap cleanup EXIT |
| 62 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?" | 65 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?" |
