Skip to content

Instantly share code, notes, and snippets.

@benkant
Created December 21, 2017 08:49
Show Gist options
  • Save benkant/8400c1d3c2eed3a41bc190e77d4392e5 to your computer and use it in GitHub Desktop.
Save benkant/8400c1d3c2eed3a41bc190e77d4392e5 to your computer and use it in GitHub Desktop.
Google Cloud Shell init
#!/usr/bin/env bash
shopt -s expand_aliases
export EDITOR=vim
export VISUAL=vim
mkdir -p $HOME/log # TODO: GCP logging shit
STARTTIME=`date --iso-8601=minutes --utc`
export LOGFILE=$HOME/log/gcsinit-${STARTTIME}.log
vi() {
vim "$@"
}
logit() {
echo -e "\n\t${1}\n" >>$LOGFILE 2>&1
}
# quote Ghost Rider
quotegr() {
echo "\033[0m\t\t\033[1m${1}\033[0m\n"
}
# quote others
quote() {
echo "\033[0m\t\t\033[2m${1}\033[0m\n"
}
talktomegoose() {
echo -e "\n\t\033[1m\033[4mFighter Weapons School\033[0m\n"
echo -e "\t\t\033[4mmiramar\033[0m: start or connect to datalab\033[0m\n"
echo -e "\t\t\033[4mdisengage\033[0m: stop the datalab instance\033[0m\n"
echo -e "\t\t\033[4mhemlock\033[0m: terminate the datalab instance\033[0m\n"
echo -e "\t\t\033[4mtalktomegoose\033[0m: print these directives\033[0m\n"
}
miramar() {
local ghostrider=``
#if gcloud compute instances describe topgun --zone asia-east1-a --format="value(status)"| grep ERROR;
if gcloud compute instances describe topgun --zone asia-east1-a;
then
echo -e $(quotegr "I feel the need... The need for speed.\n--")
datalab connect topgun
else
echo -e $(quotegr "Come on Mav, do some of that pilot shit!\n--")
datalab beta create-gpu --log-level warn --idle-timeout 90m --verbosity warning --accelerator-type nvidia-tesla-k80 --accelerator-count 1 --zone asia-east1-a --disk-size-gb 250 topgun
fi
}
disengage() {
echo -e $(quotegr "Talk to me, Goose.\n\t\t--")
datalab stop --quiet topgun
}
hemlock() {
echo -e $(quotegr "I'll fire when I'm goddamn good and ready. You got that?\n\t\t--")
datalab delete --quiet --keep-disk topgun
}
logit "You two characters... are going to Top Gun."
# TODO: import this from somewhere
gcloud config set component_manager/disable_update_check false >>$LOGFILE 2>&1
gcloud config set compute/zone asia-east1-a >>$LOGFILE 2>&1
gcloud config set compute/region asia-east1 >>$LOGFILE 2>&1
testing_install() {
sudo apt-get -y -t testing --install-suggests install python3.6 >>$LOGFILE 2>&1
sudo apt-get -y -t testing vim pv >>$LOGFILE 2>&1
}
stable_install() {
sudo apt-get -y install software-properties-common >>$LOGFILE 2>&1
}
#contains() {
# string="$1"
# substring="$2"
# if test "${string#*$substring}" != "$string"
# then
# return 0 # substring not in string
# else
# return 1 # substring in string
# fi
#}
#
#installed() {
# for package in "${1[@]}"
# do
# if [ ! contains `apt list --installed ${package}` $package ] ;
# return 0
# else
# return 1
#}
#
#testing_requires=(python3.6 vim pv)
#stable_requires=(software-properties-common)
#
# perhaps this is a new instance
# if so we have work work to
# TODO: crude
if [ -x "$(command -v python3.6)" ] ; then
echo -e $(quote "\nMaverick, you're at 3/4 of a mile. Call the ball.")
echo -e $(quotegr "Roger. Maverick has the ball.\n\t\t--")
else
echo -e $(quote "Ghost Rider this is Strike. We have unknown aircraft. Inbound Mustang. Your vector 090 for bogey.")
echo -e $(quotegr "Talk to me, Goose.")
echo -e $(quotegr "Roger I got them. 900 knots closure.\n\t\t--")
### keep on stable unless no package exists
sudo cp ~/mono/util/gcsmore.list /etc/apt/sources.list.d/ && \
sudo cp ~/mono/util/00gcsapt.pref /etc/apt/preferences.d/ && \
stable_install
sudo apt-get update >>$LOGFILE 2>&1
### and you asshole, you're lucky to be here
testing_install
# TODO: too slow
# TODO: should install not-installed not specific packaged
# sudo gcloud --quiet install cbt bigtable emulator-reverse-proxy container-builder-local
### rare but sometimes this is required
# TODO: why doesn't a new instance have the latest SDK?
sudo gcloud --quiet components update >>$LOGFILE 2>&1
### CLEANUP
# TODO: appears unecessary
#sudo apt-get -y install -f
# TODO: this removed python3.6 suggested?!
#sudo apt-get -y autoremove
# TODO: catpng
echo -e $(quotegr "I-I'm sorry, I hate it when it does that, I'm sorry. Excuse me.\n\t\t--")
fi
ENDTIME=`date --iso-8601=minutes --utc`
logit "${0} done at ${ENDTIME}"
talktomegoose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment