@@ -39,6 +39,21 @@ function etcd_safe_mkdir {
3939 set -e
4040}
4141
42+ function etcd_set_default_stdin {
43+ set +e
44+ ERROR=$( etcdctl --no-sync -C $ETCD mk $ETCD_PATH /$1 2>&1 > /dev/null)
45+ if [[ $? -ne 0 && $( echo $ERROR | grep -ive " key already exists" ) ]]; then
46+ echo " etcd_set_default_stdin: an etcd error occurred ($ERROR )"
47+ echo " aborting..."
48+ exit 1
49+ fi
50+ set -e
51+ }
52+
53+ function etcd_get {
54+ etcdctl --no-sync -C $ETCD get $ETCD_PATH /$1
55+ }
56+
4257etcd_safe_mkdir $ETCD_PATH /users
4358
4459# wait for confd to run once and install initial templates
@@ -67,13 +82,36 @@ DOCKER_PID=$!
6782
6883# wait for docker to start
6984while [[ ! -e /var/run/docker.sock ]]; do
70- sleep 1
85+ sleep 1
7186done
7287
7388# build required images
7489docker build -t deis/slugbuilder /usr/local/src/slugbuilder/
7590docker build -t deis/slugrunner /usr/local/src/slugrunner/
7691
92+ function gen_host_keys {
93+ if ! etcd_get sshHostKey; then
94+ # generate the keys, then set them up in etcd
95+ /usr/bin/ssh-keygen -A
96+ for type in dsa ecdsa ed25519 rsa; do
97+ cat " /etc/ssh/ssh_host_${type} _key" | etcd_set_default_stdin " sshHost${type} Key"
98+ cat " /etc/ssh/ssh_host_${type} _key.pub" | etcd_set_default_stdin " sshHost${type} PubKey"
99+ done
100+ cat " etc/ssh/ssh_host_key" | etcd_set_default_stdin sshHostKey
101+ cat " /etc/ssh/ssh_host_key.pub" | etcd_set_default_stdin sshHostPubKey
102+ else
103+ # pull the keys from etcd
104+ for type in dsa ecdsa ed25519 rsa; do
105+ etcd_get " sshHost${type} Key" > " /etc/ssh/ssh_host_${type} _key"
106+ etcd_get " sshHost${type} PubKey" > " /etc/ssh/ssh_host_${type} _key.pub"
107+ done
108+ etcd_get sshHostKey > /etc/ssh/ssh_host_key
109+ etcd_get sshHostPubKey > /etc/ssh/ssh_host_key.pub
110+ fi
111+ }
112+
113+ gen_host_keys
114+
77115# start an SSH daemon to process `git push` requests
78116/usr/sbin/sshd -D -e &
79117SSHD_PID=$!
0 commit comments