Skip to content

Instantly share code, notes, and snippets.

@nopdotcom
Last active September 15, 2017 19:52
Show Gist options
  • Save nopdotcom/9fe8b3d3c85b550e47c1f5efba4729e5 to your computer and use it in GitHub Desktop.
Save nopdotcom/9fe8b3d3c85b550e47c1f5efba4729e5 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# This script takes a while to run. The file "ready" is created when finished.
# If you're logged in early, you can watch progress with the command
#
# tail -f /var/log/cloud-init-output.log
#
set -e
set -x
if [ "$(id -u)" != 0 ]; then
echo "This script must be run as root."
exit 1
fi
quiet () { "$@" >/dev/null 2>&1 ; }
become () { sudo -i -u "$default_user" "$@" ; }
# We need the user that people will use to log into the
# instance. Sometimes that's root, sometimes it's ubuntu, and
# sometimes it's your favorite username (see Google Cloud Shell).
if [ "$SUDO_USER" ]; then
default_user="$SUDO_USER"
elif quiet id 1001; then
# We're on a GCE instance with an ubuntu user at uid 1000, but we log in as 1001.
default_user="$(id -un 1001)"
elif quiet id 999; then
# This shows up in LiveCDs as the ubuntu/xubuntu/lubuntu user.
default_user="$(id -un 999)"
elif quiet id 1000; then
# Aha, this is what we expected.
default_user="$(id -un 1000)"
elif quiet id ubuntu; then
# If "ubuntu" is elsewhere, use that.
default_user="$(id -un ubuntu)"
elif ! quiet id ubuntu; then
# Some systems don't have an ubuntu user; make an alias for root.
useradd --non-unique --uid 0 --gid 0 --home-dir /root -s /bin/bash ubuntu
default_user=ubuntu
become () { "$@" ; }
fi
cd "$(become pwd)"
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
apt-get update
apt-get --yes upgrade
apt-get --yes install python-pip git build-essential python-dev python-setuptools
# We only really wanted python-pip for its dependencies.
pip install --upgrade pip
# The pip we want should be in /usr/local now. Don't fail if it didn't install right.
hash -r
pip install boto msrest msrestazure azure==2.0.0rc5 dopy==0.3.5 "apache-libcloud>=1.5.0" linode-python pyrax
pip install ansible
become git clone https://github.com/jlund/streisand.git
become mkdir -p .ssh
become bash -c "ssh-keygen -f .ssh/id_rsa -N ''"
become touch ready
wall "Streisand is ready."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment