tst-pam_motd3.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. TST_DIR="tst-pam_motd3.d"
  3. function tst_cleanup() {
  4. rm -rf "${TST_DIR}"
  5. rm -f tst-pam_motd3.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. # Verify motd is still displayed when not overridden
  12. echo "motd: test-show in run - show" > ${TST_DIR}/run/motd.d/test-show.motd
  13. # Test overridden by a symlink to a file that isn't /dev/null; symlink target should show
  14. echo "motd: hidden-by-symlink in usr/lib - not show" > ${TST_DIR}/usr/lib/motd.d/hidden-by-symlink.motd
  15. echo "motd: test-from-symlink - show" > ${TST_DIR}/test-from-symlink.motd
  16. ln -sr ${TST_DIR}/test-from-symlink.motd ${TST_DIR}/run/motd.d/hidden-by-symlink.motd
  17. # Test hidden by a null symlink
  18. echo "motd: hidden-by-null-symlink in run - not show" > ${TST_DIR}/run/motd.d/hidden-by-null-symlink.motd
  19. ln -s /dev/null ${TST_DIR}/etc/motd.d/hidden-by-null-symlink.motd
  20. ./tst-pam_motd tst-pam_motd3 > tst-pam_motd3.out
  21. RET=$?
  22. motd_dir_not_show_output=$(cat tst-pam_motd3.out | grep "not show")
  23. if [ -n "${motd_dir_not_show_output}" ];
  24. then
  25. tst_cleanup
  26. exit 1
  27. fi
  28. motd_test_show_output=$(cat tst-pam_motd3.out | grep "test-show.*- show")
  29. if [ -z "${motd_test_show_output}" ];
  30. then
  31. tst_cleanup
  32. exit 1
  33. fi
  34. motd_general_symlink_show_output=$(cat tst-pam_motd3.out | grep "test-from-symlink.*- show")
  35. if [ -z "${motd_general_symlink_show_output}" ];
  36. then
  37. tst_cleanup
  38. exit 1
  39. fi
  40. tst_cleanup
  41. exit $RET