From 2aff1560a39df62ae4f0abda84a8fff12c353caa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sat, 30 Jan 2016 13:39:55 +0100 Subject: [PATCH] Fetching machine ssh keys. --- docker.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/docker.sh b/docker.sh index b5df1eb..a325428 100755 --- a/docker.sh +++ b/docker.sh @@ -27,13 +27,16 @@ # # docker network create -d overlay ics.muni.cz # +# 5) access to kdccesnet.ics.muni.cz, +# or directory config/$HOSTNAME/ssh, +# or disable FETCH_SSH_KEYS +# DOCKER_network='ics.muni.cz' #DOCKER_network='bridge' - +FETCH_SSH_KEYS=${FETCH_SSH_KEYS:-'1'} IMAGE='valtri/hadoop-debian7' - # get the first free network device devname() { i=1 @@ -48,7 +51,7 @@ devname() { if [ -z "${1}" ]; then echo "Usage:" echo - echo "$0 cfg_hostname.sh [init] []" + echo "$0 cfg_hostname.sh []" exit 1 fi . ./$1 || exit 1 @@ -65,12 +68,27 @@ if [ -n "${SIZE_MEM}" ]; then fi # ==== init ==== +confid_dir="`dirname $0`/config" +config_dir="`cd ${config_dir}; pwd`" if [ ! -f ~/.ssh/id_rsa_docker ]; then ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa_docker cp -p ~/.ssh/id_rsa_docker.pub ~/.ssh/authorized_keys_docker - if [ -f `dirname $0`/config/authorized_keys ]; then - cat `dirname $0`/config/authorized_keys >> ~/.ssh/authorized_keys_docker + if [ -f ${config_dir}/authorized_keys ]; then + cat ${config_dir}/config/authorized_keys >> ~/.ssh/authorized_keys_docker + fi +fi +if [ -n "${FETCH_SSH_KEYS}" ]; then + if [ ! -d ${config_dir}/${FACTER_hostname} ]; then + mkdir -p ${config_dir}/${FACTER_hostname}/ssh + cp -p /etc/ssh/ssh*_config ${config_dir}/${FACTER_hostname}/ssh/ + for j in '' '.pub'; do + for i in rsa dsa ecdsa; do + (umask 0177; rsh -5 -f -u -x -p 5665 kdccesnet.ics.muni.cz /usr/local/bin/rsh.getsshhostkey ${FACTER_fqdn} ssh_host_${i}_key${j} > ${config_dir}/${FACTER_hostname}/ssh/ssh_host_${i}_key${j}) + done + done + chmod 0644 ${config_dir}/${FACTER_hostname}/ssh/*.pub fi + ARGS="${ARGS} -v ${config_dir}/${FACTER_hostname}/ssh:/etc/ssh" fi for m in ${MOUNTS}; do loc_dir=`echo ${m} | cut -d: -f1` -- 1.8.2.3