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
|
2013-07-23 18:13:18 +02:00
|
|
|
cat >/etc/apt/sources.list.d/humbug.list <<EOF2
|
2013-07-11 02:32:24 +02:00
|
|
|
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-23 18:13:18 +02:00
|
|
|
# need to get puppet before we can do anything with puppet
|
2013-07-11 02:32:24 +02:00
|
|
|
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
|
2013-07-23 18:13:18 +02:00
|
|
|
|1|ykmanuFqgkQCswGBhrVtnLLPrbc=|IaJCSR5qJVwma2uxX4VRSZnMLuU= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDjW3wKDRuah6XT5a7Xta+S2d5ew1ZPxWTbKKgp6Cun111zFw1bvLGSKS0W3HnbXOyXLbVVsAH/cSNFHMvH2nitM15zp7w2w3NV8YbLZCkdFXp5KeKHuBQ+DYL+nDCKjunlrDfxDXvD7jn/wMN995ZsnEJqnc7N8uzIgt+5lbmie5jz3Xbt/7gQdjG5E0xGL7DzzJPp8kBzfE6B1qr5pWLVKXMuGXLCcbMaco5kEjRuM8dPrtG3kGG2YsjOkoHIqwtRwztXEmjklt1FFI06JYsW43PjmdP586nOg7n28k1ibhlF968PmRRX7USI7jJ+awPd/XH4neCdNG2f8JL2kRD
|
2012-09-20 20:00:02 +02:00
|
|
|
EOF2
|
|
|
|
# clone humbug repository
|
|
|
|
cd /root
|
|
|
|
rm -rf /root/humbug
|
2013-07-24 23:24:13 +02:00
|
|
|
git clone humbug@git.zulip.net:/srv/git/humbug.git
|
2012-09-20 20:00:02 +02:00
|
|
|
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
|