Vagrantfile 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. # We use Ubuntu instead of Debian because the image comes with two-way
  9. # shared folder support by default.
  10. config.vm.box = 'ubuntu/xenial64'
  11. config.vm.hostname = 'exa'
  12. # Install the dependencies needed for exa to build, as quietly as
  13. # apt can do.
  14. config.vm.provision :shell, privileged: true, inline:
  15. %[apt-get install -qq -o=Dpkg::Use-Pty=0 -y git cmake libssl-dev libgit2-dev libssh2-1-dev curl attr pkg-config]
  16. # Guarantee that the timezone is UTC -- some of the tests
  17. # depend on this (for now).
  18. config.vm.provision :shell, privileged: true, inline:
  19. %[timedatectl set-timezone UTC]
  20. # Install Rust.
  21. # This is done as vagrant, not root, because it’s vagrant
  22. # who actually uses it. Sent to /dev/null because the progress
  23. # bar produces a ton of output.
  24. config.vm.provision :shell, privileged: false, inline:
  25. %[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
  26. # Use a different ‘target’ directory on the VM than on the host.
  27. # By default it just uses the one in /vagrant/target, which can
  28. # cause problems if it has different permissions than the other
  29. # directories, or contains object files compiled for the host.
  30. config.vm.provision :shell, privileged: false, inline:
  31. %[echo "export CARGO_TARGET_DIR=/home/ubuntu/target" >> ~/.bashrc]
  32. # We create two users that own the test files.
  33. # The first one just owns the ordinary ones, because we don’t want to
  34. # depend on “vagrant” or “ubuntu” existing.
  35. user = "cassowary"
  36. config.vm.provision :shell, privileged: true, inline:
  37. %[id -u #{user} &>/dev/null || useradd #{user}]
  38. # The second one has a long name, to test that the file owner column
  39. # widens correctly. The benefit of Vagrant is that we don’t need to
  40. # set this up on the *actual* system!
  41. longuser = "antidisestablishmentarienism"
  42. config.vm.provision :shell, privileged: true, inline:
  43. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  44. # Because the timestamps are formatted differently depending on whether
  45. # they’re in the current year or not (see `details.rs`), we have to make
  46. # sure that the files are created in the current year, so they get shown
  47. # in the format we expect.
  48. current_year = Date.today.year
  49. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  50. # We also need an UID and a GID that are guaranteed to not exist, to
  51. # test what happen when they don’t.
  52. invalid_uid = 666
  53. invalid_gid = 616
  54. # Delete old testcases if they exist already, then create a
  55. # directory to house new ones.
  56. test_dir = "/testcases"
  57. config.vm.provision :shell, privileged: true, inline: <<-EOF
  58. set -xe
  59. rm -rfv #{test_dir}
  60. mkdir #{test_dir}
  61. chmod 777 #{test_dir}
  62. EOF
  63. # Awkward file size testcases.
  64. # This needs sudo to set the files’ users at the very end.
  65. config.vm.provision :shell, privileged: false, inline: <<-EOF
  66. set -xe
  67. mkdir "#{test_dir}/files"
  68. for i in {1..13}; do
  69. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  70. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  71. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  72. done
  73. touch -t #{some_date} "#{test_dir}/files/"*
  74. chmod 644 "#{test_dir}/files/"*
  75. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  76. EOF
  77. # File name extension testcases.
  78. # These are tested in grid view, so we don’t need to bother setting
  79. # owners or timestamps or anything.
  80. config.vm.provision :shell, privileged: false, inline: <<-EOF
  81. set -xe
  82. mkdir "#{test_dir}/file-names-exts"
  83. touch "#{test_dir}/file-names-exts/Makefile"
  84. touch "#{test_dir}/file-names-exts/image.png"
  85. touch "#{test_dir}/file-names-exts/image.svg"
  86. touch "#{test_dir}/file-names-exts/video.avi"
  87. touch "#{test_dir}/file-names-exts/video.wmv"
  88. touch "#{test_dir}/file-names-exts/music.mp3"
  89. touch "#{test_dir}/file-names-exts/music.ogg"
  90. touch "#{test_dir}/file-names-exts/lossless.flac"
  91. touch "#{test_dir}/file-names-exts/lossless.wav"
  92. touch "#{test_dir}/file-names-exts/crypto.asc"
  93. touch "#{test_dir}/file-names-exts/crypto.signature"
  94. touch "#{test_dir}/file-names-exts/document.pdf"
  95. touch "#{test_dir}/file-names-exts/document.xlsx"
  96. touch "#{test_dir}/file-names-exts/compressed.zip"
  97. touch "#{test_dir}/file-names-exts/compressed.tar.gz"
  98. touch "#{test_dir}/file-names-exts/compressed.tgz"
  99. touch "#{test_dir}/file-names-exts/backup~"
  100. touch "#{test_dir}/file-names-exts/#SAVEFILE#"
  101. touch "#{test_dir}/file-names-exts/file.tmp"
  102. touch "#{test_dir}/file-names-exts/compiled.class"
  103. touch "#{test_dir}/file-names-exts/compiled.o"
  104. touch "#{test_dir}/file-names-exts/compiled.js"
  105. touch "#{test_dir}/file-names-exts/compiled.coffee"
  106. EOF
  107. # Special file testcases.
  108. config.vm.provision :shell, privileged: false, inline: <<-EOF
  109. set -xe
  110. mkdir "#{test_dir}/specials"
  111. sudo mknod "#{test_dir}/specials/block-device" b 3 60
  112. sudo mknod "#{test_dir}/specials/char-device" c 14 40
  113. sudo mknod "#{test_dir}/specials/named-pipe" p
  114. sudo touch -t #{some_date} "#{test_dir}/specials/"*
  115. EOF
  116. # Awkward symlink testcases.
  117. config.vm.provision :shell, privileged: false, inline: <<-EOF
  118. set -xe
  119. mkdir "#{test_dir}/links"
  120. ln -s / "#{test_dir}/links/root"
  121. ln -s /usr "#{test_dir}/links/usr"
  122. ln -s nowhere "#{test_dir}/links/broken"
  123. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  124. touch "#{test_dir}/links/some_file"
  125. ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
  126. (cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
  127. (cd "#{test_dir}/links"; ln -s "." "current_dir")
  128. (cd "#{test_dir}/links"; ln -s ".." "parent_dir")
  129. (cd "#{test_dir}/links"; ln -s "itself" "itself")
  130. EOF
  131. # Awkward passwd testcases.
  132. # sudo is needed for these because we technically aren’t a member
  133. # of the groups (because they don’t exist), and chown and chgrp
  134. # are smart enough to disallow it!
  135. config.vm.provision :shell, privileged: false, inline: <<-EOF
  136. set -xe
  137. mkdir "#{test_dir}/passwd"
  138. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  139. chmod 644 "#{test_dir}/passwd/unknown-uid"
  140. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  141. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  142. chmod 644 "#{test_dir}/passwd/unknown-gid"
  143. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  144. EOF
  145. # Awkward permission testcases.
  146. config.vm.provision :shell, privileged: false, inline: <<-EOF
  147. set -xe
  148. mkdir "#{test_dir}/permissions"
  149. touch "#{test_dir}/permissions/all-permissions"
  150. chmod 777 "#{test_dir}/permissions/all-permissions"
  151. touch "#{test_dir}/permissions/no-permissions"
  152. chmod 000 "#{test_dir}/permissions/no-permissions"
  153. mkdir "#{test_dir}/permissions/forbidden-directory"
  154. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  155. for perms in 001 002 004 010 020 040 100 200 400; do
  156. touch "#{test_dir}/permissions/$perms"
  157. chmod $perms "#{test_dir}/permissions/$perms"
  158. done
  159. touch -t #{some_date} "#{test_dir}/permissions/"*
  160. sudo chown #{user}:#{user} "#{test_dir}/permissions/"*
  161. EOF
  162. # Awkward extended attribute testcases.
  163. config.vm.provision :shell, privileged: false, inline: <<-EOF
  164. set -xe
  165. mkdir "#{test_dir}/attributes"
  166. touch "#{test_dir}/attributes/none"
  167. touch "#{test_dir}/attributes/one"
  168. setfattr -n user.greeting -v hello "#{test_dir}/attributes/one"
  169. touch "#{test_dir}/attributes/two"
  170. setfattr -n user.greeting -v hello "#{test_dir}/attributes/two"
  171. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes/two"
  172. #touch "#{test_dir}/attributes/forbidden"
  173. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/forbidden"
  174. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/forbidden"
  175. mkdir "#{test_dir}/attributes/dirs"
  176. mkdir "#{test_dir}/attributes/dirs/empty-with-attribute"
  177. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/empty-with-attribute"
  178. mkdir "#{test_dir}/attributes/dirs/full-with-attribute"
  179. touch "#{test_dir}/attributes/dirs/full-with-attribute/file"
  180. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-with-attribute"
  181. mkdir "#{test_dir}/attributes/dirs/full-but-forbidden"
  182. touch "#{test_dir}/attributes/dirs/full-but-forbidden/file"
  183. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-but-forbidden"
  184. #chmod 000 "#{test_dir}/attributes/dirs/full-but-forbidden"
  185. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/dirs/full-but-forbidden"
  186. touch -t #{some_date} "#{test_dir}/attributes"
  187. touch -t #{some_date} "#{test_dir}/attributes/"*
  188. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*
  189. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*/*
  190. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  191. EOF
  192. end