1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
diff -ruN lessdisks-0.5.3cvs.20040906.orig/install/usr-sbin/lessdisks-keycopy lessdisks-0.5.3cvs.20040906/install/usr-sbin/lessdisks-keycopy
--- lessdisks-0.5.3cvs.20040906.orig/install/usr-sbin/lessdisks-keycopy 2004-04-30 07:05:28.000000000 -0700
+++ lessdisks-0.5.3cvs.20040906/install/usr-sbin/lessdisks-keycopy 2005-01-19 09:27:12.000000000 -0800
@@ -5,6 +5,20 @@
# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.
+# Rewrite 2005 Jonas Smedegaard <dr@jones.dk>:
+# * Preserve existing keys
+# * Quote all vars
+# * Set modes on SSH dir only if creating it
+# * Sanity checks on getting keys
+# * Inject only existing keys
+
+# Re-rewrite 2005 Vagrant Cascadian <vagrant@freegeek.org>:
+# * generate proper known_hosts file
+# * use /etc/ssh/ssh_known_hosts instead of /root/.ssh/known_hosts
+# * use $() instead of ``
+
+set -e
+
if [ -r /etc/lessdisks-install.conf ]; then
. /etc/lessdisks-install.conf
fi
@@ -18,21 +32,28 @@
exit 2
fi
-tempfile=$(tempfile)
+workdir="$lessdisks_path/etc/ssh"
+known_hosts="$workdir/ssh_known_hosts"
+thishost="$(hostname)"
-if [ -z "$tempfile" ]; then
- echo "no tempfile set... arg!"
- exit 1
+if [ ! -d "$workdir" ]; then
+ mkdir -p "$workdir"
fi
-for name in xapp disk $(hostname); do
- for type in rsa dsa; do
- echo "$name" $(cat /etc/ssh/ssh_host_$type\_key.pub) >> $tempfile
- done
+for type in rsa dsa; do
+
+ pubkey="$(cat /etc/ssh/ssh_host_${type}_key.pub | tail -n 1 | awk '{ print $1" "$2}')"
+ pubkey_type="$(echo $pubkey | awk '{print $1}')"
+ if [ -n "$pubkey" ]; then
+ # Make sure there's at least one line for perl to parse
+ echo "# dummy line" >> "$known_hosts"
+
+ for name in xapp disk $thishost; do
+ perl -ni -e "\$n++; \
+ print \"$name $pubkey\n\" if \$n==1; \
+ print && next unless /^($name\s$pubkey_type|# dummy line)/i;" "$known_hosts"
+ done
+ fi
done
-mkdir -p $lessdisks_path/root/.ssh
-cd $lessdisks_path/root/.ssh
-chmod og-rwx .
-cp $tempfile known_hosts
exit $?
|