Vagrantfile 13 KB

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