Move the welcoming text to their own files too

Again, it was hard to read and edit this text when it was in a string inside an echo command inside a bash script inside a heredoc inside a Ruby script wrapped in a mystery. It also gives me space to write some actual comments.
This commit is contained in:
Benjamin Sago 2017-10-01 09:49:45 +02:00
parent 173e9b2345
commit a4bd8f7f17
4 changed files with 88 additions and 56 deletions

61
Vagrantfile vendored
View File

@ -110,66 +110,15 @@ Vagrant.configure(2) do |config|
# actually works.
# Write some welcoming text.
# Configure the welcoming text that gets shown.
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 "exa's source is available at \033[33m/vagrant\033[0m." >> /etc/motd
echo -e "Binaries get built into \033[33m/home/ubuntu/target\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" >> /etc/motd
echo -e "\033[32;1mdebug\033[0m to toggle printing logs" >> /etc/motd
echo -e "\033[32;1mstrict\033[0m to toggle strict mode" >> /etc/motd
echo -e "\033[32;1mcolors\033[0m to toggle custom colours\n" >> /etc/motd
# Capture the help text so it gets displayed first
bash /vagrant/devtools/dev-help.sh > /etc/motd
# help banner
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
# cool prompt
echo 'function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }' >> /home/ubuntu/.bash_profile
echo 'function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }' >> /home/ubuntu/.bash_profile
echo 'function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }' >> /home/ubuntu/.bash_profile
echo 'function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }' >> /home/ubuntu/.bash_profile
echo 'function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }' >> /home/ubuntu/.bash_profile
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
# environment setting
echo 'function debug () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in "on") export EXA_DEBUG=1 ;;' >> /home/ubuntu/.bash_profile
echo ' "off") export EXA_DEBUG= ;;' >> /home/ubuntu/.bash_profile
echo ' "") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: debug on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
echo 'function strict () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in "on") export EXA_STRICT=1 ;;' >> /home/ubuntu/.bash_profile
echo ' "off") export EXA_STRICT= ;;' >> /home/ubuntu/.bash_profile
echo ' "") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: strict on|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
echo 'function colors () {' >> /home/ubuntu/.bash_profile
echo ' case "$1" in ' >> /home/ubuntu/.bash_profile
echo ' "ls")' >> /home/ubuntu/.bash_profile
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
echo ' export EXA_COLORS="" ;;' >> /home/ubuntu/.bash_profile
echo ' "hacker")' >> /home/ubuntu/.bash_profile
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
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
echo ' "off")' >> /home/ubuntu/.bash_profile
echo ' export LS_COLORS=' >> /home/ubuntu/.bash_profile
echo ' export EXA_COLORS= ;;' >> /home/ubuntu/.bash_profile
echo ' "")' >> /home/ubuntu/.bash_profile
echo ' [ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"' >> /home/ubuntu/.bash_profile
echo ' [ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;' >> /home/ubuntu/.bash_profile
echo ' *) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; }' >> /home/ubuntu/.bash_profile
# Tell bash to execute a bunch of stuff when a session starts
echo "source /vagrant/devtools/dev-bash.sh" > /home/ubuntu/.bash_profile
# Disable last login date in sshd
sed -i '/PrintLastLog yes/c\PrintLastLog no' /etc/ssh/sshd_config

56
devtools/dev-bash.sh Normal file
View File

@ -0,0 +1,56 @@
# This file gets executed when a user starts a `bash` shell, usually because
# theyve just started a new Vagrant session with `vagrant ssh`. It configures
# some (but not all) of the commands that you can use.
# Display the installed versions of tools.
# help banner
bash /vagrant/devtools/dev-versions.sh
# Configure the Cool Prompt™ (not actually trademarked).
# The Cool Prompt tells you whether youre in debug or strict mode, whether
# you have colours configured, and whether your last command failed.
function nonzero_return() { RETVAL=$?; [ $RETVAL -ne 0 ] && echo "$RETVAL "; }
function debug_mode() { [ -n "$EXA_DEBUG" ] && echo "debug "; }
function strict_mode() { [ -n "$EXA_STRICT" ] && echo "strict "; }
function lsc_mode() { [ -n "$LS_COLORS" ] && echo "lsc "; }
function exac_mode() { [ -n "$EXA_COLORS" ] && echo "exac "; }
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\] "
# The debug function lets you switch debug mode on and off.
# Turn it on if you need to see exas debugging logs.
function debug () {
case "$1" in "on") export EXA_DEBUG=1 ;;
"off") export EXA_DEBUG= ;;
"") [ -n "$EXA_DEBUG" ] && echo "debug on" || echo "debug off" ;;
*) echo "Usage: debug on|off"; return 1 ;; esac; }
# The strict function lets you switch strict mode on and off.
# Turn it on if youd like exas command-line arguments checked.
function strict () {
case "$1" in "on") export EXA_STRICT=1 ;;
"off") export EXA_STRICT= ;;
"") [ -n "$EXA_STRICT" ] && echo "strict on" || echo "strict off" ;;
*) echo "Usage: strict on|off"; return 1 ;; esac; }
# The colors function sets or unsets the LS_COLORS and EXA_COLORS
# environment variables. Theres also a hacker theme which turns everything
# green, which is usually used for checking that all colour codes work, and
# for looking cool while you phreak some mainframes or whatever.
function colors () {
case "$1" in
"ls")
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"
export EXA_COLORS="" ;;
"hacker")
export LS_COLORS="di=32:ex=32:fi=32:pi=32:so=32:bd=32:cd=32:ln=32:or=32:mi=32"
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:" ;;
"off")
export LS_COLORS=
export EXA_COLORS= ;;
"")
[ -n "$LS_COLORS" ] && echo "LS_COLORS=$LS_COLORS" || echo "ls-colors off"
[ -n "$EXA_COLORS" ] && echo "EXA_COLORS=$EXA_COLORS" || echo "exa-colors off" ;;
*) echo "Usage: ls-colors ls|hacker|off"; return 1 ;; esac; }

19
devtools/dev-help.sh Normal file
View File

@ -0,0 +1,19 @@
# This file prints out some help text that says which commands are available
# in the VM. It gets executed during Vagrant provisioning and its output gets
# dumped into /etc/motd, to print it when a user starts a new Vagrant session.
echo -e "
\033[1;33mThe exa development environment!\033[0m
exa's source is available at \033[33m/vagrant\033[0m.
Binaries get built into \033[33m/home/ubuntu/target\033[0m.
\033[4mCommands\033[0m
\033[32;1mb\033[0m or \033[32;1mbuild-exa\033[0m to run \033[1mcargo build\033[0m
\033[32;1mt\033[0m or \033[32;1mtest-exa\033[0m to run \033[1mcargo test\033[0m
\033[32;1mx\033[0m or \033[32;1mrun-xtests\033[0m to run \033[1m/vagrant/xtests/run.sh\033[0m
\033[32;1mc\033[0m or \033[32;1mcompile-exa\033[0m to run all three
\033[32;1mdebug\033[0m to toggle printing logs
\033[32;1mstrict\033[0m to toggle strict mode
\033[32;1mcolors\033[0m to toggle custom colours
"

8
devtools/dev-versions.sh Normal file
View File

@ -0,0 +1,8 @@
# Displays the installed versions of Rust and Cargo.
# This gets run from dev-bash.sh, which gets run from ~/.bash_profile, so
# the versions gets displayed after the help text for a new Vagrant session.
echo -e "\\033[4mVersions\\033[0m"
rustc --version
cargo --version
echo