Vagrantfile 13 KB

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