caplib.ksh revision aa3884f6c65ad5f3bc3816b4ef62749ba985b897
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#!/bin/ksh
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# CDDL HEADER START
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# The contents of this file are subject to the terms of the
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Common Development and Distribution License, Version 1.0 only
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# (the "License"). You may not use this file except in compliance
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# with the License.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# or http://www.opensolaris.org/os/licensing.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# See the License for the specific language governing permissions
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# and limitations under the License.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# When distributing Covered Code, include this CDDL HEADER in each
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# If applicable, add the following below this CDDL HEADER, with the
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# fields enclosed by brackets "[]" replaced with your own identifying
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# information: Portions Copyright [yyyy] [name of copyright owner]
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# CDDL HEADER END
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# ident "%Z%%M% %I% %E% SMI"
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
aa3884f6c65ad5f3bc3816b4ef62749ba985b897ck# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Use is subject to license terms.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# This script is called by flarcreate.sh
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Unmount all hwcap libraries (like /usr/lib/libc/libc_hwcap2.so.1)
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# and store commands needed to remount them in preexit/remount_hwcap.xxxx
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# scripts, which remounts them in the preexit phase.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
aa3884f6c65ad5f3bc3816b4ef62749ba985b897ckif [ -z "$FLASH_PID" ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo "$0: ERROR: FLASH_PID not set in execution environment, exiting..."
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 1
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskCHMOD=/usr/bin/chmod
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskELFDUMP=/usr/ccs/bin/elfdump
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskMOUNT=/usr/sbin/mount
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskUMOUNT=/usr/sbin/umount
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskEGREP=/usr/bin/egrep
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskSED=/usr/bin/sed
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskCMD_LIST="$CHMOD $ELFDUMP $MOUNT $UMOUNT $EGREP $SED"
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfor cmd in $CMD_LIST
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskdo
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk if [ ! -x $cmd ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo "$0: ERROR: $cmd not found or not executable, exiting..."
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 1
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk fi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskdone
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Fill "LIBS" with a list of mounted libraries in the form:
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# MOUNTPOUNT:FILE
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# e.g.:
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# /lib/libc.so.1:/usr/lib/libc/libc_hwcap2.so.1
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskLIBS=`$MOUNT | $EGREP "^/lib|^/usr/lib" | \
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk $SED -e 's:^\(/[^ ]*\) on \([^ ]*\).*$:\1@\2:'`
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
aa3884f6c65ad5f3bc3816b4ef62749ba985b897ckif [ ! "$LIBS" ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 0
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskREMOUNT_DIR=/etc/flash/preexit
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskREMOUNT=${REMOUNT_DIR}/remount_hwcap.${FLASH_PID}
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Create the flash preexit script directory for the remount scripts if it
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# doesn't already exist.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskif [ ! -d $REMOUNT_DIR ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk umask 077
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk /usr/bin/mkdir $REMOUNT_DIR
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk if [ $? -ne 0 ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo "$0: ERROR: could not mkdir $REMOUNT_DIR, exiting..."
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 1
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk fi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# If an old remount script by this name exists, delete it
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskif [ -f $REMOUNT ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk /bin/rm -f $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskumask 477
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskcat > $REMOUNT << EOF
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#!/bin/sh
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskif [ \"\$FLASH_PID\" != \"$FLASH_PID\" ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk /bin/rm -f $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 0
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskEOF
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskif [ $? -ne 0 ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo "$0: ERROR: could not create $REMOUNT, exiting..."
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk exit 1
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Now process each of the libraries that are mounted. For each, find out if
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# it's a hwcap library; if it is, unmount it and write instructions to the
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# preexit script as to how to remount it.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskfor entry in $LIBS
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskdo
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo $entry | IFS=@ read MOUNTPOINT MOUNTLIB
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk CAPLIB=`$ELFDUMP -H $MOUNTLIB`
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk if [ \( $? -eq 0 \) -a \( -n "$CAPLIB" \) ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk $UMOUNT $MOUNTPOINT || $UMOUNT -f $MOUNTPOINT || \
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk { echo "$0: ERROR: Could not unmount" \
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk "$MOUNTPOINT, exiting..."; \
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk /bin/sh $REMOUNT; /bin/rm -f $REMOUNT; exit 1; }
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo $MOUNTLIB | $EGREP -s :
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk if [ $? -eq 0 ]; then
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk MOUNTOPTS="-O"
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk else
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk MOUNTOPTS="-O -F lofs"
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk fi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk echo "$MOUNT $MOUNTOPTS $MOUNTLIB $MOUNTPOINT" >> $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk fi
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskdone
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# Write final cleanup instructions to the flash preexit remount script and make
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk# it executable.
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk#
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskecho "/bin/rm -f $REMOUNT" >> $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskecho "exit 0" >> $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharsk$CHMOD 0500 $REMOUNT
a7123019ed2e4decef929dc2e426f3f310788fa1kucharskexit 0