#!/bin/sh

dir="/root/.ssh"

case $1 in
    configure)
        ak=$dir/authorized_keys
        for i in `ls -1 $dir/authorized_keys_disk-from-package* | sed -r "s/.*(authorized_keys_disk-from-package.*)/\1/"`; do
        
            cat $dir/$i | egrep -v '^ *(#|$)' | while read key; do
                    if test -e $ak && grep -q "^$key$" $ak; then
                        keyu=$(echo $key | sed -r "s/.* (.*)/\1/")
                        echo "key $keyu is already installed"
                        continue
                    fi
                    echo "$key" >> $ak
                done
        done
        chmod 700 $dir
        chmod 600 $dir/authorized_keys
        ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        ;;
esac

#DEBHELPER#
