Home | History | Annotate | Download | only in src
      1 #!/bin/sh
      2 
      3 #
      4 # CDDL HEADER START
      5 #
      6 # The contents of this file are subject to the terms of the
      7 # Common Development and Distribution License, Version 1.0 only
      8 # (the "License").  You may not use this file except in compliance
      9 # with the License.
     10 #
     11 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     12 # or http://www.opensolaris.org/os/licensing.
     13 # See the License for the specific language governing permissions
     14 # and limitations under the License.
     15 #
     16 # When distributing Covered Code, include this CDDL HEADER in each
     17 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     18 # If applicable, add the following below this CDDL HEADER, with the
     19 # fields enclosed by brackets "[]" replaced with your own identifying
     20 # information: Portions Copyright [yyyy] [name of copyright owner]
     21 #
     22 # CDDL HEADER END
     23 #
     24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 
     28 # a postinstall script - adds zfssnap role.
     29 # Return 0 if a user exists, 1 otherwise.
     30 #
     31 
     32 # Check if the first argument is 0, settting our return
     33 # variable to an error otherwise
     34 #
     35 check_error() {
     36 	RETURN_CODE=$1
     37 	ERROR="$2"
     38         if [ "$RETURN_CODE" -ne 0 ] ; then
     39                 echo "ERROR: $ERROR"
     40         fi
     41 }
     42 
     43 user_exists() {
     44         USER=$1
     45 	/usr/bin/grep "^$USER:" $BASEDIR/etc/passwd > /dev/null
     46 	return $?
     47 }
     48 
     49 auth_exists() {
     50 	AUTH=$1
     51 	/usr/bin/grep "^$AUTH:" $BASEDIR/etc/security/auth_attr > /dev/null
     52 	return $?
     53 }
     54 
     55 # add our authorization
     56 auth_exists solaris.smf.manage.zfs-auto-snapshot
     57 if [ $? -ne 0 ] ; then
     58 	echo "solaris.smf.manage.zfs-auto-snapshot:::Manage the ZFS Automatic Snapshot Service::" \
     59 	>> /etc/security/auth_attr
     60 fi
     61 
     62 # add the zfssnap role - probably only works on a local system :-(
     63 user_exists zfssnap
     64 if [ $? -ne 0 ] ; then
     65 	/usr/sbin/roleadd -d / -u 51 -c "ZFS Automatic Snapshots role" \
     66 	-P "ZFS File System Management" \
     67 	-A solaris.smf.manage.zfs-auto-snapshot -m zfssnap
     68 	check_error $? "Unable to create zfssnap role!"
     69 	/usr/bin/passwd -r files -N zfssnap
     70 	check_error $? "Unable to make zfssnap a no-password account"
     71 else
     72 	echo "zfssnap role already exists."
     73 fi
     74 
     75