install-log... done!

Andy Goth unununium at openverse.org
Mon Jan 15 18:39:12 PST 2001


So I haven't written a hint surrounding it yet, but before I do that I
want to submit this script for your approval.  It's 3736 bytes, which
is (1) fairly small and (2) waaaaay too big for what it does.

If you like it, could you please upload it in some utilities directory
on the LFS site so I can give a URL in my hint rather than having to
wrap it in a large cat << "ENDOFFILE" construct?  And if you do upload
it, do I have permission to announce it on freshmeat?

I've tested it and haven't found any bugs... yet.  Keep in mind that
this is merely version 0. :^)  Maybe the --pre-chroot mode doesn't work
yet... I haven't had a chance to use that option yet.
-- 
Andy Goth  |  unununium at openverse.org  |  uin: 35256413  |  aim: Un111
-------------- next part --------------
#!/bin/sh

# install-log
# By Andy Goth <unununium at openverse.org>,
# with thanks to Gerard Beekmans <gerard at linuxfromscratch.org>
# For LFS <linuxfromscratch.org>

VERSION="0"
DATE="January 15, 2001"

# Luser enlightenment function
function syntax() {
	cat << EOF
install-log, version ${VERSION}, ${DATE}
Usage: ${0} [options]
Options:  (either --before or --after must be specified)
   --before                    Initialize filesystem inventory
   --after <package>           Use after installing <package>
      --force                  Overwrite existing package installation log
      --edit                   Edit log with vi
   --quiet                     Do not output messages (except errors)
   --pre-chroot                Treat ${LFS} as root (/) of filesystem
   --help                      This truck
Configuration variables:  (/etc/install-log.rc is sourced prior to execution)
   EXCLUDE="/dev:/proc"        List of directories not to scan
   LOGDIR="/var/install-logs"  Directory in which to keep logs
   EDITOR="/usr/bin/vi"        Program to use with --edit
   FORCE="yes"                 Always force
   EDIT="yes"                  Always edit
   QUIET="yes"                 Always shush
   PRE_CHROOT="yes"            Always fake a chroot
EOF
	exit 1
}

# File already exists warning
function file_warn() {
	echo "Log file already exists!  Use --force to override."
	exit 2
}

# No $LFS warning
function lfs_warn() {
	echo "LFS not set!  Type 'export LFS=\"/lfs/root/dir\"' to fix."
	exit 3
}

# No .before-inst warning
function beforeinst_warn() {
	echo "No ${LOGDIR}/.before-inst file!  Run '${0} --before' to fix."
	exit 4
}

# Other error
function die() {
	echo "Failed!"
	exit 127
}

# Set defaults and grab configuration
EXCLUDE="/usr/src:/usr/local/src:/opt/src:/proc:/dev:/mnt:/home:/root:/tmp"
LOGDIR="/var/install-logs"
EDITOR="vi"
[ -r "/etc/install-log.rc" ] && source "/etc/install-log.rc"

# Turn exclusion list into a (crazy) regular expression
EX_REGEXP=$(echo ${EXCLUDE} | 
		sed 's/^/\\\(\^\./;s/$/\$\\\)/;s/\:/\$\\\)\\\|\\\(\^\./g')

# Parse options
ROOT="/"
while [ "${1}" ]
do
	case "${1}" in
	--before)
		[ "${MODE}" ] && syntax
		MODE="before"
		;;
	--after)
		[ "${MODE}" ] && syntax
		MODE="after"
		shift
		[ "${1}" ] || syntax
		PACKAGE="${1}"
		;;
	--force)
		FORCE="yes"
		;;
	--edit)
		EDIT="yes"
		;;
	--quiet)
		QUIET="yes"
		;;
	--pre-chroot)
		[ "${LFS}" ] || lfs_warn
		PRE_CHROOT="yes"
		ROOT="${LFS}"
		LOGDIR="${LFS}/${LOGDIR}"
		# Source chrooted install-log.rc
		[ -r "${LFS}/etc/install-log.rc" ] &&
				source "${LFS}/etc/install-log.rc"
		;;
	*)
		syntax
		;;
	esac
	shift
done

[ "${MODE}" ] || syntax

case "${MODE}" in
before)
	# Build a list of the contents of the filesystem
	[ "${QUIET}" ] || echo -n "Doing initial filesystem scan... "
	cd "${ROOT}"
	find . -regex ${EX_REGEXP} -prune -o -print | sed 's/\.\//\//' > \
			"${LOGDIR}/.before-inst" || die
	[ "${QUIET}" ] || echo "done."
	;;
after)
	[ -f "${LOGDIR}/.before-inst" ] || beforeinst_warn
	[ -f "${LOGDIR}/${PACKAGE}" ] && [ ! "${FORCE}" ] && file_warn

	# Compare .before-inst and the current filesystem contents and list
	# all the new files in ${LOGFILE}
	[ "${QUIET}" ] || echo -n "Scanning filesystem for differences... "
	cd "${ROOT}"
	find . -regex ${EX_REGEXP} -prune -o -print | \
			sed 's/\.\//\//' | diff "${LOGDIR}/.before-inst" - | \
			sed 's/> //' | grep "/" > "${LOGDIR}/${PACKAGE}" || die
	[ "${QUIET}" ] || echo "done."
	[ "${QUIET}" ] || echo "Log written to ${LOGDIR}/${PACKAGE}"
	
	# Rebuild .before-inst
	if [ "${PRE_CHROOT}" ]
	then
		${0} "--before --pre-chroot"
	else
		${0} "--before"
	fi

	# Maybe edit the resulting log file
	[ "${EDIT}" ] && (${EDITOR} "${LOGDIR}/${PACKAGE}" || die)
	;;
*)
	# What the hell...?
	echo "Internal error"
	exit 255
	;;
esac


More information about the blfs-support mailing list