Vagrantfile 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. require 'date'
  2. Vagrant.configure(2) do |config|
  3. # We use Ubuntu instead of Debian because the image comes with two-way
  4. # shared folder support by default.
  5. UBUNTU = 'ubuntu/xenial64'
  6. # The main VM is the one used for development and testing.
  7. config.vm.define(:exa, primary: true) do |config|
  8. config.vm.provider :virtualbox do |v|
  9. v.name = 'exa'
  10. v.memory = 1024
  11. v.cpus = 1
  12. end
  13. config.vm.box = UBUNTU
  14. config.vm.hostname = 'exa'
  15. # Make sure we know the VM image’s default user name. The ā€˜cassowary’ user
  16. # (specified later) is used for most of the test *output*, but we still
  17. # need to know where the ā€˜target’ and ā€˜.cargo’ directories go.
  18. developer = 'ubuntu'
  19. # Install the dependencies needed for exa to build, as quietly as
  20. # apt can do.
  21. config.vm.provision :shell, privileged: true, inline: <<-EOF
  22. set -xe
  23. apt-get update
  24. apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  25. git cmake curl attr libgit2-dev zip \
  26. fish zsh bash bash-completion
  27. EOF
  28. # Guarantee that the timezone is UTC -- some of the tests
  29. # depend on this (for now).
  30. config.vm.provision :shell, privileged: true, inline:
  31. %[timedatectl set-timezone UTC]
  32. # Install Rust.
  33. # This is done as vagrant, not root, because it’s vagrant
  34. # who actually uses it. Sent to /dev/null because the progress
  35. # bar produces a ton of output.
  36. config.vm.provision :shell, privileged: false, inline:
  37. %[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
  38. # Use a different ā€˜target’ directory on the VM than on the host.
  39. # By default it just uses the one in /vagrant/target, which can
  40. # cause problems if it has different permissions than the other
  41. # directories, or contains object files compiled for the host.
  42. config.vm.provision :shell, privileged: true, inline: <<-EOF
  43. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
  44. echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
  45. EOF
  46. # Create a variety of misc scripts.
  47. config.vm.provision :shell, privileged: true, inline: <<-EOF
  48. set -xe
  49. echo -e "#!/bin/sh\n/home/#{developer}/target/debug/exa \"\\$*\"" > /usr/bin/exa
  50. echo -e "#!/bin/sh\n/home/#{developer}/target/release/exa \"\\$*\"" > /usr/bin/rexa
  51. echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml" > /usr/bin/build-exa
  52. ln -sf /usr/bin/build-exa /usr/bin/b
  53. echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml --lib -- --quiet" > /usr/bin/test-exa
  54. ln -sf /usr/bin/test-exa /usr/bin/t
  55. echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
  56. ln -sf /usr/bin/run-xtests /usr/bin/x
  57. echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
  58. ln -sf /usr/bin/compile-exa /usr/bin/c
  59. echo "#!/bin/bash" > /usr/bin/package-exa
  60. echo "set -e" >> /usr/bin/package-exa
  61. echo 'echo -e "\nCompiling release version of exa..."' >> /usr/bin/package-exa
  62. echo "cargo build --release --manifest-path /vagrant/Cargo.toml" >> /usr/bin/package-exa
  63. echo "cargo test --release --manifest-path /vagrant/Cargo.toml --lib" >> /usr/bin/package-exa
  64. echo "/vagrant/xtests/run.sh --release" >> /usr/bin/package-exa
  65. echo "cp /home/ubuntu/target/release/exa /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  66. echo 'echo -e "\nStripping binary..."' >> /usr/bin/package-exa
  67. echo "strip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  68. echo 'echo -e "\nZipping binary..."' >> /usr/bin/package-exa
  69. echo "rm -f /vagrant/exa-linux-x86_64.zip" >> /usr/bin/package-exa
  70. echo "zip -j /vagrant/exa-linux-x86_64.zip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  71. echo 'echo -e "\nLibraries linked:"' >> /usr/bin/package-exa
  72. echo "ldd /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  73. echo 'echo -e "\nAll done!"' >> /usr/bin/package-exa
  74. echo '/vagrant/exa-linux-x86_64 /vagrant/exa-linux-x86_64* -lB' >> /usr/bin/package-exa
  75. chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa}
  76. EOF
  77. # Download my patched version of git2-rs.
  78. # This is basically a hack and we should get rid of it as soon as
  79. # a better solution comes along.
  80. # See https://github.com/ogham/exa/issues/194
  81. config.vm.provision :shell, privileged: false, inline: <<-EOF
  82. set -xe
  83. if [ -d /home/ubuntu/git2-rs ]; then
  84. cd /home/ubuntu/git2-rs
  85. git pull https://github.com/ogham/git2-rs.git || echo "Failed to update git2-rs fork"
  86. else
  87. git clone https://github.com/ogham/git2-rs.git /home/ubuntu/git2-rs
  88. fi
  89. mkdir -p /home/ubuntu/.cargo
  90. echo 'paths = ["/home/ubuntu/git2-rs/libgit2-sys"]' > /home/ubuntu/.cargo/config
  91. EOF
  92. # This fix is applied by changing the VM rather than changing the
  93. # Cargo.toml file so it works for everyone because it’s such a niche
  94. # build issue, it’s not worth specifying a non-crates.io dependency
  95. # and losing the ability to `cargo publish` the exa crate there!
  96. # It also isolates the hackiness to the one place I can test it
  97. # actually works.
  98. # Write some welcoming text.
  99. config.vm.provision :shell, privileged: true, inline: <<-EOF
  100. rm -f /etc/update-motd.d/*
  101. echo -e "" > /etc/motd
  102. echo -e "\033[1;33mThe exa development environment!\033[0m" >> /etc/motd
  103. echo -e "exa's source is available at \033[33m/vagrant\033[0m." >> /etc/motd
  104. echo -e "Binaries get built into \033[33m/home/ubuntu/target\033[0m." >> /etc/motd
  105. echo -e "" >> /etc/motd
  106. echo -e "\033[4mCommands\033[0m" >> /etc/motd
  107. echo -e "\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m" >> /etc/motd
  108. echo -e "\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m" >> /etc/motd
  109. echo -e "\033[32;1mx\033[0m or \033[32;1mrun-xtests\033[0m to run \033[1m/vagrant/xtests/run.sh\033[0m" >> /etc/motd
  110. echo -e "\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three" >> /etc/motd
  111. echo -e "\033[32;1mdebug\033[0m to toggle printing logs" >> /etc/motd
  112. echo -e "\033[32;1mstrict\033[0m to toggle strict mode" >> /etc/motd
  113. echo -e "\033[32;1mcolors\033[0m to toggle custom colours\n" >> /etc/motd
  114. # help banner
  115. echo 'echo -e "\\033[4mVersions\\033[0m"' > /home/ubuntu/.bash_profile
  116. echo "rustc --version" >> /home/ubuntu/.bash_profile
  117. echo "cargo --version" >> /home/ubuntu/.bash_profile
  118. echo "echo" >> /home/ubuntu/.bash_profile
  119. # cool prompt
  120. echo 'function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }' >> /home/ubuntu/.bash_profile
  121. echo 'function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }' >> /home/ubuntu/.bash_profile
  122. echo 'function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }' >> /home/ubuntu/.bash_profile
  123. echo 'function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }' >> /home/ubuntu/.bash_profile
  124. echo 'function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }' >> /home/ubuntu/.bash_profile
  125. echo 'export PS1="\\[\\e[1;36m\\]\\h \\[\\e[32m\\]\\w \\[\\e[31m\\]\\`nonzero_return\\`\\[\\e[35m\\]\\`debug_mode\\`\\[\\e[32m\\]\\`lsc_mode\\`\\[\\e[1;32m\\]\\`exac_mode\\`\\[\\e[33m\\]\\`strict_mode\\`\\[\\e[36m\\]\\\\$\\[\\e[0m\\] "' >> /home/ubuntu/.bash_profile
  126. # environment setting
  127. echo 'function debug () {' >> /home/ubuntu/.bash_profile
  128. echo ' case "$1" in "on") export EXA_DEBUG=1 ;;' >> /home/ubuntu/.bash_profile
  129. echo ' "off") export EXA_DEBUG= ;;' >> /home/ubuntu/.bash_profile
  130. echo ' "") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;' >> /home/ubuntu/.bash_profile
  131. echo ' *) echo "Usage: debug on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  132. echo 'function strict () {' >> /home/ubuntu/.bash_profile
  133. echo ' case "$1" in "on") export EXA_STRICT=1 ;;' >> /home/ubuntu/.bash_profile
  134. echo ' "off") export EXA_STRICT= ;;' >> /home/ubuntu/.bash_profile
  135. echo ' "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;' >> /home/ubuntu/.bash_profile
  136. echo ' *) echo "Usage: strict on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  137. echo 'function colors () {' >> /home/ubuntu/.bash_profile
  138. echo ' case "$1" in ' >> /home/ubuntu/.bash_profile
  139. echo ' "ls")' >> /home/ubuntu/.bash_profile
  140. echo ' export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"' >> /home/ubuntu/.bash_profile
  141. echo ' export EXA_COLORS="" ;;' >> /home/ubuntu/.bash_profile
  142. echo ' "hacker")' >> /home/ubuntu/.bash_profile
  143. echo ' export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"' >> /home/ubuntu/.bash_profile
  144. echo ' export EXA_COLORS="ur=32:uw=32:ux=32:ue=32:gr=32:gw=32:gx=32:tr=32:tw=32:tx=32:su=32:sf=32:xa=32:sn=32:sb=32:df=32:ds=32:uu=32:un=32:gu=32:gn=32:lc=32:lm=32:ga=32:gm=32:gd=32:gv=32:gt=32:xx=32:da=32:in=32:bl=32:hd=32:lp=32:cc=32:" ;;' >> /home/ubuntu/.bash_profile
  145. echo ' "off")' >> /home/ubuntu/.bash_profile
  146. echo ' export LS_COLORS=' >> /home/ubuntu/.bash_profile
  147. echo ' export EXA_COLORS= ;;' >> /home/ubuntu/.bash_profile
  148. echo ' "")' >> /home/ubuntu/.bash_profile
  149. echo ' [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"' >> /home/ubuntu/.bash_profile
  150. echo ' [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;' >> /home/ubuntu/.bash_profile
  151. echo ' *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  152. # Disable last login date in sshd
  153. sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
  154. systemctl restart sshd
  155. EOF
  156. # Link the completion files so they’re ā€œinstalledā€.
  157. config.vm.provision :shell, privileged: true, inline: <<-EOF
  158. set -xe
  159. test -h /etc/bash_completion.d/exa \
  160. || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
  161. test -h /usr/share/zsh/vendor-completions/_exa \
  162. || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
  163. test -h /usr/share/fish/completions/exa.fish \
  164. || ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish
  165. EOF
  166. # We create two users that own the test files.
  167. # The first one just owns the ordinary ones, because we don’t want the
  168. # test outputs to depend on ā€œvagrantā€ or ā€œubuntuā€ existing.
  169. user = "cassowary"
  170. config.vm.provision :shell, privileged: true, inline:
  171. %[id -u #{user} &>/dev/null || useradd #{user}]
  172. # The second one has a long name, to test that the file owner column
  173. # widens correctly. The benefit of Vagrant is that we don’t need to
  174. # set this up on the *actual* system!
  175. longuser = "antidisestablishmentarienism"
  176. config.vm.provision :shell, privileged: true, inline:
  177. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  178. # Because the timestamps are formatted differently depending on whether
  179. # they’re in the current year or not (see `details.rs`), we have to make
  180. # sure that the files are created in the current year, so they get shown
  181. # in the format we expect.
  182. current_year = Date.today.year
  183. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  184. # We also need an UID and a GID that are guaranteed to not exist, to
  185. # test what happen when they don’t.
  186. invalid_uid = 666
  187. invalid_gid = 616
  188. # Delete old testcases if they exist already, then create a
  189. # directory to house new ones.
  190. test_dir = "/testcases"
  191. config.vm.provision :shell, privileged: true, inline: <<-EOF
  192. set -xe
  193. rm -rfv #{test_dir}
  194. mkdir #{test_dir}
  195. chmod 777 #{test_dir}
  196. EOF
  197. # Awkward file size testcases.
  198. # This needs sudo to set the files’ users at the very end.
  199. config.vm.provision :shell, privileged: false, inline: <<-EOF
  200. set -xe
  201. mkdir "#{test_dir}/files"
  202. for i in {1..13}; do
  203. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  204. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  205. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  206. done
  207. touch -t #{some_date} "#{test_dir}/files/"*
  208. chmod 644 "#{test_dir}/files/"*
  209. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  210. EOF
  211. # File name extension testcases.
  212. # These aren’t tested in details view, but we set timestamps on them to
  213. # test that various sort options work.
  214. config.vm.provision :shell, privileged: false, inline: <<-EOF
  215. set -xe
  216. mkdir "#{test_dir}/file-names-exts"
  217. touch "#{test_dir}/file-names-exts/Makefile"
  218. touch "#{test_dir}/file-names-exts/IMAGE.PNG"
  219. touch "#{test_dir}/file-names-exts/image.svg"
  220. touch "#{test_dir}/file-names-exts/VIDEO.AVI"
  221. touch "#{test_dir}/file-names-exts/video.wmv"
  222. touch "#{test_dir}/file-names-exts/music.mp3"
  223. touch "#{test_dir}/file-names-exts/MUSIC.OGG"
  224. touch "#{test_dir}/file-names-exts/lossless.flac"
  225. touch "#{test_dir}/file-names-exts/lossless.wav"
  226. touch "#{test_dir}/file-names-exts/crypto.asc"
  227. touch "#{test_dir}/file-names-exts/crypto.signature"
  228. touch "#{test_dir}/file-names-exts/document.pdf"
  229. touch "#{test_dir}/file-names-exts/DOCUMENT.XLSX"
  230. touch "#{test_dir}/file-names-exts/COMPRESSED.ZIP"
  231. touch "#{test_dir}/file-names-exts/compressed.tar.gz"
  232. touch "#{test_dir}/file-names-exts/compressed.tgz"
  233. touch "#{test_dir}/file-names-exts/compressed.tar.xz"
  234. touch "#{test_dir}/file-names-exts/compressed.txz"
  235. touch "#{test_dir}/file-names-exts/compressed.deb"
  236. touch "#{test_dir}/file-names-exts/backup~"
  237. touch "#{test_dir}/file-names-exts/#SAVEFILE#"
  238. touch "#{test_dir}/file-names-exts/file.tmp"
  239. touch "#{test_dir}/file-names-exts/compiled.class"
  240. touch "#{test_dir}/file-names-exts/compiled.o"
  241. touch "#{test_dir}/file-names-exts/compiled.js"
  242. touch "#{test_dir}/file-names-exts/compiled.coffee"
  243. EOF
  244. # File name testcases.
  245. # bash really doesn’t want you to create a file with escaped characters
  246. # in its name, so we have to resort to the echo builtin and touch!
  247. #
  248. # The double backslashes are not strictly necessary; without them, Ruby
  249. # will interpolate them instead of bash, but because Vagrant prints out
  250. # each command it runs, your *own* terminal will go ā€œdingā€ from the alarm!
  251. config.vm.provision :shell, privileged: false, inline: <<-EOF
  252. set -xe
  253. mkdir "#{test_dir}/file-names"
  254. echo -ne "#{test_dir}/file-names/ascii: hello" | xargs -0 touch
  255. echo -ne "#{test_dir}/file-names/emoji: [šŸ†’]" | xargs -0 touch
  256. echo -ne "#{test_dir}/file-names/utf-8: pâté" | xargs -0 touch
  257. echo -ne "#{test_dir}/file-names/bell: [\\a]" | xargs -0 touch
  258. echo -ne "#{test_dir}/file-names/backspace: [\\b]" | xargs -0 touch
  259. echo -ne "#{test_dir}/file-names/form-feed: [\\f]" | xargs -0 touch
  260. echo -ne "#{test_dir}/file-names/new-line: [\\n]" | xargs -0 touch
  261. echo -ne "#{test_dir}/file-names/return: [\\r]" | xargs -0 touch
  262. echo -ne "#{test_dir}/file-names/tab: [\\t]" | xargs -0 touch
  263. echo -ne "#{test_dir}/file-names/vertical-tab: [\\v]" | xargs -0 touch
  264. echo -ne "#{test_dir}/file-names/escape: [\\033]" | xargs -0 touch
  265. echo -ne "#{test_dir}/file-names/ansi: [\\033[34mblue\\033[0m]" | xargs -0 touch
  266. echo -ne "#{test_dir}/file-names/invalid-utf8-1: [\\xFF]" | xargs -0 touch
  267. echo -ne "#{test_dir}/file-names/invalid-utf8-2: [\\xc3\\x28]" | xargs -0 touch
  268. echo -ne "#{test_dir}/file-names/invalid-utf8-3: [\\xe2\\x82\\x28]" | xargs -0 touch
  269. echo -ne "#{test_dir}/file-names/invalid-utf8-4: [\\xf0\\x28\\x8c\\x28]" | xargs -0 touch
  270. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]" | xargs -0 mkdir
  271. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/subfile" | xargs -0 touch
  272. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/another: [\\n]" | xargs -0 touch
  273. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 touch
  274. mkdir "#{test_dir}/file-names/links"
  275. ln -s "#{test_dir}/file-names/new-line-dir"*/* "#{test_dir}/file-names/links"
  276. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 rm
  277. EOF
  278. # Special file testcases.
  279. config.vm.provision :shell, privileged: false, inline: <<-EOF
  280. set -xe
  281. mkdir "#{test_dir}/specials"
  282. sudo mknod "#{test_dir}/specials/block-device" b 3 60
  283. sudo mknod "#{test_dir}/specials/char-device" c 14 40
  284. sudo mknod "#{test_dir}/specials/named-pipe" p
  285. sudo touch -t #{some_date} "#{test_dir}/specials/"*
  286. EOF
  287. # Awkward symlink testcases.
  288. config.vm.provision :shell, privileged: false, inline: <<-EOF
  289. set -xe
  290. mkdir "#{test_dir}/links"
  291. ln -s / "#{test_dir}/links/root"
  292. ln -s /usr "#{test_dir}/links/usr"
  293. ln -s nowhere "#{test_dir}/links/broken"
  294. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  295. touch "#{test_dir}/links/some_file"
  296. ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
  297. (cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
  298. (cd "#{test_dir}/links"; ln -s "." "current_dir")
  299. (cd "#{test_dir}/links"; ln -s ".." "parent_dir")
  300. (cd "#{test_dir}/links"; ln -s "itself" "itself")
  301. EOF
  302. # Awkward passwd testcases.
  303. # sudo is needed for these because we technically aren’t a member
  304. # of the groups (because they don’t exist), and chown and chgrp
  305. # are smart enough to disallow it!
  306. config.vm.provision :shell, privileged: false, inline: <<-EOF
  307. set -xe
  308. mkdir "#{test_dir}/passwd"
  309. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  310. chmod 644 "#{test_dir}/passwd/unknown-uid"
  311. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  312. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  313. chmod 644 "#{test_dir}/passwd/unknown-gid"
  314. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  315. EOF
  316. # Awkward permission testcases.
  317. # Differences in the way ā€˜chmod’ handles setting ā€˜setuid’ and ā€˜setgid’
  318. # when you don’t already own the file mean that we need to use ā€˜sudo’
  319. # to change permissions to those.
  320. config.vm.provision :shell, privileged: false, inline: <<-EOF
  321. set -xe
  322. mkdir "#{test_dir}/permissions"
  323. mkdir "#{test_dir}/permissions/forbidden-directory"
  324. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  325. touch -t #{some_date} "#{test_dir}/permissions/forbidden-directory"
  326. sudo chown #{user}:#{user} "#{test_dir}/permissions/forbidden-directory"
  327. for perms in 000 001 002 004 010 020 040 100 200 400 644 755 777 1000 1001 2000 2010 4000 4100 7666 7777; do
  328. touch "#{test_dir}/permissions/$perms"
  329. sudo chown #{user}:#{user} "#{test_dir}/permissions/$perms"
  330. sudo chmod $perms "#{test_dir}/permissions/$perms"
  331. sudo touch -t #{some_date} "#{test_dir}/permissions/$perms"
  332. done
  333. EOF
  334. old = '200303030000.00'
  335. med = '200606152314.29' # the june gets used for fr_FR locale tests
  336. new = '200912221038.53' # and the december for ja_JP local tests
  337. # Awkward date and time testcases.
  338. config.vm.provision :shell, privileged: false, inline: <<-EOF
  339. set -xe
  340. mkdir "#{test_dir}/dates"
  341. # there's no way to touch the created date of a file...
  342. # so we have to do this the old-fashioned way!
  343. # (and make sure these don't actually get listed)
  344. touch -t #{old} "#{test_dir}/dates/peach"; sleep 1
  345. touch -t #{med} "#{test_dir}/dates/plum"; sleep 1
  346. touch -t #{new} "#{test_dir}/dates/pear"
  347. # modified dates
  348. touch -t #{old} -m "#{test_dir}/dates/pear"
  349. touch -t #{med} -m "#{test_dir}/dates/peach"
  350. touch -t #{new} -m "#{test_dir}/dates/plum"
  351. # accessed dates
  352. touch -t #{old} -a "#{test_dir}/dates/plum"
  353. touch -t #{med} -a "#{test_dir}/dates/pear"
  354. touch -t #{new} -a "#{test_dir}/dates/peach"
  355. sudo chown #{user}:#{user} -R "#{test_dir}/dates"
  356. EOF
  357. # Awkward extended attribute testcases.
  358. # We need to test combinations of various numbers of files *and*
  359. # extended attributes in directories. Turns out, the easiest way to
  360. # do this is to generate all combinations of files with ā€œone-xattrā€
  361. # or ā€œtwo-xattrsā€ in their name and directories with ā€œemptyā€ or
  362. # ā€œone-fileā€ in their name, then just give the right number of
  363. # xattrs and children to those.
  364. config.vm.provision :shell, privileged: false, inline: <<-EOF
  365. set -xe
  366. mkdir "#{test_dir}/attributes"
  367. mkdir "#{test_dir}/attributes/files"
  368. touch "#{test_dir}/attributes/files/"{no-xattrs,one-xattr,two-xattrs}{,_forbidden}
  369. mkdir "#{test_dir}/attributes/dirs"
  370. mkdir "#{test_dir}/attributes/dirs/"{no-xattrs,one-xattr,two-xattrs}_{empty,one-file,two-files}{,_forbidden}
  371. setfattr -n user.greeting -v hello "#{test_dir}/attributes"/**/*{one-xattr,two-xattrs}*
  372. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes"/**/*two-xattrs*
  373. for dir in "#{test_dir}/attributes/dirs/"*one-file*; do
  374. touch $dir/file-in-question
  375. done
  376. for dir in "#{test_dir}/attributes/dirs/"*two-files*; do
  377. touch $dir/this-file
  378. touch $dir/that-file
  379. done
  380. find "#{test_dir}/attributes" -exec touch {} -t #{some_date} \\;
  381. # I want to use the following to test,
  382. # but it only works on macos:
  383. #chmod +a "#{user} deny readextattr" "#{test_dir}/attributes"/**/*_forbidden
  384. sudo chmod 000 "#{test_dir}/attributes"/**/*_forbidden
  385. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  386. EOF
  387. # A sample Git repository
  388. # This uses cd because it's easier than telling Git where to go each time
  389. config.vm.provision :shell, privileged: false, inline: <<-EOF
  390. set -xe
  391. mkdir "#{test_dir}/git"
  392. cd "#{test_dir}/git"
  393. git init
  394. mkdir edits additions moves
  395. echo "original content" | tee edits/{staged,unstaged,both}
  396. echo "this file gets moved" > moves/hither
  397. git add edits moves
  398. git commit -m "Automated test commit"
  399. echo "modifications!" | tee edits/{staged,both}
  400. touch additions/{staged,edited}
  401. mv moves/{hither,thither}
  402. git add edits moves additions
  403. echo "more modifications!" | tee edits/unstaged edits/both additions/edited
  404. touch additions/unstaged
  405. find "#{test_dir}/git" -exec touch {} -t #{some_date} \\;
  406. sudo chown #{user}:#{user} -R "#{test_dir}/git"
  407. EOF
  408. # A second Git repository
  409. # for testing two at once
  410. config.vm.provision :shell, privileged: false, inline: <<-EOF
  411. set -xe
  412. mkdir -p "#{test_dir}/git2/deeply/nested/directory"
  413. cd "#{test_dir}/git2"
  414. git init
  415. touch "deeply/nested/directory/upd8d"
  416. git add "deeply/nested/directory/upd8d"
  417. git commit -m "Automated test commit"
  418. echo "Now with contents" > "deeply/nested/directory/upd8d"
  419. touch "deeply/nested/directory/l8st"
  420. echo -e "target\n*.mp3" > ".gitignore"
  421. mkdir "ignoreds"
  422. touch "ignoreds/music.mp3"
  423. touch "ignoreds/music.m4a"
  424. mkdir "ignoreds/nested"
  425. touch "ignoreds/nested/70s grove.mp3"
  426. touch "ignoreds/nested/funky chicken.m4a"
  427. mkdir "target"
  428. touch "target/another ignored file"
  429. mkdir "deeply/nested/repository"
  430. cd "deeply/nested/repository"
  431. git init
  432. touch subfile
  433. find "#{test_dir}/git2" -exec touch {} -t #{some_date} \\;
  434. sudo chown #{user}:#{user} -R "#{test_dir}/git2"
  435. EOF
  436. # Hidden and dot file testcases.
  437. # We need to set the permissions of `.` and `..` because they actually
  438. # get displayed in the output here, so this has to come last.
  439. config.vm.provision :shell, privileged: false, inline: <<-EOF
  440. set -xe
  441. shopt -u dotglob
  442. GLOBIGNORE=".:.."
  443. mkdir "#{test_dir}/hiddens"
  444. touch "#{test_dir}/hiddens/visible"
  445. touch "#{test_dir}/hiddens/.hidden"
  446. touch "#{test_dir}/hiddens/..extra-hidden"
  447. # ./hiddens/
  448. touch -t #{some_date} "#{test_dir}/hiddens/"*
  449. chmod 644 "#{test_dir}/hiddens/"*
  450. sudo chown #{user}:#{user} "#{test_dir}/hiddens/"*
  451. # .
  452. touch -t #{some_date} "#{test_dir}/hiddens"
  453. chmod 755 "#{test_dir}/hiddens"
  454. sudo chown #{user}:#{user} "#{test_dir}/hiddens"
  455. # ..
  456. sudo touch -t #{some_date} "#{test_dir}"
  457. sudo chmod 755 "#{test_dir}"
  458. sudo chown #{user}:#{user} "#{test_dir}"
  459. EOF
  460. # Set up some locales
  461. config.vm.provision :shell, privileged: false, inline: <<-EOF
  462. set -xe
  463. # uncomment these from the config file
  464. sudo sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen
  465. sudo sed -i '/ja_JP.UTF-8/s/^# //g' /etc/locale.gen
  466. sudo locale-gen
  467. EOF
  468. # Install kcov for test coverage
  469. # This doesn’t run coverage over the xtests so it’s less useful for now
  470. if ENV.key?('INSTALL_KCOV')
  471. config.vm.provision :shell, privileged: false, inline: <<-EOF
  472. set -xe
  473. test -e ~/.cargo/bin/cargo-kcov \
  474. || cargo install cargo-kcov
  475. sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  476. cmake g++ pkg-config \
  477. libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev
  478. cargo kcov --print-install-kcov-sh | sudo sh
  479. EOF
  480. end
  481. end
  482. # Remember that problem that exa had where the binary wasn’t actually
  483. # self-contained? Or the problem where the Linux binary was actually the
  484. # macOS binary in disguise?
  485. #
  486. # This is a ā€œfreshā€ VM that intentionally downloads no dependencies and
  487. # installs nothing so that we can check that exa still runs!
  488. config.vm.define(:fresh) do |config|
  489. config.vm.box = UBUNTU
  490. config.vm.hostname = 'fresh'
  491. config.vm.provider :virtualbox do |v|
  492. v.name = 'exa-fresh'
  493. v.memory = 384
  494. v.cpus = 1
  495. end
  496. end
  497. end