#!/bin/sh

# copies host keys into known hosts files for lessdisks terminals

# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.

if [ -r /etc/lessdisks-install.conf ]; then
  . /etc/lessdisks-install.conf
fi 

if [ -r /etc/lessdisks/server.config ]; then
  . /etc/lessdisks/server.config
fi

if [ -z "$lessdisks_path" ]; then
  echo "lessdisks_path not set, exiting..."
  exit 2
fi

tempfile=$(tempfile)

if [ -z "$tempfile" ]; then
  echo "no tempfile set... arg!"
  exit 1
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
done

mkdir -p $lessdisks_path/root/.ssh
cd $lessdisks_path/root/.ssh
chmod og-rwx .
cp $tempfile known_hosts
exit $?
