install-aws-server: Improve handling of various corner cases.

This script is pretty far from being polished, but it is useful, so we
might as well make it a bit more robust.
This commit is contained in:
Tim Abbott 2017-10-05 21:57:18 -07:00
parent f2055397c1
commit d9c26c307c
1 changed files with 18 additions and 8 deletions

View File

@ -52,7 +52,7 @@ if [ -z "$branch" ]; then
branch=$(crudini --get "$zulip_ssh_config_file" repo default_branch)
fi
VIRTUALENV_NEEDED=$(if $(echo "$type" | grep -q ::app); then echo -n yes; else echo -n no; fi)
VIRTUALENV_NEEDED=$(if $(echo "$type" | grep -q app_frontend); then echo -n yes; else echo -n no; fi)
# 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,
@ -64,7 +64,13 @@ set +e
ssh "${SSH_OPTS[@]}" "$server" -t -i "$amazon_key_file" -lubuntu -o "ControlMaster=no" <<EOF
sudo mkdir -p ~root/.ssh && sudo cp .ssh/authorized_keys /root/.ssh/authorized_keys
sudo sed -i 's/disable_root: true/disable_root: false/' /etc/cloud/cloud.cfg
mkdir -p /etc/zulip
sudo mkdir -p /etc/zulip
EOF
ssh "${SSH_OPTS[@]}" "$server" -t -i "$amazon_key_file" -lroot <<EOF
# Set the hostname early
echo "$hostname" > /etc/hostname
hostname "$hostname"
sed -i 's/localhost$/localhost $hostname/' /etc/hosts
EOF
set -e
@ -78,25 +84,29 @@ if [ -e "$zulipconf_file" ]; then
fi
ssh "${SSH_OPTS[@]}" "$server" -t -i "$amazon_key_file" -lroot <<EOF
set -x
# Finish setting up the SSH private key
chmod 600 /root/.ssh/id_rsa
# Delete the ubuntu user
userdel ubuntu
if grep -q '^ubuntu:' /etc/passwd; then
userdel ubuntu
fi
# Make sure root doesn't have a password
passwd -d root
# Set the hostname
echo "$hostname" > /etc/hostname
sed -i 's/localhost$/localhost $hostname/' /etc/hosts
apt-get update
apt-get -y upgrade
cd "$(mktemp -d)"
# Get GitHub known_hosts setup
# TODO: Replace this with hardcoding the actual GitHub keys
ssh -oStrictHostKeyChecking=no git@github.com </dev/null >/dev/null || true
if ! [ -e "zulip" ]; then
# need to install git to clone the repo
apt-get install -y git crudini
git clone $zulip_repo
git clone "$zulip_repo" zulip
fi
cd zulip
git fetch