2012-09-20 20:00:02 +02:00
|
|
|
#!/bin/bash -xe
|
|
|
|
|
|
|
|
server=$1
|
|
|
|
type=$2
|
2012-11-01 20:18:09 +01:00
|
|
|
hostname=$3
|
|
|
|
if [ -z "$hostname" ]; then
|
|
|
|
echo "USAGE: $0 server type hostname"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-07-11 02:26:04 +02:00
|
|
|
if ! $(echo "$hostname" | grep -q zulip); then
|
2012-11-01 20:18:09 +01:00
|
|
|
echo "USAGE: $0 server type hostname"
|
2013-07-11 02:26:04 +02:00
|
|
|
echo "Hostname must have zulip in it."
|
2012-09-20 20:00:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-12-13 17:29:38 +01:00
|
|
|
humbug_root=${HUMBUG_ROOT:-$HOME/humbug}
|
|
|
|
|
|
|
|
amazon_key_file=$humbug_root/humbug.pem
|
2012-12-13 17:12:49 +01:00
|
|
|
if ! [ -e "$amazon_key_file" ]; then
|
2012-12-12 17:37:46 +01:00
|
|
|
echo "You need humbug.pem at $amazon_key_file; ask tabbott for it"
|
2012-09-20 20:00:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-08 00:33:31 +01:00
|
|
|
server_private_key_file=$humbug_root/servers/puppet/modules/humbug/files/id_rsa
|
2012-12-13 17:12:49 +01:00
|
|
|
if ! [ -e "$server_private_key_file" ]; then
|
2012-12-12 17:37:46 +01:00
|
|
|
echo "You need a server ssh key at $server_private_key_file"
|
2012-09-20 20:00:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
# Force RSA keys. We do this because the ECDSA key is not printed on syslog,
|
|
|
|
# and our puppet configuration does not use ECDSA. If we don't do this,
|
|
|
|
# we'll get key errors after puppet apply.
|
|
|
|
SSH_OPTS="-o HostKeyAlgorithms=ssh-rsa"
|
2012-12-12 17:50:22 +01:00
|
|
|
|
2013-07-23 18:12:52 +02:00
|
|
|
set +e
|
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -ladmin <<EOF
|
|
|
|
sudo sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
|
|
|
sudo mkdir ~root/.ssh && sudo cp .ssh/authorized_keys ~root/.ssh/authorized_keys
|
|
|
|
sudo service ssh restart
|
|
|
|
|
|
|
|
EOF
|
2012-09-20 20:00:02 +02:00
|
|
|
|
2013-07-23 18:12:52 +02:00
|
|
|
set -e
|
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -lroot <<EOF
|
|
|
|
echo "$hostname" > /etc/hostname
|
|
|
|
sed -i 's/localhost$/localhost $hostname/' /etc/hosts
|
|
|
|
/etc/init.d/hostname.sh start
|
|
|
|
|
|
|
|
# First, install any updates from the apt repo that may be needed
|
|
|
|
cat >>/etc/apt/sources.list.d/humbug.list <<EOF2
|
|
|
|
deb http://apt.humbughq.com/ops wheezy main
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF2
|
|
|
|
apt-get update
|
2012-12-13 17:14:54 +01:00
|
|
|
apt-get -y upgrade
|
2012-09-20 20:00:02 +02:00
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
# need to get puppet before we can do anything with puppeti
|
|
|
|
apt-get install -y puppet git
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Give new server git access
|
2012-11-01 20:14:31 +01:00
|
|
|
# TODO: Don't give servers push access to our git!
|
2013-07-11 02:32:24 +02:00
|
|
|
scp $SSH_OPTS -i "$amazon_key_file" "$server_private_key_file" root@"$server":/root/.ssh/id_rsa
|
2012-09-20 20:00:02 +02:00
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -lroot <<EOF
|
2012-09-20 20:00:02 +02:00
|
|
|
chmod 600 /root/.ssh/id_rsa
|
|
|
|
# Setup initial known_hosts including git server
|
|
|
|
cat > /root/.ssh/known_hosts <<EOF2
|
|
|
|
|1|YmrT42zuHUt3kvg+MzhtF1IXakM=|Ps1MaxDiy5uTeFTjB2k8oQQyxg8= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+jhFu8Y9kSe+HyWtCmH2GqTi38lwqZzhAkyaUaASwvcvCRJWGC6AMPGVCKyNxJMcWcIcmP+mB8i5z5AhsgqwEmV5F9TrbPYjbroALCoZEon/bnCBNd3Jh/8eKZI/VLCzWQpL2FTZ5p1RYnCJ4PKSjd8PbKbGd5eAyRlbuETeyavwC+komLlekKkV+wiAv4aGuGRZeGrVJIqSRydVplQrFVaoF/1ifFS/XcNx18jFH0nw8oPOahaTzB/EUTTS/q1Cq0XgrA7x6bsr5kg4Vtw0BcP7JLob6pl/1D9FjLYsDPZCPGIfJV2uF4WcRJWg/U6OtSKOrwTmVw02TcwaavARr
|
|
|
|
|1|ccgacGoQ9gPCsFVrAopK3oGvYfU=|YcNvWUziiANLr22lvHD05N2veas= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+jhFu8Y9kSe+HyWtCmH2GqTi38lwqZzhAkyaUaASwvcvCRJWGC6AMPGVCKyNxJMcWcIcmP+mB8i5z5AhsgqwEmV5F9TrbPYjbroALCoZEon/bnCBNd3Jh/8eKZI/VLCzWQpL2FTZ5p1RYnCJ4PKSjd8PbKbGd5eAyRlbuETeyavwC+komLlekKkV+wiAv4aGuGRZeGrVJIqSRydVplQrFVaoF/1ifFS/XcNx18jFH0nw8oPOahaTzB/EUTTS/q1Cq0XgrA7x6bsr5kg4Vtw0BcP7JLob6pl/1D9FjLYsDPZCPGIfJV2uF4WcRJWg/U6OtSKOrwTmVw02TcwaavARr
|
|
|
|
EOF2
|
|
|
|
# clone humbug repository
|
|
|
|
cd /root
|
|
|
|
rm -rf /root/humbug
|
|
|
|
git clone humbug@git.humbughq.com:/srv/git/humbug.git
|
|
|
|
cd /root/humbug
|
2013-02-08 21:05:33 +01:00
|
|
|
git checkout master
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF
|
|
|
|
|
2013-07-11 02:32:24 +02:00
|
|
|
ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -lroot <<EOF
|
2013-02-08 00:33:31 +01:00
|
|
|
cp -a /root/humbug/servers/puppet/modules/humbug/files/puppet.conf /etc/puppet/
|
2013-07-11 02:32:24 +02:00
|
|
|
|
2013-05-23 23:34:54 +02:00
|
|
|
userdel admin
|
2013-02-11 18:12:51 +01:00
|
|
|
puppet apply -e 'class {"humbug": machinetype => "$type"}'
|
2013-05-23 21:06:13 +02:00
|
|
|
cp -a /root/humbug /home/humbug/humbug
|
|
|
|
chown -R humbug:humbug /home/humbug/humbug
|
2012-10-30 19:20:12 +01:00
|
|
|
# These server restarting bits should be moveable into puppet-land, ideally
|
2012-12-13 17:14:54 +01:00
|
|
|
apt-get -y upgrade
|
2012-10-30 19:20:12 +01:00
|
|
|
if [ -e "/etc/init.d/nginx" ]; then
|
|
|
|
service nginx restart
|
|
|
|
fi
|
|
|
|
if [ -e "/etc/init.d/apache2" ]; then
|
|
|
|
service apache2 restart
|
|
|
|
fi
|
2012-11-01 20:18:09 +01:00
|
|
|
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF
|
|
|
|
|
2012-11-01 20:14:31 +01:00
|
|
|
# TODO: Don't give servers push access to our git!
|
2013-07-11 02:32:24 +02:00
|
|
|
scp $SSH_OPTS -i "$amazon_key_file" "$server_private_key_file" humbug@"$server":/home/humbug/.ssh/id_rsa
|
|
|
|
ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -lhumbug <<EOF
|
2012-11-01 20:14:31 +01:00
|
|
|
chmod 600 /home/humbug/.ssh/id_rsa
|
|
|
|
EOF
|
|
|
|
|
2012-09-20 20:00:02 +02:00
|
|
|
set +x
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Done.
|
|
|
|
|
2013-04-01 20:37:53 +02:00
|
|
|
FIXME: Manually run servers/install-nodejs if necessary
|
|
|
|
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF
|