#!/bin/sh
# afconfig - Semiautomatic configuration script for af with Debian.
# Copyright (c) 1996 Malc Arnold.
# 

# Identify the files
tmpfile=/tmp/afconfig.$$
afrc=/etc/af/afrc

# Check the arguments
test "$1" = "--force" && force="yes" || force="no"

# Check if we should proceed
if test -f /etc/af/afrc && test "$force" = "no"; then
  echo "Af is already configured; I'll leave the existing"
  echo "configuration untouched.  Use --force to ignore it."
  echo "The new afrc will be stored in /etc/af/afrc.dist"
  afrc=/etc/af/afrc.dist
fi

# Set up standard output to the temp file
exec > $tmpfile

# Now start writing the temp file
echo "; Automatically generated by afconfig on `date`"
echo

# Set up the mail domain
echo "; Set up the mail domain correctly"
echo "(setq domain (system \"cat /etc/mailname || hostname --fqdn\"))"
echo

# Set up how we will browse info files
test -x /usr/bin/info && info="info af" || info="typeout"
echo "; Set up the program to browse the info manual"
echo "(setq info-browser \"$info\")"
echo

# Set up the programs to handle MIME mail
test -x /usr/bin/metamail && mime="metamail" || mime=""
test -n "$mime" && mimepager="$mime -m af -p" || mimepager="nil"
test -n "$mime" && mimespooler="$mime -m af -h" || mimespooler="nil"
test -n "$mime" && mimesaver="$mime -m af -w" || mimesaver="nil"
echo "; Set up the handling of MIME mail"
echo "(setq mime-pager \"$mimepager\")"
echo "(setq mime-printer \"$mimespooler\")"
echo "(setq mime-saver \"$mimesaver\")"
echo

# Check we can print messages
test -x /usr/bin/lpr && lpr="lpr -p" || lpr="nil"
echo "; Set up printing via lpr"
echo "(setq print-command \"$lpr\")"
echo

# Set up the spell-checker
test -x /usr/bin/ispell && ispell="ispell -x" || ispell="nil"
echo "; Set up the spell-check program"
echo "(setq spell-checker \"$ispell\")"
echo

# Set up af to handle ansi keymaps if required
echo "; Set up ansi keymaps if required"
echo "(if (or (equal (getenv \"TERM\") \"linux\")"
echo "	(equal (getenv \"TERM\") \"xterm\")"
echo "	(equal (getenv \"TERM\") \"xterms\"))"
echo "    (load-library \"ansi.afl\"))"

# Now move the temp file to the right place
mv -f $tmpfile $afrc
