In the following Makefile
_aliases is a patch script for the
/etc/mail/aliases file created and discussed in the previous post.
The file
_newaliases:
Code:
# -----------------
cat <<END
Running NEWALIASES to rebuild the aliases database ....
$(newaliases)
END
# --
The
_existing-root-mail installs or moves the existing
/var/mail/root to
/var/mail/${USER}. If done as first thing after an install, this will usually do no harm, because the user's
/var/mail file will not exist yet or will be empty.
If you don't want this , read the
install(1) man page for the correct option to create a backup of an existing
/var/mail/${USER} first.
Code:
# -------------------------------------------
USER=j65nko
echo --- move existing root email to $USER
install -o ${USER} -g ${USER} -m u=rw /var/mail/root /var/mail/${USER}
The Makefile itself:
Code:
# Makefile to divert root mail to user account
FILE = _rootmail-to-j65nko
${FILE}: _aliases _newaliases _existing-root-mail
cat ${.ALLSRC} >${.TARGET}
clean:
rm -f ${FILE}
You run the Makefile with the
make command:
Code:
$ make
cat _aliases _newaliases _existing-root-mail >_rootmail-to-j65nko
All components are concatenated to a single file. The resulting file name can be changed easily by editing the
FILE variable.
After editing one of the components run
make again to create an updated version.
A commonly encountered issue with Makefiles:
Code:
"Makefile", line 6: Need an operator
Fatal errors encountered -- cannot continue
You probably got this error by copying and pasting the Makefile instead of downloading and unpacking the attached tgz file.
The Makefile requires a tab before the commands, which (re)create the target. Here the
cat command in line 6. By pasting, you lost this tab and it was replaced by a couple of spaces.
You can diagnose this easily with:
Code:
cat -ten Makefile
1 # Makefile to divert root mail to user account$
2 $
3 FILE = _rootmail-to-j65nko$
4 $
5 ${FILE}: _aliases _newaliases _existing-root-mail$
6 cat ${.ALLSRC} >${.TARGET}$
The "operator" line 6, has no tab, a
^I, but a series of spaces.
The correct version
Code:
$ cat -ten Makefile
1 # Makefile to divert root mail to user account$
2 $
3 FILE^I= _rootmail-to-j65nko$
4 $
5 ${FILE}: _aliases _newaliases _existing-root-mail$
6 ^Icat ${.ALLSRC} >${.TARGET}$
Here line 6 has a tab character