X-Git-Url: https://code.grnet.gr/git/snf-image/blobdiff_plain/c50358a6a55d24aee3197328a5eaa87991900486..HEAD:/snf-image-helper/tasks/40DeleteSSHKeys.in diff --git a/snf-image-helper/tasks/40DeleteSSHKeys.in b/snf-image-helper/tasks/40DeleteSSHKeys.in index 9b80630..a6dbc16 100644 --- a/snf-image-helper/tasks/40DeleteSSHKeys.in +++ b/snf-image-helper/tasks/40DeleteSSHKeys.in @@ -37,11 +37,13 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing." fi -if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then +if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then exit 0 fi -distro=$(get_base_distro "$SNF_IMAGE_TARGET") +if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then + distro=$(get_base_distro "$SNF_IMAGE_TARGET") +fi HOST_KEY="/etc/ssh/ssh_host_key" RSA_KEY="/etc/ssh/ssh_host_rsa_key" @@ -50,6 +52,13 @@ ECDSA_KEY="/etc/ssh/ssh_host_ecdsa_key" target="$SNF_IMAGE_TARGET" +if [ "x$distro" = "xdebian" ]; then + mount -o bind /proc "$target/proc" + add_cleanup umount "$target/proc" + mount -o bind /dev "$target/dev" + add_cleanup umount "$target/dev" +fi + #Remove the default keys for pair in "$HOST_KEY@rsa1" "$RSA_KEY@rsa" "$DSA_KEY@dsa" "$ECDSA_KEY@ecdsa"; do key=$(echo $pair | cut -d@ -f1) @@ -72,24 +81,24 @@ if [ ! -e "$config" ]; then fi # Remove non-default keys... -grep ^HostKey "$config" || true | while read key_line; do +{ grep ^HostKey "$config" || true; } | while read key_line; do key=$(echo $key_line | cut -d" " -f2) if [ "$key" = $HOST_KEY -o "$key" = $RSA_KEY -o \ "$key" = $DSA_KEY -o "$key" = $ECDSA_KEY ]; then - continue; + continue fi if [ "x$distro" = "xdebian" ]; then # Most distros recreate missing keys...debian complains type="" if [ -e "$target/$key" ]; then - if grep -e "-----BEGIN DSA PRIVATE KEY-----" "$target/$key"; then + if grep -e "-----BEGIN DSA PRIVATE KEY-----" "$target/$key" > /dev/null; then type=dsa - elif grep -e "-----BEGIN EC PRIVATE KEY-----" "$target/$key"; then + elif grep -e "-----BEGIN EC PRIVATE KEY-----" "$target/$key" > /dev/null; then type=ecdsa - elif grep -e "-----BEGIN RSA PRIVATE KEY-----" "$target/$key"; then + elif grep -e "-----BEGIN RSA PRIVATE KEY-----" "$target/$key" > /dev/null; then type=rsa - elif grep -e "SSH PRIVATE KEY FILE FORMAT" "$target/$key"; then + elif grep -e "SSH PRIVATE KEY FILE FORMAT" "$target/$key" > /dev/null; then type=rsa1 fi else # do some guessing...