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