1075N/A#!/usr/bin/ksh -p
2362N/A#
1075N/A# CDDL HEADER START
1075N/A#
1075N/A# The contents of this file are subject to the terms of the
1075N/A# Common Development and Distribution License (the "License").
1075N/A# You may not use this file except in compliance with the License.
1075N/A#
1075N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1075N/A# or http://www.opensolaris.org/os/licensing.
1075N/A# See the License for the specific language governing permissions
1075N/A# and limitations under the License.
1075N/A#
1075N/A# When distributing Covered Code, include this CDDL HEADER in each
1075N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1075N/A# If applicable, add the following below this CDDL HEADER, with the
1075N/A# fields enclosed by brackets "[]" replaced with your own identifying
1075N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2362N/A#
2362N/A# CDDL HEADER END
2362N/A#
1075N/A# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
1075N/A#
1075N/A
1075N/A# Load SMF constants and functions
1075N/A. /lib/svc/share/smf_include.sh
1075N/A. /lib/svc/share/fs_include.sh
1075N/A. /lib/svc/share/pkg5_include.sh
1075N/A
1075N/ACHOWN=/usr/bin/chown
1075N/AZFS=/usr/sbin/zfs
1075N/A
1075N/Aresult=$SMF_EXIT_ERR_FATAL
1075N/A
1075N/Acase "$1" in
1075N/A'start')
1075N/A # check if we already have a mounted /var/share/pkg/repositories
1075N/A readmnttab /var/share/pkg/repositories < /etc/mnttab
1075N/A if [ "$fstype" = zfs ] ; then
1075N/A exit $SMF_EXIT_OK
1075N/A else
1075N/A readmnttab / < /etc/mnttab
1075N/A if [ "$fstype" = zfs ] ; then
1075N/A #
1075N/A # $special gets set by readmnttab in
1075N/A # /lib/svc/share/fs_include.sh
1075N/A #
1075N/A be=$special
1075N/A rpool=$(print $be | cut -d / -f1)
1075N/A else
1075N/A # we're on a LiveCD, so exit immediately.
1075N/A exit $SMF_EXIT_OK
1075N/A fi
1075N/A
1075N/A DS="$rpool/VARSHARE/pkg/repositories"
1075N/A
1075N/A # If the dataset exists, we mount it along with any child
1075N/A # datasets, then exit.
1075N/A $ZFS list "$DS" > /dev/null 2>&1
if [ $? -eq 0 ] ; then
child_fs_mount=0
for child in $($ZFS list -H -r -t filesystem \
-o name "$DS"); do
$ZFS mount "$child"
child_fs_mount=$(( $child_fs_mount + $? ))
done
if [ $child_fs_mount -eq 0 ] ; then
exit $SMF_EXIT_OK
else
check_failure 1 \
"Unable to mount child datasets of $DS" \
$SMF_FMRI exit
fi
fi
# Otherwise, we need to create the dataset, taking care to set
# canmount=noauto, to allow multiple bootable rpools to coexist
# on the same system.
$ZFS create -p $DS
check_failure $? "Unable to create $DS" $SMF_FMRI exit
for fs in "$rpool/VARSHARE/pkg" \
"$rpool/VARSHARE/pkg/repositories" ; do
$ZFS set canmount=noauto $fs
done
$ZFS allow pkg5srv create,mount,canmount,snapshot "$DS"
check_failure $? \
"Unable to delegate ZFS permissions on $DS" \
$SMF_FMRI exit
$CHOWN pkg5srv:pkg5srv /var/share/pkg/repositories
check_failure $? \
"Unable to chown /var/share/pkg/repositories" \
$SMF_FMRI exit
fi
;;
esac
exit $SMF_EXIT_OK