Vagrantfile 15 KB

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