Vagrantfile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. require 'date'
  2. Vagrant.configure(2) do |config|
  3. config.vm.provider :virtualbox do |v|
  4. v.name = 'exa'
  5. v.memory = 1024
  6. v.cpus = 1
  7. end
  8. # We use Ubuntu instead of Debian because the image comes with two-way
  9. # shared folder support by default.
  10. config.vm.box = 'ubuntu/xenial64'
  11. config.vm.hostname = 'exa'
  12. # Install the dependencies needed for exa to build, as quietly as
  13. # apt can do.
  14. config.vm.provision :shell, privileged: true, inline:
  15. %[apt-get install -qq -o=Dpkg::Use-Pty=0 -y git cmake libgit2-dev curl attr pkg-config]
  16. # Guarantee that the timezone is UTC -- some of the tests
  17. # depend on this (for now).
  18. config.vm.provision :shell, privileged: true, inline:
  19. %[timedatectl set-timezone UTC]
  20. # Install Rust.
  21. # This is done as vagrant, not root, because it’s vagrant
  22. # who actually uses it. Sent to /dev/null because the progress
  23. # bar produces a ton of output.
  24. config.vm.provision :shell, privileged: false, inline:
  25. %[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
  26. # Use a different ‘target’ directory on the VM than on the host.
  27. # By default it just uses the one in /vagrant/target, which can
  28. # cause problems if it has different permissions than the other
  29. # directories, or contains object files compiled for the host.
  30. config.vm.provision :shell, privileged: false, inline: <<-EOF
  31. function put_line() {
  32. grep -q -F "$2" $1 || echo "$2" >> $1
  33. }
  34. put_line ~/.bashrc 'export CARGO_TARGET_DIR=/home/ubuntu/target'
  35. put_line ~/.bashrc 'alias dexa=~/target/debug/exa'
  36. put_line ~/.bashrc 'alias rexa=~/target/release/exa'
  37. EOF
  38. # We create two users that own the test files.
  39. # The first one just owns the ordinary ones, because we don’t want to
  40. # depend on “vagrant” or “ubuntu” existing.
  41. user = "cassowary"
  42. config.vm.provision :shell, privileged: true, inline:
  43. %[id -u #{user} &>/dev/null || useradd #{user}]
  44. # The second one has a long name, to test that the file owner column
  45. # widens correctly. The benefit of Vagrant is that we don’t need to
  46. # set this up on the *actual* system!
  47. longuser = "antidisestablishmentarienism"
  48. config.vm.provision :shell, privileged: true, inline:
  49. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  50. # Because the timestamps are formatted differently depending on whether
  51. # they’re in the current year or not (see `details.rs`), we have to make
  52. # sure that the files are created in the current year, so they get shown
  53. # in the format we expect.
  54. current_year = Date.today.year
  55. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  56. # We also need an UID and a GID that are guaranteed to not exist, to
  57. # test what happen when they don’t.
  58. invalid_uid = 666
  59. invalid_gid = 616
  60. # Delete old testcases if they exist already, then create a
  61. # directory to house new ones.
  62. test_dir = "/testcases"
  63. config.vm.provision :shell, privileged: true, inline: <<-EOF
  64. set -xe
  65. rm -rfv #{test_dir}
  66. mkdir #{test_dir}
  67. chmod 777 #{test_dir}
  68. EOF
  69. # Awkward file size testcases.
  70. # This needs sudo to set the files’ users at the very end.
  71. config.vm.provision :shell, privileged: false, inline: <<-EOF
  72. set -xe
  73. mkdir "#{test_dir}/files"
  74. for i in {1..13}; do
  75. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  76. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  77. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  78. done
  79. touch -t #{some_date} "#{test_dir}/files/"*
  80. chmod 644 "#{test_dir}/files/"*
  81. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  82. EOF
  83. # File name extension testcases.
  84. # These are tested in grid view, so we don’t need to bother setting
  85. # owners or timestamps or anything.
  86. config.vm.provision :shell, privileged: false, inline: <<-EOF
  87. set -xe
  88. mkdir "#{test_dir}/file-names-exts"
  89. touch "#{test_dir}/file-names-exts/Makefile"
  90. touch "#{test_dir}/file-names-exts/image.png"
  91. touch "#{test_dir}/file-names-exts/image.svg"
  92. touch "#{test_dir}/file-names-exts/video.avi"
  93. touch "#{test_dir}/file-names-exts/video.wmv"
  94. touch "#{test_dir}/file-names-exts/music.mp3"
  95. touch "#{test_dir}/file-names-exts/music.ogg"
  96. touch "#{test_dir}/file-names-exts/lossless.flac"
  97. touch "#{test_dir}/file-names-exts/lossless.wav"
  98. touch "#{test_dir}/file-names-exts/crypto.asc"
  99. touch "#{test_dir}/file-names-exts/crypto.signature"
  100. touch "#{test_dir}/file-names-exts/document.pdf"
  101. touch "#{test_dir}/file-names-exts/document.xlsx"
  102. touch "#{test_dir}/file-names-exts/compressed.zip"
  103. touch "#{test_dir}/file-names-exts/compressed.tar.gz"
  104. touch "#{test_dir}/file-names-exts/compressed.tgz"
  105. touch "#{test_dir}/file-names-exts/backup~"
  106. touch "#{test_dir}/file-names-exts/#SAVEFILE#"
  107. touch "#{test_dir}/file-names-exts/file.tmp"
  108. touch "#{test_dir}/file-names-exts/compiled.class"
  109. touch "#{test_dir}/file-names-exts/compiled.o"
  110. touch "#{test_dir}/file-names-exts/compiled.js"
  111. touch "#{test_dir}/file-names-exts/compiled.coffee"
  112. EOF
  113. # File name testcases.
  114. # bash really doesn’t want you to create a file with escaped characters
  115. # in its name, so we have to resort to the echo builtin and touch!
  116. #
  117. # The double backslashes are not strictly necessary; without them, Ruby
  118. # will interpolate them instead of bash, but because Vagrant prints out
  119. # each command it runs, your *own* terminal will go “ding” from the alarm!
  120. config.vm.provision :shell, privileged: false, inline: <<-EOF
  121. set -xe
  122. mkdir "#{test_dir}/file-names"
  123. echo -ne "#{test_dir}/file-names/ascii: hello" | xargs -0 touch
  124. echo -ne "#{test_dir}/file-names/emoji: [🆒]" | xargs -0 touch
  125. echo -ne "#{test_dir}/file-names/utf-8: pâté" | xargs -0 touch
  126. echo -ne "#{test_dir}/file-names/bell: [\\a]" | xargs -0 touch
  127. echo -ne "#{test_dir}/file-names/backspace: [\\b]" | xargs -0 touch
  128. echo -ne "#{test_dir}/file-names/form-feed: [\\f]" | xargs -0 touch
  129. echo -ne "#{test_dir}/file-names/new-line: [\\n]" | xargs -0 touch
  130. echo -ne "#{test_dir}/file-names/return: [\\r]" | xargs -0 touch
  131. echo -ne "#{test_dir}/file-names/tab: [\\t]" | xargs -0 touch
  132. echo -ne "#{test_dir}/file-names/vertical-tab: [\\v]" | xargs -0 touch
  133. echo -ne "#{test_dir}/file-names/escape: [\\033]" | xargs -0 touch
  134. echo -ne "#{test_dir}/file-names/ansi: [\\033[34mblue\\033[0m]" | xargs -0 touch
  135. echo -ne "#{test_dir}/file-names/invalid-utf8-1: [\\xFF]" | xargs -0 touch
  136. echo -ne "#{test_dir}/file-names/invalid-utf8-2: [\\xc3\\x28]" | xargs -0 touch
  137. echo -ne "#{test_dir}/file-names/invalid-utf8-3: [\\xe2\\x82\\x28]" | xargs -0 touch
  138. echo -ne "#{test_dir}/file-names/invalid-utf8-4: [\\xf0\\x28\\x8c\\x28]" | xargs -0 touch
  139. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]" | xargs -0 mkdir
  140. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/subfile" | xargs -0 touch
  141. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/another: [\\n]" | xargs -0 touch
  142. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 touch
  143. mkdir "#{test_dir}/file-names/links"
  144. ln -s "#{test_dir}/file-names/new-line-dir"*/* "#{test_dir}/file-names/links"
  145. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 rm
  146. EOF
  147. # Special file testcases.
  148. config.vm.provision :shell, privileged: false, inline: <<-EOF
  149. set -xe
  150. mkdir "#{test_dir}/specials"
  151. sudo mknod "#{test_dir}/specials/block-device" b 3 60
  152. sudo mknod "#{test_dir}/specials/char-device" c 14 40
  153. sudo mknod "#{test_dir}/specials/named-pipe" p
  154. sudo touch -t #{some_date} "#{test_dir}/specials/"*
  155. EOF
  156. # Awkward symlink testcases.
  157. config.vm.provision :shell, privileged: false, inline: <<-EOF
  158. set -xe
  159. mkdir "#{test_dir}/links"
  160. ln -s / "#{test_dir}/links/root"
  161. ln -s /usr "#{test_dir}/links/usr"
  162. ln -s nowhere "#{test_dir}/links/broken"
  163. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  164. touch "#{test_dir}/links/some_file"
  165. ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
  166. (cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
  167. (cd "#{test_dir}/links"; ln -s "." "current_dir")
  168. (cd "#{test_dir}/links"; ln -s ".." "parent_dir")
  169. (cd "#{test_dir}/links"; ln -s "itself" "itself")
  170. EOF
  171. # Awkward passwd testcases.
  172. # sudo is needed for these because we technically aren’t a member
  173. # of the groups (because they don’t exist), and chown and chgrp
  174. # are smart enough to disallow it!
  175. config.vm.provision :shell, privileged: false, inline: <<-EOF
  176. set -xe
  177. mkdir "#{test_dir}/passwd"
  178. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  179. chmod 644 "#{test_dir}/passwd/unknown-uid"
  180. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  181. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  182. chmod 644 "#{test_dir}/passwd/unknown-gid"
  183. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  184. EOF
  185. # Awkward permission testcases.
  186. config.vm.provision :shell, privileged: false, inline: <<-EOF
  187. set -xe
  188. mkdir "#{test_dir}/permissions"
  189. touch "#{test_dir}/permissions/all-permissions"
  190. chmod 777 "#{test_dir}/permissions/all-permissions"
  191. touch "#{test_dir}/permissions/no-permissions"
  192. chmod 000 "#{test_dir}/permissions/no-permissions"
  193. mkdir "#{test_dir}/permissions/forbidden-directory"
  194. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  195. for perms in 001 002 004 010 020 040 100 200 400; do
  196. touch "#{test_dir}/permissions/$perms"
  197. chmod $perms "#{test_dir}/permissions/$perms"
  198. done
  199. touch -t #{some_date} "#{test_dir}/permissions/"*
  200. sudo chown #{user}:#{user} "#{test_dir}/permissions/"*
  201. EOF
  202. # Awkward extended attribute testcases.
  203. config.vm.provision :shell, privileged: false, inline: <<-EOF
  204. set -xe
  205. mkdir "#{test_dir}/attributes"
  206. touch "#{test_dir}/attributes/none"
  207. touch "#{test_dir}/attributes/one"
  208. setfattr -n user.greeting -v hello "#{test_dir}/attributes/one"
  209. touch "#{test_dir}/attributes/two"
  210. setfattr -n user.greeting -v hello "#{test_dir}/attributes/two"
  211. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes/two"
  212. #touch "#{test_dir}/attributes/forbidden"
  213. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/forbidden"
  214. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/forbidden"
  215. mkdir "#{test_dir}/attributes/dirs"
  216. mkdir "#{test_dir}/attributes/dirs/empty-with-attribute"
  217. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/empty-with-attribute"
  218. mkdir "#{test_dir}/attributes/dirs/full-with-attribute"
  219. touch "#{test_dir}/attributes/dirs/full-with-attribute/file"
  220. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-with-attribute"
  221. mkdir "#{test_dir}/attributes/dirs/full-but-forbidden"
  222. touch "#{test_dir}/attributes/dirs/full-but-forbidden/file"
  223. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-but-forbidden"
  224. #chmod 000 "#{test_dir}/attributes/dirs/full-but-forbidden"
  225. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/dirs/full-but-forbidden"
  226. touch -t #{some_date} "#{test_dir}/attributes"
  227. touch -t #{some_date} "#{test_dir}/attributes/"*
  228. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*
  229. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*/*
  230. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  231. EOF
  232. end