Add some more helper scripts

Also, add some welcoming text when the user logs in over SSH.
This commit is contained in:
Benjamin Sago 2017-08-19 17:59:52 +01:00
parent 9e4ac8cae9
commit 1c2e34f649
1 changed files with 42 additions and 13 deletions

55
Vagrantfile vendored
View File

@ -44,27 +44,56 @@ Vagrant.configure(2) do |config|
# By default it just uses the one in /vagrant/target, which can
# cause problems if it has different permissions than the other
# directories, or contains object files compiled for the host.
config.vm.provision :shell, privileged: false, inline: <<-EOF
function put_line() {
grep -q -F "$2" $1 || echo "$2" >> $1
}
put_line ~/.bashrc 'export CARGO_TARGET_DIR=/home/#{developer}/target'
put_line ~/.bashrc 'export PATH=$PATH:/home/#{developer}/.cargo/bin'
config.vm.provision :shell, privileged: true, inline: <<-EOF
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/#{developer}/.cargo/bin"' > /etc/environment
echo 'CARGO_TARGET_DIR="/home/#{developer}/target"' >> /etc/environment
EOF
# Create "dexa" and "rexa" scripts that run the debug and release
# compiled versions of exa.
# Create a variety of misc scripts.
config.vm.provision :shell, privileged: true, inline: <<-EOF
set -xe
echo -e "#!/bin/sh\n/home/#{developer}/target/debug/exa \"\\$*\"" > /usr/bin/exa
echo -e "#!/bin/sh\n/home/#{developer}/target/release/exa \"\\$*\"" > /usr/bin/rexa
echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml" > /usr/bin/b
echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml" > /usr/bin/t
echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/x
chmod +x /usr/bin/{exa,rexa,b,t,x}
echo -e "#!/bin/sh\ncargo build --manifest-path /vagrant/Cargo.toml" > /usr/bin/build-exa
ln -sf /usr/bin/build-exa /usr/bin/b
echo -e "#!/bin/sh\ncargo test --manifest-path /vagrant/Cargo.toml" > /usr/bin/test-exa
ln -sf /usr/bin/test-exa /usr/bin/t
echo -e "#!/bin/sh\n/vagrant/xtests/run.sh" > /usr/bin/run-xtests
ln -sf /usr/bin/run-xtests /usr/bin/x
echo -e "#!/bin/sh\nbuild-exa && test-exa && run-xtests" > /usr/bin/compile-exa
ln -sf /usr/bin/compile-exa /usr/bin/c
chmod +x /usr/bin/{exa,rexa,b,t,x,c,build-exa,test-exa,run-xtests,compile-exa}
EOF
# Write some welcoming text.
config.vm.provision :shell, privileged: true, inline: <<-EOF
rm -f /etc/update-motd.d/*
echo -e "" > /etc/motd
echo -e "\033[1;33mThe exa development environment!\033[0m" >> /etc/motd
echo -e "" >> /etc/motd
echo -e "\033[4mCommands\033[0m" >> /etc/motd
echo -e "\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m" >> /etc/motd
echo -e "\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m" >> /etc/motd
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
echo -e "\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three\n" >> /etc/motd
echo 'echo -e "\\033[4mVersions\\033[0m"' > /home/ubuntu/.bash_profile
echo "rustc --version" >> /home/ubuntu/.bash_profile
echo "cargo --version" >> /home/ubuntu/.bash_profile
echo "echo" >> /home/ubuntu/.bash_profile
# Disable last login date in sshd
sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config
systemctl restart sshd
EOF