-
-
Save lavir/b827c94e21772f61932734f39c0821a1 to your computer and use it in GitHub Desktop.
Initialize a developer machine in DigitalOcean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# | |
size=512mb | |
remote_user=mfojtik | |
# size=32gb | |
# | |
# | |
echo "--> Waiting for 'dev' (size: $size) to be ready ..." | |
doctl compute droplet create dev \ | |
--image centos-7-2-x64 \ | |
--size $size \ | |
--region ams3 \ | |
--ssh-keys 40:2b:46:cb:d9:63:53:07:01:73:ef:0d:42:37:bc:02 \ | |
--wait >/dev/null | |
address=$(doctl compute droplet ls dev --no-header | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") | |
if [ -z "${address}" ]; then | |
echo "----> ERROR: Unable to get IP address :-(" | |
exit 1 | |
fi | |
echo "----> The dev droplet (${address}) is up ..." | |
function scp_cmd() { | |
scp -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o StrictHostKeyChecking=no $@ | |
} | |
function ssh_cmd() { | |
ssh -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o StrictHostKeyChecking=no $@ | |
} | |
echo "----> Waiting for successfull SSH connection ..." | |
connected=false | |
for i in {1..60}; do | |
connected=true | |
ssh_cmd root@${address} /usr/bin/true && break || sleep 2 | |
connected=false | |
echo "----> SSH not ready yet :-(" | |
done | |
if [ "${connected}" == "false" ]; then | |
echo "----> ERROR: Unable to connect: $(cat /tmp/dev.log)" | |
exit 1 | |
else | |
echo "----> Succesfully connected" | |
fi | |
echo "---> Installing developer tools ..." | |
ssh_cmd root@{address} /bin/bash -c "" &> /tmp/dev.log | |
cat > /tmp/install-user.sh << EOF | |
#!/bin/sh -e | |
echo "---> Installing developer tools ..." | |
yum clean all && yum update -y && yum install -y git hg mercurial gcc gcc-c++ libseccomp-devel screen vim | |
echo "---> Creating and provisioning $remote_user account ..." | |
useradd ${remote_user} && echo openshift | passwd ${remote_user} --stdin | |
mkdir -p /home/${remote_user}/.ssh | |
mkdir -p /home/${remote_user}/go/src/github.com/openshift | |
EOF | |
chmod +x /tmp/install-user.sh | |
scp_cmd -r /tmp/install-user.sh root@${address}:/root/ | |
ssh_cmd root@${address} /root/install-user.sh | |
echo "---> Copying ${remote_user} SSH keys ..." | |
scp_cmd -r $HOME/.ssh root@${address}:/home/${remote_user}/ | |
echo "---> Installing Go 1.6.1 ..." | |
cat > /tmp/install-go16.sh << EOF | |
#!/bin/sh -e | |
chown -R ${remote_user}:${remote_user} /home/${remote_user} | |
pushd /opt >/dev/null | |
wget --quiet https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz | |
tar xzf go1.6.2.linux-amd64.tar.gz | |
rm -f go1.6.2.linux-amd64.tar.gz | |
popd >/dev/null | |
EOF | |
chmod +x /tmp/install-go16.sh | |
scp_cmd -r /tmp/install-go16.sh root@${address}:/root/ | |
ssh_cmd root@${address} /root/install-go16.sh | |
echo "---> Enabling Go 1.6.1 ..." | |
cat > /tmp/enable-go16.sh << EOF | |
export GOROOT=/opt/go | |
export GOPATH=/home/${remote_user}/go | |
export PATH=\$PATH:/opt/go/bin:/home/${remote_user}/go/bin | |
export GOMAXPROCS=12 | |
export GOOS=linux | |
EOF | |
chmod +x /tmp/enable-go16.sh | |
scp_cmd /tmp/enable-go16.sh root@${address}:/etc/profile.d/ &>/dev/null | |
echo "---> Installing git config ..." | |
scp_cmd $HOME/.gitconfig ${remote_user}@${address}:.gitconfig | |
echo "---> Copying sources ..." | |
rsync -az --exclude '.git' $GOPATH/src/github.com/openshift/origin ${remote_user}@${address}:go/src/github.com/openshift | |
cat > /tmp/install-sources.sh << EOF | |
#!/bin/sh -e | |
echo "---> Initializing dev git ..." | |
pushd /home/${remote_user}/go/src/github.com/openshift/origin >/dev/null | |
git add -A | |
git commit -m "dev repo" | |
EOF | |
chmod +x /tmp/install-sources.sh | |
scp_cmd -r /tmp/install-user.sh ${remote_user}@${address}: | |
ssh_cmd ${remote_user}@${address} /home/${remote_user}/install-sources.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment