1 0 dave # 2 0 dave # CDDL HEADER START 3 0 dave # 4 0 dave # The contents of this file are subject to the terms of the 5 0 dave # Common Development and Distribution License (the "License"). 6 0 dave # You may not use this file except in compliance with the License. 7 0 dave # 8 0 dave # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 dave # or http://www.opensolaris.org/os/licensing. 10 0 dave # See the License for the specific language governing permissions 11 0 dave # and limitations under the License. 12 0 dave # 13 0 dave # When distributing Covered Code, include this CDDL HEADER in each 14 0 dave # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 dave # If applicable, add the following below this CDDL HEADER, with the 16 0 dave # fields enclosed by brackets "[]" replaced with your own identifying 17 0 dave # information: Portions Copyright [yyyy] [name of copyright owner] 18 0 dave # 19 0 dave # CDDL HEADER END 20 0 dave # 21 2 dave # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 22 0 dave # Use is subject to license terms. 23 0 dave # 24 0 dave # ident "%Z%%M% %I% %E% SMI" 25 0 dave # 26 0 dave # 27 0 dave # Copy files from SRCDIR to TARGETDIR. The list of files to 28 0 dave # be copied are stored in FILELIST in the format: 29 0 dave # 30 0 dave # <type(f or d)> <permission> <ownership> <filename> 31 0 dave # 32 0 dave copyfiles() { 33 0 dave typeset fl="" 34 0 dave 35 0 dave SRCDIR=$1 36 0 dave TARGETDIR=$2 37 0 dave FILELIST=$3 38 0 dave 39 0 dave cat "$FILELIST" | while read typ perms own f 40 0 dave do 41 0 dave fl="$f" 42 0 dave 43 0 dave if [[ "$typ" = "d" ]] 44 0 dave then 45 0 dave mkdir -m $perms -p "$TARGETDIR/$f" 46 0 dave 47 0 dave elif [[ "$typ" = "f" ]] 48 0 dave then 49 2 dave /usr/bin/cp -f -p "$SRCDIR/$f" "$TARGETDIR/$f" 50 0 dave 51 0 dave elif [[ "$typ" = "s" ]] 52 0 dave then 53 0 dave fl=`echo $f | sed 's/=/ /' | cut -d" " -f1` 54 0 dave trg=`echo $f | sed 's/=/ /' | cut -d" " -f2` 55 0 dave ln -sf $trg "$TARGETDIR/$fl" 56 0 dave 57 0 dave elif [[ "$typ" = "l" ]] 58 0 dave then 59 0 dave fl=`echo $f | sed 's/=/ /' | cut -d" " -f1` 60 0 dave trg=`echo $f | sed 's/=/ /' | cut -d" " -f2` 61 0 dave 62 0 dave dir=`pwd` 63 0 dave cd `dirname "$TARGETDIR/$fl"` 64 0 dave ln -f $trg `basename "$fl"` 65 0 dave cd $dir 66 0 dave else 67 0 dave continue 68 0 dave fi 69 0 dave 70 0 dave if [[ "$typ" != "s" ]] 71 0 dave then 72 0 dave if [[ "$typ" != "d" ]] 73 0 dave then 74 0 dave /usr/bin/chmod $perms "$TARGETDIR/$fl" 75 0 dave fi 76 0 dave /usr/bin/chown $own "$TARGETDIR/$fl" 77 0 dave else 78 0 dave /usr/bin/chown -h $own "$TARGETDIR/$fl" 79 0 dave fi 80 0 dave done 81 0 dave } 82 0 dave # 83 0 dave # Given a target base directory and a file containing a list of files, create 84 0 dave # any directories in that list with the permissions and ownership as specified 85 0 dave # in the list 86 0 dave # 87 0 dave mkdirs() { 88 0 dave typeset fl="" 89 0 dave 90 0 dave TARGETDIR=$1 91 0 dave FILELIST=$2 92 0 dave 93 0 dave cat "$FILELIST" | while read typ perms own f 94 0 dave do 95 0 dave fl="$f" 96 0 dave 97 0 dave if [[ "$typ" = "d" ]] 98 0 dave then 99 0 dave /usr/bin/mkdir -m $perms -p "$TARGETDIR/$f" 100 0 dave /usr/bin/chown $own "$TARGETDIR/$fl" 101 0 dave fi 102 0 dave done 103 0 dave } 104 0 dave # 105 0 dave # Relocate a list of modules from one directory to another 106 0 dave # 107 0 dave relocatemodules() { 108 0 dave FROMDIR=$1 109 0 dave TODIR=$2 110 0 dave MODULES=$3 111 0 dave 112 0 dave grep -v "^#" $MODULES | while read mod 113 0 dave do 114 0 dave fdir=`dirname $TODIR/$mod` 115 0 dave mkdir -p $fdir 116 0 dave 117 0 dave cp $FROMDIR/$mod $TODIR/$mod 118 0 dave rm -f $FROMDIR/$mod 119 0 dave done 120 0 dave } 121 0 dave 122