1 #!/bin/sh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 # Use is subject to license terms. 24 # 25 26 PATH="/usr/bin:/usr/sbin:${PATH}" 27 export PATH 28 29 while read src dest; do 30 if [ ! -f $dest ]; then 31 cp -p $src $dest 32 continue; 33 fi 34 35 newdest=/tmp/i.logindevperm.$$ 36 cat /dev/null > $newdest 37 38 while read line; do 39 # if not an entry, just print as is and move to next record 40 entry=`echo "$line" | egrep "^[# ]*/[a-zA-Z0-9\/]+[ ]+[0-9]+[ ]+"` 41 if [ -z "$entry" ]; then 42 echo "$line" 43 continue 44 fi 45 46 # extract 'devices' field 47 devices=`echo "$line" | awk '{print $3}'` 48 if [ -z "$devices" ]; then 49 echo "$line" 50 continue 51 fi 52 53 # extract 'drivers' field 54 drivers=`echo "$line" | awk '{print $4}'` 55 found_driver=`echo "$drivers" | egrep "^driver="` 56 if [ -z "$found_driver" ]; then 57 drivers="" 58 fi 59 60 devices=`echo "$devices" | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g' | sed 's/\+/\\\+/g' | sed 's/\*/\\\*/g'` 61 62 # if dest has an entry for these devices and the difference 63 # between dest entry and src entry is not only 64 # "/dev/console" vs. "/dev/vt/active", preserve dest entry 65 dest_entry=`egrep "^[# ]*/[a-zA-Z0-9\/]+[ ]+[0-9]+[ ]+$devices[ ]*$drivers" $dest | tail -1 2>/dev/null` 66 tmp_line=`echo "$line" | sed 's:/dev/vt/active:/dev/console:'` 67 68 if [ -n "$dest_entry" ] && [ "$dest_entry" != "$tmp_line" ]; then 69 echo "$dest_entry" 70 else 71 echo "$line" 72 fi 73 done < $src > $newdest 74 75 # now carry over user's own entries 76 while read line; do 77 # skip non-entries 78 entry=`echo "$line" | egrep "^[# ]*/[a-zA-Z0-9\/]+[ ]+[0-9]+[ ]+"` 79 if [ -z "$entry" ]; then 80 continue 81 fi 82 83 # extract 'devices' field 84 devices=`echo "$line" | awk '{print $3}'` 85 if [ -z "$devices" ]; then 86 continue 87 fi 88 89 # extract 'drivers' field 90 drivers=`echo "$line" | awk '{print $4}'` 91 found_driver=`echo "$drivers" | egrep "^driver="` 92 if [ -z "$found_driver" ]; then 93 drivers="" 94 fi 95 96 devices=`echo "$devices" | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g' | sed 's/\+/\\\+/g' | sed 's/\*/\\\*/g'` 97 98 # if dest has an entry for these devices, preserve that 99 dest_entry=`egrep "^[# ]*/[a-zA-Z0-9\/]+[ ]+[0-9]+[ ]+"$devices"[ ]*"$drivers"" $newdest | tail -1 2>/dev/null` 100 if [ -z "$dest_entry" ]; then 101 echo "$line" 102 fi 103 done < $dest >> $newdest 104 105 cp $newdest $dest 106 rm -f $newdest 107 done 108 109 exit 0 110