[net.sources] Shell script to generate shell script which recreates /dev/*

fred@umcp-cs.UUCP (06/21/84)

Have you ever accidentally trashed your entire /dev directory? You
have?  Well how did you decide which devices to re-create using
mknod?  Sort of a bother looking all that up and typing in all the
commands by hand wasn't it?  Here's a shell script which makes the
whole process trivial. Just run it late at night and it'll keep
around a shell script which will do the proper sequence of mknods
chowns and chmods to recreate the directory. We use the crontab
line:

	10 4 * * * /usr/lib/make_dev > /etc/rebuild_dev

To automatically keep /etc/rebuild_dev current. If the /dev directory
gets seriously trashed, we just have to execute the script
/etc/rebuild_dev (as super-user) to restore things to a reasonable
state.

:::::::::::::::::
/usr/lib/make_dev
:::::::::::::::::
|#! /bin/sh
|#
|# @(#)make_dev.sh	(U of Maryland) FLB 10-Feb-1983
|#
|# This shell script outputs a shell script which will rebuild /dev
|#
|echo '#! /bin/sh'
|echo '#'
|echo -n '# rebuild /dev as of '
|date
|echo '#'
|#
|# Do a ``mknod'' for each device.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/mknod " $9 " " substr($1, 1, 1) " " \
|		$4 " " $5 }'
|#
|# Change user and group ownerships.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/chown " $3 " " $9; }'
|ls -lg /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/chgrp " $3 " " $9; }'
|#
|# Change file mode.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk 'BEGIN { x["r"] = 4; x["w"] = 2; x["x"] = 1 }
|		/^[bc]/ { a =   x[substr($1, 2, 1)]; \
|			a = a + x[substr($1, 3, 1)]; \
|			a = a + x[substr($1, 4, 1)]; \
|			b =     x[substr($1, 5, 1)]; \
|			b = b + x[substr($1, 6, 1)]; \
|			b = b + x[substr($1, 7, 1)]; \
|			c =     x[substr($1, 8, 1)]; \
|			c = c + x[substr($1, 9, 1)]; \
|			c = c + x[substr($1, 10, 1)]; \
|			print "/bin/chmod " a b c " " $9 }'

ggr@hudson.UUCP (Guy Riddle) (06/29/84)

Another easy way to make copies of /dev (and subdirectories) is to
use cpio.  It knows about special files and named pipes and will
happily re-create them for you.  I have used it to quickly produce
a bunch of special files needed by our local-area network software.

			=== Guy Riddle == AT&T Bell Laboratories, New Jersey ===