changeset 164:d0bba0117456

make test script more cross platform?
author Paul Fisher <paul@pfish.zone>
date Mon, 14 Jul 2025 18:12:14 -0400
parents a75a66cb4181
children c4b1e280463c
files testharness/install-test-harness.sh
diffstat 1 files changed, 56 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/testharness/install-test-harness.sh	Mon Jul 14 17:40:11 2025 -0400
+++ b/testharness/install-test-harness.sh	Mon Jul 14 18:12:14 2025 -0400
@@ -1,13 +1,62 @@
-#!/bin/bash
+#!/bin/sh
+
+set -exo pipefail
+
+LINUX_BSD_CONF="/etc/pam.d/nonstick-testharness"
+
+pam_library_path() {
+  case "$(uname -s)" in
+  "Linux" | "SunOS")
+    echo "/usr/lib/security"
+    ;;
+  *BSD)
+    echo "/usr/lib"
+    ;;
+  *)
+    echo "UNKNOWN OS!!!"
+    return 1
+    ;;
+  esac
+}
 
-set -eo pipefail
+setup_pam_conf() {
+  case "$(uname -s)" in
+  "Linux" | *BSD)
+    sudo cp nonstick_testharness.conf "$LINUX_BSD_CONF"
+    ;;
+  "SunOS")
+    sudo cp /etc/pam.conf /etc/pam.conf.bak
+    sed 's/^\([^#]\)/nonstick-testharness \1/' <./nonstick_testharness.conf \
+      | sudo tee -a /etc/pam.conf >/dev/null
+    ;;
+  *)
+    echo "UNKNOWN OS!!!"
+    return 1
+    ;;
+  esac
+}
+cleanup_pam_conf() {
+  case "$(uname -s)" in
+  "Linux" | *BSD)
+    sudo rm "$LINUX_BSD_CONF"
+    ;;
+  "SunOS")
+    sudo mv /etc/pam.conf.bak /etc/pam.conf
+    ;;
+  esac
+}
 
 HERE="$(dirname -- "$0")"
-echo "$HERE"
+cd "$HERE"
 cargo build --release
+PAM_LIBRARY="$(pam_library_path)/pam_testharness.so"
 
-sudo mkdir -p /lib/security
-sudo cp ../target/release/libnonstick_testharness.so /lib/security/pam_testharness.so
-sudo cp nonstick_testharness.conf /etc/pam.d/nonstick-testharness
-trap 'sudo rm /etc/pam.d/nonstick-testharness; sudo rm /lib/security/pam_testharness.so' EXIT
+cleanup() {
+  sudo rm "$PAM_LIBRARY"
+  cleanup_pam_conf
+}
+
+sudo cp ../target/release/libnonstick_testharness.so "$PAM_LIBRARY"
+setup_pam_conf
+trap cleanup EXIT
 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?"
\ No newline at end of file