#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright 2012 Nexenta Systems, Inc. All rights reserved.
# both ufs and hsfs (iso9660) format archives are unpacked
# only ufs archives are generated
#
# usage: pack <archive> <root>
# unpack <archive> <root>
#
# Where <root> is the directory to unpack to and will be cleaned out
# if it exists.
#
{
printf "usage: root_archive pack <archive> <root>\n"
printf " root_archive unpack <archive> <root>\n"
exit 1
}
{
if [ -d $MNT ] ; then
fi
fi
}
{
(
cd $MNT
)
# increase the chances the unmount will succeed
}
{
MR=$1
fi
else
fi
if [ $? != 0 ] ; then
exit 2
fi
else
printf "invalid root archive\n"
fi
fi
}
{
SRC=$1
DST=$2
(
cd $SRC
# copy all files over to preserve hard links
#
fiocompress -mc $file $DST/$file &
fi
done
# now re-copy a couple of uncompressed files
# some of the files are replaced with links into
# from there as well and add them to the list ti
# be copied uncompressed
(
)
(
cd $DST
)
done
else
fi
)
}
{
}
pack()
{
MR="$1"
# always compress if fiocompress exists
#
if [ -x /usr/sbin/fiocompress ] ; then
COMPRESS=true
fi
# Estimate image size and add %10 overhead for ufs stuff.
# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
# e.g. zfs, in which the disk usage is less than the sum of the file
# sizes. The nawk code
#
# {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
#
# next multiple of 1024. This mimics the behavior of ufs especially
# with directories. This results in a total size that's slightly
# bigger than if du was called on a ufs directory.
#
# if the operation in turn is compressing the files the amount
# of typical shrinkage is used to come up with a useful archive
# size
{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
END {print int(t * 1.10 / 1024)}')
fi
if [ $? != 0 ] ; then
exit 2
fi
fi
(
cd "$UNPACKED_ROOT"
else
fi
)
fi
else
fi
}
{
}
# main
#
while getopts s:6c opt ; do
s) EXTRA_SPACE="$OPTARG"
;;
6) STRIP_AMD64=false
;;
c) COMPRESS=true
;;
*) usage
;;
esac
done
[ $# == 3 ] || usage
UNPACKED_ROOT="$3"
MR="$2"
# sanity check
fi
fi
# always unpack into a fresh root
case $1 in
rm -rf "$UNPACKED_ROOT"
mkdir -p "$UNPACKED_ROOT"
;;
esac
case $1 in
;;
;;
*) usage
;;
esac