tst-pam_motd2.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. TST_DIR="tst-pam_motd2.d"
  3. function tst_cleanup() {
  4. rm -rf "${TST_DIR}"
  5. rm -f tst-pam_motd2.out
  6. }
  7. mkdir -p ${TST_DIR}
  8. mkdir -p ${TST_DIR}/etc/motd.d
  9. mkdir -p ${TST_DIR}/run/motd.d
  10. mkdir -p ${TST_DIR}/usr/lib/motd.d
  11. echo "motd: /etc/motd" > ${TST_DIR}/etc/motd
  12. echo "motd: /run/motd" > ${TST_DIR}/run/motd
  13. echo "motd: /usr/lib/motd" > ${TST_DIR}/usr/lib/motd
  14. # Drop a motd file in test directories such that every overriding
  15. # condition (for 3 directories in this case) will be seen.
  16. echo "motd: e0r0u1 in usr/lib - will show" > ${TST_DIR}/usr/lib/motd.d/e0r0u1.motd
  17. echo "motd: e0r1u0 in run - will show" > ${TST_DIR}/run/motd.d/e0r1u0.motd
  18. echo "motd: e0r1u1 in usr/lib - not show" > ${TST_DIR}/usr/lib/motd.d/e0r1u1.motd
  19. echo "motd: e0r1u1 in run - will show" > ${TST_DIR}/run/motd.d/e0r1u1.motd
  20. echo "motd: e1r0u0 in etc - will show" > ${TST_DIR}/etc/motd.d/e1r0u0.motd
  21. echo "motd: e1r0u1 in usr/lib - not show" > ${TST_DIR}/usr/lib/motd.d/e1r0u1.motd
  22. echo "motd: e1r0u1 in etc - will show" > ${TST_DIR}/etc/motd.d/e1r0u1.motd
  23. echo "motd: e1r1u0 in run - not show" > ${TST_DIR}/run/motd.d/e1r1u0.motd
  24. echo "motd: e1r1u0 in etc - will show" > ${TST_DIR}/etc/motd.d/e1r1u0.motd
  25. echo "motd: e1r1u1 in usr/lib - not show" > ${TST_DIR}/usr/lib/motd.d/e1r1u1.motd
  26. echo "motd: e1r1u1 in run - not show" > ${TST_DIR}/run/motd.d/e1r1u1.motd
  27. echo "motd: e1r1u1 in etc - will show" > ${TST_DIR}/etc/motd.d/e1r1u1.motd
  28. ./tst-pam_motd tst-pam_motd2 > tst-pam_motd2.out
  29. RET=$?
  30. motd_to_show_output=$(cat tst-pam_motd2.out | grep "motd: /etc/motd")
  31. if [ -z "${motd_to_show_output}" ];
  32. then
  33. tst_cleanup
  34. exit 1
  35. fi
  36. motd_dir_not_show_output=$(cat tst-pam_motd2.out | grep "not show")
  37. if [ -n "${motd_dir_not_show_output}" ];
  38. then
  39. tst_cleanup
  40. exit 1
  41. fi
  42. tst_cleanup
  43. exit $RET