#!/bin/sh

try_again () {
    echo -n "Try again? (y/n) "
    read input
    if ! expr "$input" : "y" > /dev/null 2>&2; then
      echo "Aborting."
      exit 1
    fi;
}

echo "Insert a blank floppy disk into your (first) floppy drive, and"
echo -n "press Enter when ready: "

read input

while :; do
    mformat a:
    if [ $? -ne 0 ]; then
        echo "Formatting failed.  Are you sure there is a disk in the drive?"
        echo "If so, this disk may be damaged and you may need to try another"
        echo "one."
        try_again
    else
        break
    fi
done

while :; do
    logfiles="$DMESGLOG $IDENTLOG $LOGFILE $SYSLOG"
    if [ -z "$logfiles" ]; then
        echo "No logfiles defined!"
        exit 2
    fi
    file_list=
    for file in $logfiles; do
        if [ -e $file ]; then
            file_list="$file_list $file"
        else
            echo "Note: logfile $file not found on system."
        fi
    done
    # more than a meg of logfiles?
    if [ $(cat $file_list | wc -c) -gt 1048576 ]; then
        new_file_list=
        for file in $file_list; do
            gzip -9c $file > $file.gz
            new_file_list="$new_file_list $file.gz"
        done
        file_list=$new_file_list
    fi
    mcopy $file_list a:
    if [ $? -ne 0 ]; then
        echo "Copying logfiles failed."
        try_again
    else
        break
    fi
done

# vim:ai:et:sts=4:sw=4:tw=0:
