Bash + Git

A tale in two parts today. Quick bash admin and git woes.

Bash Admin

Today I was faced with a real sysadmin task. I had 32 nodes I needed to configure all with just a bare bones Ubuntu install. Typically I fallback on ansible as my provisioning and configuration tool of choice. Unfortunately the machines did not even have python installed so we couldn’t jump right there.

To make matters worse, the single user on the machine was not configured with an ssh key, so password based authentication was all that was available. Here is what I came up with:

for i in $(seq $2 $3); do
  echo "--------- START ---------"
  echo "copy $1 to remote machine: .$i"
  sshpass -e scp $1 user@10.10.10.$i:~/auto.sh
  echo "run remote script with sudo"
  sshpass -e ssh user@10.10.10.$i <<EOF
echo "${SSHPASS}" | sudo -S /home/user/auto.sh
EOF
  echo "clean up remote script"
  sshpass -e ssh user@10.10.10.$i "rm auto.sh"
  echo "---------  END  ---------"
done

Essentially a script to iterate over a range of hosts, that will upload a script (using sshpass to do password based authentication), and then run the script with sudo. The here documents bit was particularly new to me. As was sudo -S. In the end I was able to easily run arbitrary scripts on the machines to perform a minimal bootstraping. Automation win.

I’d be happy to hear how anyone else might have solved this problem. For what it’s worth I also learned about the -s flag for bash with stdin redirection:

ssh server@server "bash -s" < local.sh

Git Submodules Fail

Ran into another frustrating corner case with git submodules today. Based on my GitHub pages setup from yesterday. We had someone attempt to use the repo without the submodules checked out. This I anticipated and had documented to use:

git submodule init
git submodule update --recursive

Unfortunately, they did not have access to one of the repositories (the deployment one). This clone processed to fail and put everything in a really odd state. And in particular was preventing them from checking out the theme submodule (which they should have been able to).

Eventual fix was to just check out the single submodule (didn’t know that was a thing), and then all was well.

git submodule update --init website/themes/beautifulhugo/

I also learned about git submodule deinit.

In the future whenever possible I plan to avoid submodules. The fix for this specific project is to just directly commit the theme to the repo. Always more to learn.

Fin.