1.2 Patching '/etc/mail/aliases'manually
The OpenBSD
afterboot(8) man page lists a configuration task we will automate with a patch.
Code:
Edit /etc/mail/aliases and set the three standard aliases to go to either
a mailing list, or the system administrator.
# Well-known aliases -- these should be filled in!
root: sysadm
manager: root
dumper: root
Run newaliases(8) after changes.
We will use directory ORIG to save a copy of the original
'/etc/mail/aliases' file. The edited version will be in directory NEW.
Code:
$ mkdir WORK ; cd WORK
$ mkdir NEW ORIG
$ cp /etc/mail/aliases .
$ cp aliases ORIG
$ cp aliases NEW
$ vi NEW/aliases
After editing we create the patch with
diff
Code:
$ diff -u ORIG/aliases NEW/aliases
--- ORIG/aliases Sat Jan 23 03:00:16 2010
+++ NEW/aliases Sat Jan 23 03:03:54 2010
@@ -64,9 +64,9 @@
sshd: /dev/null
# Well-known aliases -- these should be filled in!
-# root:
-# manager:
-# dumper:
+root: j65nko
+manager: j65nko
+dumper: j65nko
# RFC 2142: NETWORK OPERATIONS MAILBOX NAMES
abuse: root
@@ -74,11 +74,11 @@
security: root
# RFC 2142: SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES
-# hostmaster: root
-# usenet: root
-# news: usenet
-# webmaster: root
-# ftp: root
+hostmaster: root
+usenet: root
+news: usenet
+webmaster: root
+ftp: root
# uncomment this for msgs:
# msgs: "|/usr/bin/msgs -s"
As you can see it is very easy to figure out the changes. The deleted lines from ORIG/aliases are prefixed with "---", the added lines in NEW/aliases with "+++".
A simple redirect will save the patch to file:
Code:
$ diff -u ORIG/aliases NEW/aliases >patch
Applying the patch is simple. We will use the following options:
Code:
-b, --backup
Save a backup copy of the file before it is modified. By default
the original file is saved with a backup extension of ".orig" un-
less the file already has a numbered backup, in which case a num-
bered backup is made. This is equivalent to specifying "-V
existing". This option is currently the default, unless --posix
is specified.
-p strip-count, --strip strip-count
Sets the pathname strip count, which controls how pathnames found
in the patch file are treated, in case you keep your files in a
different directory than the person who sent out the patch. The
strip count specifies how many slashes are to be stripped from
the front of the pathname. (Any intervening directory names also
go away.) For example, supposing the file name in the patch file
was /u/howard/src/blurfl/blurfl.c:
Setting -p0 gives the entire pathname unmodified.
Code:
$ patch -b -p0 aliases <patch
Hmm... Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- ORIG/aliases Sat Jan 23 03:00:16 2010
|+++ NEW/aliases Sat Jan 23 03:03:54 2010
--------------------------
Patching file aliases using Plan A...
Hunk #1 succeeded at 64.
Hunk #2 succeeded at 74.
done