logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

chmod.sh (1767B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. target="$(dirname "$0")/../cmd/chmod"
  5. plans=11
  6. . "$(dirname "$0")/tap.sh"
  7. tmpfile="${TMPDIR-/tmp}/test_chmod_$(date +%s)"
  8. touch "$tmpfile" || exit 1
  9. t '0' "-v 0 $tmpfile" "chmod: Permissions changed from 00644/-rw-r--r-- to 00000/---------- for '${tmpfile}'
  10. "
  11. t '00' "-v 00 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'
  12. "
  13. t '000' "-v 000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'
  14. "
  15. t '0000' "-v 0000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'
  16. "
  17. t '0444' "-v 0444 $tmpfile" "chmod: Permissions changed from 00000/---------- to 00444/-r--r--r-- for '${tmpfile}'
  18. "
  19. t '0777' "-v 0777 $tmpfile" "chmod: Permissions changed from 00444/-r--r--r-- to 00777/-rwxrwxrwx for '${tmpfile}'
  20. "
  21. t --exit=1 'invalid 0888' "-v 0888 $tmpfile" "chmod: Failed parsing mode '0888': contains digit outside of [0-7]
  22. "
  23. t 'mode:-w,+x' "-v -w,+x $tmpfile" "chmod: Portability Warning: Pass -- before a mode with a leading dash(-) to separate it from options
  24. chmod: Permissions changed from 00777/-rwxrwxrwx to 00577/-r-xrwxrwx for '${tmpfile}'
  25. "
  26. t 'mode:-r' "-v -r $tmpfile" "chmod: Portability Warning: Pass -- before a mode with a leading dash(-) to separate it from options
  27. chmod: Permissions changed from 00577/-r-xrwxrwx to 00133/---x-wx-wx for '${tmpfile}'
  28. "
  29. t '__mode:-x,+w' "-v -- -x,+w $tmpfile" "chmod: Permissions changed from 00133/---x-wx-wx to 00222/--w--w--w- for '${tmpfile}'
  30. "
  31. t '__mode:-w' "-v -- -w $tmpfile" "chmod: Permissions changed from 00222/--w--w--w- to 00022/-----w--w- for '${tmpfile}'
  32. "
  33. rm -f "$tmpfile" || exit 1