Vagrantfile 13 KB

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