#!/bin/bash

UNPACKDIR="$HOME"

tar --extract --gzip --file stdaccount.tar.gz --directory $UNPACKDIR --verbose

cd $UNPACKDIR

function rmmd5 {
  FILENAME="$1"
  shift
  MD5s="$@"
  if [ -f "$FILENAME" ]; then
    for md5 in $MD5s; do
      if [ "$md5" = "$(md5sum "$FILENAME" | cut -d\  -f 1)" ]; then
        rm "$FILENAME"
	break
      fi
    done
    if [ -f "$FILENAME" ]; then
      echo "not rmming $FILENAME, md5sum differs"
    fi
  fi
}

function rmfile {
  FILENAME="$1"
  if [ -f "$FILENAME" ] || [ -h "$FILENAME" ]; then
    rm -rf "$FILENAME"
  fi
  if [ -e "$FILENAME" ]; then
    echo >&2 "WARN: $FILENAME neither plain file nor symlink"
    ls >&2 -ald $FILENAME
  fi
}

rmfile .ssh/.dont-make-authorized_keys
rmfile .ssh/.dont-make-config

if ! [ -e ".ssh/authorized_keys.conf" ]; then
  echo 'AKC_CLASSES="dist/mh-home dist/mh-private"' > .ssh/authorized_keys.conf
fi

rmfile stdaccount.tar.gz
rmfile stdaccount.tar.bz2
rmmd5 .ssh/authorized_keys.all 0ecc80248fd5550800a0552f31baa6cf
rmmd5 .ssh/authorized_keys.dist 05790ddb8e07eeb4554a2d6520ab0ddc
rmmd5 .ssh/authorized_keys.local d03f0a58248c6fb22e5ad3fb67ab9deb
rmmd5 .ssh/config.dist.foot a39de14e94eeccdac2d06315539b66b2
rmmd5 .ssh/config.dist.head 52ef4197a1b0c75d560aa7ca7f6631fc
rmmd5 .ssh/config.dist.hosts 6b0eb5db01d96faf8d59688af5c0fd60
rmmd5 .ssh/config.foot 21a8f9e18261b2403a08c6d9b046c2ca a39de14e94eeccdac2d06315539b66b2
rmmd5 .ssh/config.head 51e1ebb8d7edb86170c7c97bd5489df2 52ef4197a1b0c75d560aa7ca7f6631fc
rmfile .my/bin/staroffice
rmfile .my/bin/vmware
rmfile .my/bin/cdwrite
rmfile .my/bin/mkisofs
rmmd5 .my/bin/sshaddidentities f17cd3b243e36419be6d732235c3bfc5
rmmd5 .my/bin/scys123_1024 b0031eafdb44534afa9d2dde9cffaecc
rmmd5 .my/bin/scys123_900 b0031eafdb44534afa9d2dde9cffaecc
rmmd5 .my/bin/checkmail 8af718482df002b6418730947bb5550a
rmmd5 .my/bin/cleanlogs 5fc98f217694d2f5c6c7b335cfd559c0
rmmd5 .my/bin/apt-select 5e32738e26e83da5363ef15655bdf1ec
rmmd5 .my/bin/aptbuilddep 7f1cd43f9f189c46c8aa9384fd7a0156
rmmd5 .my/bin/coracvs 4b9c812fa57891755fd612f859347706
rmmd5 .my/bin/extract-kernel-config c887ea0e57d0c982ec7d9a6114e942ab
rmmd5 .my/bin/getarticle ad7b5c0e8815816a94252fd402751e65
rmmd5 .my/bin/install_stdaccount 723b981abca2101c9aa39ea7550d0262
rmmd5 .my/bin/mhnetscape ee7cece58466bd9548164886fe8b9023
rmmd5 .my/bin/newscommand 1b859deb57a577b7693136eb2be35b40
rmmd5 .my/bin/pw 73c1af1ac8dde2ee0da424319ed81882
rmmd5 .my/bin/sendhttprequest 5ee9ee886aeeff57c7e5065a16a9da08
rmmd5 .my/bin/sumoverview 9924616a63084e93c9f145ad3bb0a09e
rmmd5 .my/bin/tarchroot ae6fe27a01438099efb8c6f9aac4105c
rmmd5 .my/bin/zap a777674c10c008f30164dc261318424e
rmmd5 .my/bin/smtpauthpasswd e638336fa20c4d564aa03806a59b8094
$SHELL --login
rmfile $0
