generate-testcases.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # This is a script to generate "awkward" files and directories as test cases,
  3. # to check that exa can actually handle them: symlinks that point at
  4. # themselves, directories that you aren't allowed to view, files with strange
  5. # extended attributes, that sort of thing.
  6. ## -- configuration --
  7. # Directory that the files should be generated in.
  8. DIR=testcases
  9. if [[ -e "$DIR" ]]
  10. then
  11. echo "'$DIR' already exists - aborting" >&2
  12. exit 2
  13. fi
  14. # You! Yes, you, the name of the user running this script.
  15. YOU=`whoami`
  16. # Someone with *higher* privileges than yourself, such as root.
  17. ROOT=root
  18. # A UID that doesn't map to any user on the system.
  19. INVALID_UID=666
  20. # A GID that doesn't map to any group on the system.
  21. INVALID_GID=616
  22. # List commands as they are run
  23. # set -x
  24. # Abort on any error!
  25. abort() { echo 'Hit an error - aborting' >&2; exit 1; }
  26. trap 'abort' ERR
  27. # Get confirmation from the user before running.
  28. # echo "This script will generate files into the $DIR directory."
  29. # echo "It requires sudo for the '$ROOT' user."
  30. # echo "You probably want to edit this file before running it."
  31. # read -r -p "Continue? [y/N] " response
  32. # if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]
  33. # then
  34. # exit 2
  35. # fi
  36. mkdir "$DIR"
  37. ## -- links --
  38. mkdir "$DIR/links"
  39. ln -s / "$DIR/links/root"
  40. ln -s /usr "$DIR/links/usr"
  41. ln -s nowhere "$DIR/links/broken"
  42. ## -- users and groups --
  43. mkdir "$DIR/passwd"
  44. # sudo is needed for these because we technically aren't a member of the
  45. # groups (because they don't exist), and chown and chgrp are smart enough to
  46. # disallow it!
  47. touch "$DIR/passwd/unknown-uid"
  48. sudo -u "$ROOT" chown $INVALID_UID "$DIR/passwd/unknown-uid"
  49. touch "$DIR/passwd/unknown-gid"
  50. sudo -u "$ROOT" chgrp $INVALID_GID "$DIR/passwd/unknown-gid"
  51. ## -- permissions --
  52. mkdir "$DIR/permissions"
  53. touch "$DIR/permissions/all-permissions"
  54. chmod 777 "$DIR/permissions/all-permissions"
  55. touch "$DIR/permissions/no-permissions"
  56. chmod 000 "$DIR/permissions/no-permissions"
  57. mkdir "$DIR/permissions/forbidden-directory"
  58. chmod 000 "$DIR/permissions/forbidden-directory"
  59. ## -- extended attributes --
  60. mkdir "$DIR/attributes"
  61. touch "$DIR/attributes/none"
  62. touch "$DIR/attributes/one"
  63. xattr -w greeting hello "$DIR/attributes/one"
  64. touch "$DIR/attributes/two"
  65. xattr -w greeting hello "$DIR/attributes/two"
  66. xattr -w another_greeting hi "$DIR/attributes/two"
  67. touch "$DIR/attributes/forbidden"
  68. xattr -w greeting hello "$DIR/attributes/forbidden"
  69. chmod +a "$YOU deny readextattr" "$DIR/attributes/forbidden"
  70. mkdir "$DIR/attributes/dirs"
  71. mkdir "$DIR/attributes/dirs/empty-with-attribute"
  72. xattr -w greeting hello "$DIR/attributes/dirs/empty-with-attribute"
  73. mkdir "$DIR/attributes/dirs/full-with-attribute"
  74. touch "$DIR/attributes/dirs/full-with-attribute/file"
  75. xattr -w greeting hello "$DIR/attributes/dirs/full-with-attribute"
  76. mkdir "$DIR/attributes/dirs/full-but-forbidden"
  77. touch "$DIR/attributes/dirs/full-but-forbidden/file"
  78. xattr -w greeting hello "$DIR/attributes/dirs/full-but-forbidden"
  79. chmod 000 "$DIR/attributes/dirs/full-but-forbidden"
  80. chmod +a "$YOU deny readextattr" "$DIR/attributes/dirs/full-but-forbidden"