#!/bin/bash # THIS BOOTSTRAP SCRIPT IS PROVIDED WITHOUT WARRANTY! # Don't come crying to Warf if this script eats your desktop # Download and execute remote script if supplied hash matches # $1 == sha1 hash # $2 == script name bootstrap() { echo "### INFO: Starting bootstrap of script: $2" local build=$(mktemp -d -p /var/tmp) mkdir -p $build pushd $build 2>&1 > /dev/null echo "### INFO: Preparing to download script: $2" | tee -a $HOME/bootstrap.log curl -so $2 https://${BOOTSTRAP}${BOOTPATH// /\/}$2 local ret=$? if [[ $ret == 0 ]]; then echo "### INFO: Checking SHA1 checksum for script: $2" | tee -a $HOME/bootstrap.log local sha1=$(sha1sum $2 | awk '{print $1}') if [[ "$sha1" == "$1" ]]; then echo "### INFO: Executing script: $2" | tee -a $HOME/bootstrap.log chmod +x $2 && /bin/bash -c ./$2 | tee -a $HOME/bootstrap.log else echo "### ERROR: SHA1 checksum does not match for script: $2 (expected: '$1', actual: '${sha1}'), skipping" | tee -a $HOME/bootstrap.log fi else echo "### ERROR: Could not download script: $2" | tee -a $HOME/bootstrap.log fi popd rm -rf $build echo "### INFO: Finished bootstrap of script: $2" | tee -a $HOME/bootstrap.log } export BOOTSTRAP=boot.warf.ca export BOOTPATH=/$(hostname | awk -F\. '{for (i=NF; i>0; i--) printf("%s ",$i);print ""}') export -f bootstrap /bin/bash <(curl -s https://${BOOTSTRAP}${BOOTPATH// /\/}__init__.sh) # EOF