Vagrantfile 8.9 KB

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