comparison testharness/install-test-harness.sh @ 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
comparison
equal deleted inserted replaced
163:a75a66cb4181 164:d0bba0117456
1 #!/bin/bash 1 #!/bin/sh
2 2
3 set -eo pipefail 3 set -exo pipefail
4
5 LINUX_BSD_CONF="/etc/pam.d/nonstick-testharness"
6
7 pam_library_path() {
8 case "$(uname -s)" in
9 "Linux" | "SunOS")
10 echo "/usr/lib/security"
11 ;;
12 *BSD)
13 echo "/usr/lib"
14 ;;
15 *)
16 echo "UNKNOWN OS!!!"
17 return 1
18 ;;
19 esac
20 }
21
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() {
39 case "$(uname -s)" in
40 "Linux" | *BSD)
41 sudo rm "$LINUX_BSD_CONF"
42 ;;
43 "SunOS")
44 sudo mv /etc/pam.conf.bak /etc/pam.conf
45 ;;
46 esac
47 }
4 48
5 HERE="$(dirname -- "$0")" 49 HERE="$(dirname -- "$0")"
6 echo "$HERE" 50 cd "$HERE"
7 cargo build --release 51 cargo build --release
52 PAM_LIBRARY="$(pam_library_path)/pam_testharness.so"
8 53
9 sudo mkdir -p /lib/security 54 cleanup() {
10 sudo cp ../target/release/libnonstick_testharness.so /lib/security/pam_testharness.so 55 sudo rm "$PAM_LIBRARY"
11 sudo cp nonstick_testharness.conf /etc/pam.d/nonstick-testharness 56 cleanup_pam_conf
12 trap 'sudo rm /etc/pam.d/nonstick-testharness; sudo rm /lib/security/pam_testharness.so' EXIT 57 }
58
59 sudo cp ../target/release/libnonstick_testharness.so "$PAM_LIBRARY"
60 setup_pam_conf
61 trap cleanup EXIT
13 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?" 62 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?"