Vagrantfile 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 zip \
  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: true, inline: <<-EOF
  36. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
  37. echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
  38. EOF
  39. # Create a variety of misc scripts.
  40. config.vm.provision :shell, privileged: true, inline: <<-EOF
  41. set -xe
  42. echo -e "#!/bin/sh\n/home/#{developer}/target/debug/exa \"\\$*\"" > /usr/bin/exa
  43. echo -e "#!/bin/sh\n/home/#{developer}/target/release/exa \"\\$*\"" > /usr/bin/rexa
  44. echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml" > /usr/bin/build-exa
  45. ln -sf /usr/bin/build-exa /usr/bin/b
  46. echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml --lib -- --quiet" > /usr/bin/test-exa
  47. ln -sf /usr/bin/test-exa /usr/bin/t
  48. echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
  49. ln -sf /usr/bin/run-xtests /usr/bin/x
  50. echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
  51. ln -sf /usr/bin/compile-exa /usr/bin/c
  52. echo "#!/bin/bash" > /usr/bin/package-exa
  53. echo "set -e" >> /usr/bin/package-exa
  54. echo 'echo -e "\nCompiling release version of exa..."' >> /usr/bin/package-exa
  55. echo "cargo build --release --manifest-path /vagrant/Cargo.toml" >> /usr/bin/package-exa
  56. echo "cargo test --release --manifest-path /vagrant/Cargo.toml --lib" >> /usr/bin/package-exa
  57. echo "/vagrant/xtests/run.sh --release" >> /usr/bin/package-exa
  58. echo "cp /home/ubuntu/target/release/exa /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  59. echo 'echo -e "\nStripping binary..."' >> /usr/bin/package-exa
  60. echo "strip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  61. echo 'echo -e "\nZipping binary..."' >> /usr/bin/package-exa
  62. echo "rm -f /vagrant/exa-linux-x86_64.zip" >> /usr/bin/package-exa
  63. echo "zip /vagrant/exa-linux-x86_64.zip /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  64. echo 'echo -e "\nLibraries linked:"' >> /usr/bin/package-exa
  65. echo "ldd /vagrant/exa-linux-x86_64" >> /usr/bin/package-exa
  66. echo 'echo -e "\nAll done!"' >> /usr/bin/package-exa
  67. echo '/vagrant/exa-linux-x86_64 /vagrant/exa-linux-x86_64* -lB' >> /usr/bin/package-exa
  68. chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa,package-exa}
  69. EOF
  70. # Write some welcoming text.
  71. config.vm.provision :shell, privileged: true, inline: <<-EOF
  72. rm -f /etc/update-motd.d/*
  73. echo -e "" > /etc/motd
  74. echo -e "\033[1;33mThe exa development environment!\033[0m" >> /etc/motd
  75. echo -e "exa's source is available at \033[33m/vagrant\033[0m." >> /etc/motd
  76. echo -e "Binaries get built into \033[33m/home/ubuntu/target\033[0m." >> /etc/motd
  77. echo -e "" >> /etc/motd
  78. echo -e "\033[4mCommands\033[0m" >> /etc/motd
  79. echo -e "\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m" >> /etc/motd
  80. echo -e "\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m" >> /etc/motd
  81. 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
  82. echo -e "\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three" >> /etc/motd
  83. echo -e "\033[32;1mdebug on\033[0;32m|\033[1moff\033[0m to toggle printing logs" >> /etc/motd
  84. echo -e "\033[32;1mstrict on\033[0;32m|\033[1moff\033[0m to toggle strict mode" >> /etc/motd
  85. echo -e "\033[32;1mls-colors on\033[0;32m|\033[1moff\033[0m to toggle LS_COLORS\n" >> /etc/motd
  86. # help banner
  87. echo 'echo -e "\\033[4mVersions\\033[0m"' > /home/ubuntu/.bash_profile
  88. echo "rustc --version" >> /home/ubuntu/.bash_profile
  89. echo "cargo --version" >> /home/ubuntu/.bash_profile
  90. echo "echo" >> /home/ubuntu/.bash_profile
  91. # cool prompt
  92. echo 'function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }' >> /home/ubuntu/.bash_profile
  93. echo 'function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }' >> /home/ubuntu/.bash_profile
  94. echo 'function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }' >> /home/ubuntu/.bash_profile
  95. echo 'function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }' >> /home/ubuntu/.bash_profile
  96. echo 'export PS1="\\[\\e[1;36m\\]\\h \\[\\e[32m\\]\\w \\[\\e[31m\\]\\`nonzero_return\\`\\[\\e[35m\\]\\`debug_mode\\`\\[\\e[32m\\]\\`lsc_mode\\`\\[\\e[33m\\]\\`strict_mode\\`\\[\\e[36m\\]\\\\$\\[\\e[0m\\] "' >> /home/ubuntu/.bash_profile
  97. # environment setting
  98. echo 'function debug () {' >> /home/ubuntu/.bash_profile
  99. echo ' case "$1" in "on") export EXA_DEBUG=1 ;;' >> /home/ubuntu/.bash_profile
  100. echo ' "off") export EXA_DEBUG= ;;' >> /home/ubuntu/.bash_profile
  101. echo ' "") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;' >> /home/ubuntu/.bash_profile
  102. echo ' *) echo "Usage: debug on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  103. echo 'function strict () {' >> /home/ubuntu/.bash_profile
  104. echo ' case "$1" in "on") export EXA_STRICT=1 ;;' >> /home/ubuntu/.bash_profile
  105. echo ' "off") export EXA_STRICT= ;;' >> /home/ubuntu/.bash_profile
  106. echo ' "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;' >> /home/ubuntu/.bash_profile
  107. echo ' *) echo "Usage: strict on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  108. echo 'function ls-colors () {' >> /home/ubuntu/.bash_profile
  109. echo ' case "$1" in "on") 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
  110. echo ' "off") export LS_COLORS= ;;' >> /home/ubuntu/.bash_profile
  111. echo ' "") [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off" ;;' >> /home/ubuntu/.bash_profile
  112. echo ' *) echo "Usage: ls-colors on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
  113. # Disable last login date in sshd
  114. sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
  115. systemctl restart sshd
  116. EOF
  117. # Link the completion files so they’re “installed”.
  118. config.vm.provision :shell, privileged: true, inline: <<-EOF
  119. set -xe
  120. test -h /etc/bash_completion.d/exa \
  121. || ln -s /vagrant/contrib/completions.bash /etc/bash_completion.d/exa
  122. test -h /usr/share/zsh/vendor-completions/_exa \
  123. || ln -s /vagrant/contrib/completions.zsh /usr/share/zsh/vendor-completions/_exa
  124. test -h /usr/share/fish/completions/exa.fish \
  125. || ln -s /vagrant/contrib/completions.fish /usr/share/fish/completions/exa.fish
  126. EOF
  127. # We create two users that own the test files.
  128. # The first one just owns the ordinary ones, because we don’t want the
  129. # test outputs to depend on “vagrant” or “ubuntu” existing.
  130. user = "cassowary"
  131. config.vm.provision :shell, privileged: true, inline:
  132. %[id -u #{user} &>/dev/null || useradd #{user}]
  133. # The second one has a long name, to test that the file owner column
  134. # widens correctly. The benefit of Vagrant is that we don’t need to
  135. # set this up on the *actual* system!
  136. longuser = "antidisestablishmentarienism"
  137. config.vm.provision :shell, privileged: true, inline:
  138. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  139. # Because the timestamps are formatted differently depending on whether
  140. # they’re in the current year or not (see `details.rs`), we have to make
  141. # sure that the files are created in the current year, so they get shown
  142. # in the format we expect.
  143. current_year = Date.today.year
  144. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  145. # We also need an UID and a GID that are guaranteed to not exist, to
  146. # test what happen when they don’t.
  147. invalid_uid = 666
  148. invalid_gid = 616
  149. # Delete old testcases if they exist already, then create a
  150. # directory to house new ones.
  151. test_dir = "/testcases"
  152. config.vm.provision :shell, privileged: true, inline: <<-EOF
  153. set -xe
  154. rm -rfv #{test_dir}
  155. mkdir #{test_dir}
  156. chmod 777 #{test_dir}
  157. EOF
  158. # Awkward file size testcases.
  159. # This needs sudo to set the files’ users at the very end.
  160. config.vm.provision :shell, privileged: false, inline: <<-EOF
  161. set -xe
  162. mkdir "#{test_dir}/files"
  163. for i in {1..13}; do
  164. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  165. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  166. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  167. done
  168. touch -t #{some_date} "#{test_dir}/files/"*
  169. chmod 644 "#{test_dir}/files/"*
  170. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  171. EOF
  172. # File name extension testcases.
  173. # These aren’t tested in details view, but we set timestamps on them to
  174. # test that various sort options work.
  175. config.vm.provision :shell, privileged: false, inline: <<-EOF
  176. set -xe
  177. mkdir "#{test_dir}/file-names-exts"
  178. touch "#{test_dir}/file-names-exts/Makefile"
  179. touch "#{test_dir}/file-names-exts/IMAGE.PNG"
  180. touch "#{test_dir}/file-names-exts/image.svg"
  181. touch "#{test_dir}/file-names-exts/VIDEO.AVI"
  182. touch "#{test_dir}/file-names-exts/video.wmv"
  183. touch "#{test_dir}/file-names-exts/music.mp3"
  184. touch "#{test_dir}/file-names-exts/MUSIC.OGG"
  185. touch "#{test_dir}/file-names-exts/lossless.flac"
  186. touch "#{test_dir}/file-names-exts/lossless.wav"
  187. touch "#{test_dir}/file-names-exts/crypto.asc"
  188. touch "#{test_dir}/file-names-exts/crypto.signature"
  189. touch "#{test_dir}/file-names-exts/document.pdf"
  190. touch "#{test_dir}/file-names-exts/DOCUMENT.XLSX"
  191. touch "#{test_dir}/file-names-exts/COMPRESSED.ZIP"
  192. touch "#{test_dir}/file-names-exts/compressed.tar.gz"
  193. touch "#{test_dir}/file-names-exts/compressed.tgz"
  194. touch "#{test_dir}/file-names-exts/compressed.tar.xz"
  195. touch "#{test_dir}/file-names-exts/compressed.txz"
  196. touch "#{test_dir}/file-names-exts/compressed.deb"
  197. touch "#{test_dir}/file-names-exts/backup~"
  198. touch "#{test_dir}/file-names-exts/#SAVEFILE#"
  199. touch "#{test_dir}/file-names-exts/file.tmp"
  200. touch "#{test_dir}/file-names-exts/compiled.class"
  201. touch "#{test_dir}/file-names-exts/compiled.o"
  202. touch "#{test_dir}/file-names-exts/compiled.js"
  203. touch "#{test_dir}/file-names-exts/compiled.coffee"
  204. EOF
  205. # File name testcases.
  206. # bash really doesn’t want you to create a file with escaped characters
  207. # in its name, so we have to resort to the echo builtin and touch!
  208. #
  209. # The double backslashes are not strictly necessary; without them, Ruby
  210. # will interpolate them instead of bash, but because Vagrant prints out
  211. # each command it runs, your *own* terminal will go “ding” from the alarm!
  212. config.vm.provision :shell, privileged: false, inline: <<-EOF
  213. set -xe
  214. mkdir "#{test_dir}/file-names"
  215. echo -ne "#{test_dir}/file-names/ascii: hello" | xargs -0 touch
  216. echo -ne "#{test_dir}/file-names/emoji: [🆒]" | xargs -0 touch
  217. echo -ne "#{test_dir}/file-names/utf-8: pâté" | xargs -0 touch
  218. echo -ne "#{test_dir}/file-names/bell: [\\a]" | xargs -0 touch
  219. echo -ne "#{test_dir}/file-names/backspace: [\\b]" | xargs -0 touch
  220. echo -ne "#{test_dir}/file-names/form-feed: [\\f]" | xargs -0 touch
  221. echo -ne "#{test_dir}/file-names/new-line: [\\n]" | xargs -0 touch
  222. echo -ne "#{test_dir}/file-names/return: [\\r]" | xargs -0 touch
  223. echo -ne "#{test_dir}/file-names/tab: [\\t]" | xargs -0 touch
  224. echo -ne "#{test_dir}/file-names/vertical-tab: [\\v]" | xargs -0 touch
  225. echo -ne "#{test_dir}/file-names/escape: [\\033]" | xargs -0 touch
  226. echo -ne "#{test_dir}/file-names/ansi: [\\033[34mblue\\033[0m]" | xargs -0 touch
  227. echo -ne "#{test_dir}/file-names/invalid-utf8-1: [\\xFF]" | xargs -0 touch
  228. echo -ne "#{test_dir}/file-names/invalid-utf8-2: [\\xc3\\x28]" | xargs -0 touch
  229. echo -ne "#{test_dir}/file-names/invalid-utf8-3: [\\xe2\\x82\\x28]" | xargs -0 touch
  230. echo -ne "#{test_dir}/file-names/invalid-utf8-4: [\\xf0\\x28\\x8c\\x28]" | xargs -0 touch
  231. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]" | xargs -0 mkdir
  232. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/subfile" | xargs -0 touch
  233. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/another: [\\n]" | xargs -0 touch
  234. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 touch
  235. mkdir "#{test_dir}/file-names/links"
  236. ln -s "#{test_dir}/file-names/new-line-dir"*/* "#{test_dir}/file-names/links"
  237. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 rm
  238. EOF
  239. # Special file testcases.
  240. config.vm.provision :shell, privileged: false, inline: <<-EOF
  241. set -xe
  242. mkdir "#{test_dir}/specials"
  243. sudo mknod "#{test_dir}/specials/block-device" b 3 60
  244. sudo mknod "#{test_dir}/specials/char-device" c 14 40
  245. sudo mknod "#{test_dir}/specials/named-pipe" p
  246. sudo touch -t #{some_date} "#{test_dir}/specials/"*
  247. EOF
  248. # Awkward symlink testcases.
  249. config.vm.provision :shell, privileged: false, inline: <<-EOF
  250. set -xe
  251. mkdir "#{test_dir}/links"
  252. ln -s / "#{test_dir}/links/root"
  253. ln -s /usr "#{test_dir}/links/usr"
  254. ln -s nowhere "#{test_dir}/links/broken"
  255. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  256. touch "#{test_dir}/links/some_file"
  257. ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
  258. (cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
  259. (cd "#{test_dir}/links"; ln -s "." "current_dir")
  260. (cd "#{test_dir}/links"; ln -s ".." "parent_dir")
  261. (cd "#{test_dir}/links"; ln -s "itself" "itself")
  262. EOF
  263. # Awkward passwd testcases.
  264. # sudo is needed for these because we technically aren’t a member
  265. # of the groups (because they don’t exist), and chown and chgrp
  266. # are smart enough to disallow it!
  267. config.vm.provision :shell, privileged: false, inline: <<-EOF
  268. set -xe
  269. mkdir "#{test_dir}/passwd"
  270. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  271. chmod 644 "#{test_dir}/passwd/unknown-uid"
  272. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  273. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  274. chmod 644 "#{test_dir}/passwd/unknown-gid"
  275. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  276. EOF
  277. # Awkward permission testcases.
  278. # Differences in the way ‘chmod’ handles setting ‘setuid’ and ‘setgid’
  279. # when you don’t already own the file mean that we need to use ‘sudo’
  280. # to change permissions to those.
  281. config.vm.provision :shell, privileged: false, inline: <<-EOF
  282. set -xe
  283. mkdir "#{test_dir}/permissions"
  284. mkdir "#{test_dir}/permissions/forbidden-directory"
  285. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  286. touch -t #{some_date} "#{test_dir}/permissions/forbidden-directory"
  287. sudo chown #{user}:#{user} "#{test_dir}/permissions/forbidden-directory"
  288. 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
  289. touch "#{test_dir}/permissions/$perms"
  290. sudo chown #{user}:#{user} "#{test_dir}/permissions/$perms"
  291. sudo chmod $perms "#{test_dir}/permissions/$perms"
  292. sudo touch -t #{some_date} "#{test_dir}/permissions/$perms"
  293. done
  294. EOF
  295. old = '200303030000.00'
  296. med = '200606152314.29' # the june gets used for fr_FR locale tests
  297. new = '200912221038.53' # and the december for ja_JP local tests
  298. # Awkward date and time testcases.
  299. config.vm.provision :shell, privileged: false, inline: <<-EOF
  300. set -xe
  301. mkdir "#{test_dir}/dates"
  302. # there's no way to touch the created date of a file...
  303. # so we have to do this the old-fashioned way!
  304. # (and make sure these don't actually get listed)
  305. touch -t #{old} "#{test_dir}/dates/peach"; sleep 1
  306. touch -t #{med} "#{test_dir}/dates/plum"; sleep 1
  307. touch -t #{new} "#{test_dir}/dates/pear"
  308. # modified dates
  309. touch -t #{old} -m "#{test_dir}/dates/pear"
  310. touch -t #{med} -m "#{test_dir}/dates/peach"
  311. touch -t #{new} -m "#{test_dir}/dates/plum"
  312. # accessed dates
  313. touch -t #{old} -a "#{test_dir}/dates/plum"
  314. touch -t #{med} -a "#{test_dir}/dates/pear"
  315. touch -t #{new} -a "#{test_dir}/dates/peach"
  316. sudo chown #{user}:#{user} -R "#{test_dir}/dates"
  317. EOF
  318. # Awkward extended attribute testcases.
  319. # We need to test combinations of various numbers of files *and*
  320. # extended attributes in directories. Turns out, the easiest way to
  321. # do this is to generate all combinations of files with “one-xattr”
  322. # or “two-xattrs” in their name and directories with “empty” or
  323. # “one-file” in their name, then just give the right number of
  324. # xattrs and children to those.
  325. config.vm.provision :shell, privileged: false, inline: <<-EOF
  326. set -xe
  327. mkdir "#{test_dir}/attributes"
  328. mkdir "#{test_dir}/attributes/files"
  329. touch "#{test_dir}/attributes/files/"{no-xattrs,one-xattr,two-xattrs}{,_forbidden}
  330. mkdir "#{test_dir}/attributes/dirs"
  331. mkdir "#{test_dir}/attributes/dirs/"{no-xattrs,one-xattr,two-xattrs}_{empty,one-file,two-files}{,_forbidden}
  332. setfattr -n user.greeting -v hello "#{test_dir}/attributes"/**/*{one-xattr,two-xattrs}*
  333. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes"/**/*two-xattrs*
  334. for dir in "#{test_dir}/attributes/dirs/"*one-file*; do
  335. touch $dir/file-in-question
  336. done
  337. for dir in "#{test_dir}/attributes/dirs/"*two-files*; do
  338. touch $dir/this-file
  339. touch $dir/that-file
  340. done
  341. touch -t #{some_date} "#{test_dir}/attributes" # there's probably
  342. touch -t #{some_date} "#{test_dir}/attributes"/* # a better
  343. touch -t #{some_date} "#{test_dir}/attributes"/*/* # way to
  344. touch -t #{some_date} "#{test_dir}/attributes"/*/*/* # do this
  345. # I want to use the following to test,
  346. # but it only works on macos:
  347. #chmod +a "#{user} deny readextattr" "#{test_dir}/attributes"/**/*_forbidden
  348. sudo chmod 000 "#{test_dir}/attributes"/**/*_forbidden
  349. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  350. EOF
  351. # A sample Git repository
  352. # This uses cd because it's easier than telling Git where to go each time
  353. config.vm.provision :shell, privileged: false, inline: <<-EOF
  354. set -xe
  355. mkdir "#{test_dir}/git"
  356. cd "#{test_dir}/git"
  357. git init
  358. mkdir edits additions moves
  359. echo "original content" | tee edits/{staged,unstaged,both}
  360. echo "this file gets moved" > moves/hither
  361. git add edits moves
  362. git commit -m "Automated test commit"
  363. echo "modifications!" | tee edits/{staged,both}
  364. touch additions/{staged,edited}
  365. mv moves/{hither,thither}
  366. git add edits moves additions
  367. echo "more modifications!" | tee edits/unstaged edits/both additions/edited
  368. touch additions/unstaged
  369. touch -t #{some_date} "#{test_dir}/git/"*/*
  370. sudo chown #{user}:#{user} -R "#{test_dir}/git"
  371. EOF
  372. # Hidden and dot file testcases.
  373. # We need to set the permissions of `.` and `..` because they actually
  374. # get displayed in the output here, so this has to come last.
  375. config.vm.provision :shell, privileged: false, inline: <<-EOF
  376. set -xe
  377. shopt -u dotglob
  378. GLOBIGNORE=".:.."
  379. mkdir "#{test_dir}/hiddens"
  380. touch "#{test_dir}/hiddens/visible"
  381. touch "#{test_dir}/hiddens/.hidden"
  382. touch "#{test_dir}/hiddens/..extra-hidden"
  383. # ./hiddens/
  384. touch -t #{some_date} "#{test_dir}/hiddens/"*
  385. chmod 644 "#{test_dir}/hiddens/"*
  386. sudo chown #{user}:#{user} "#{test_dir}/hiddens/"*
  387. # .
  388. touch -t #{some_date} "#{test_dir}/hiddens"
  389. chmod 755 "#{test_dir}/hiddens"
  390. sudo chown #{user}:#{user} "#{test_dir}/hiddens"
  391. # ..
  392. sudo touch -t #{some_date} "#{test_dir}"
  393. sudo chmod 755 "#{test_dir}"
  394. sudo chown #{user}:#{user} "#{test_dir}"
  395. EOF
  396. # Set up some locales
  397. config.vm.provision :shell, privileged: false, inline: <<-EOF
  398. set -xe
  399. # uncomment these from the config file
  400. sudo sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen
  401. sudo sed -i '/ja_JP.UTF-8/s/^# //g' /etc/locale.gen
  402. sudo locale-gen
  403. EOF
  404. # Install kcov for test coverage
  405. # This doesn’t run coverage over the xtests so it’s less useful for now
  406. if ENV.key?('INSTALL_KCOV')
  407. config.vm.provision :shell, privileged: false, inline: <<-EOF
  408. set -xe
  409. test -e ~/.cargo/bin/cargo-kcov \
  410. || cargo install cargo-kcov
  411. sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y \
  412. cmake g++ pkg-config \
  413. libcurl4-openssl-dev libdw-dev binutils-dev libiberty-dev
  414. cargo kcov --print-install-kcov-sh | sudo sh
  415. EOF
  416. end
  417. end