Vagrantfile 13 KB

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