1 #
   2 # Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.
   8 #
   9 # This code is distributed in the hope that it will be useful, but WITHOUT
  10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 # version 2 for more details (a copy is included in the LICENSE file that
  13 # accompanied this code).
  14 #
  15 # You should have received a copy of the GNU General Public License version
  16 # 2 along with this work; if not, write to the Free Software Foundation,
  17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 #
  19 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20 # CA 95054 USA or visit www.sun.com if you need additional information or
  21 # have any questions.
  22 #
  23 
  24 #
  25 # Utility Shell Script for generating .properties files or .password files
  26 # or .access files from a list of input .in files.
  27 #
  28 # Source in this GeneratePropertyPassword.sh and call the function
  29 # generatePropertyPasswordFiles. 
  30 # Call restoreFilePermissions to restore file permissions after the test completes
  31 #
  32 
  33 
  34 OS=`uname -s`
  35 UMASK=`umask`
  36 
  37 case $OS in
  38 SunOS | Linux)
  39     PATHSEP=":"
  40     FILESEP="/"
  41     DFILESEP=$FILESEP
  42     TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
  43 
  44 cat <<EOF > ${TMP_FILE}
  45 s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
  46 EOF
  47     ;;
  48 Windows_95 | Windows_98 | Windows_NT | Windows_ME)
  49     PATHSEP=";"
  50     FILESEP="\\"
  51     DFILESEP=$FILESEP$FILESEP
  52     TMP_FILE=${TESTCLASSES}${FILESEP}${TESTCLASS}.sed.tmpfile
  53 
  54 cat <<EOF > ${TMP_FILE}0
  55 s^@TEST-SRC@/^${TESTCLASSES}${DFILESEP}^g
  56 EOF
  57     # Need to put double backslash in the .properties files
  58     cat ${TMP_FILE}0 | sed -e 's^\\\\^ZZZZ^g' | \
  59         sed -e 's^\\^ZZZZ^g' | \
  60         sed -e 's^ZZZZ^\\\\\\\\^g' > ${TMP_FILE}
  61 
  62     if [ "$OS" = "Windows_NT" ]; then
  63         USER=`id -u -n`
  64         CACLS="$SystemRoot/system32/cacls.exe"
  65         REVOKEALL="${TESTSRC}/../../windows/revokeall.exe"
  66         if [ ! -f "$REVOKEALL" ] ; then
  67             echo "$REVOKEALL missing"
  68             exit 1
  69         fi
  70     fi
  71 
  72 
  73     ;;
  74 *)
  75     echo "Unrecognized system!"
  76     exit 1
  77     ;;
  78 esac
  79 
  80 generatePropertyPasswordFiles() 
  81 {
  82    for f in $@
  83    do
  84         echo processing $f
  85         suffix=`basename $f .in`
  86         f2="${TESTCLASSES}${FILESEP}${suffix}"
  87 
  88         if [ -f "$f2" ] ; then
  89             rm -f $f2 || echo WARNING: $f2 already exits - unable to remove old copy
  90         fi
  91 
  92         echo creating $f2
  93         sed -f $TMP_FILE $f > $f2
  94 
  95         if [ "$OS" = "Windows_NT" ]; then
  96             chown $USER $f2
  97             # Grant this user full access
  98             echo Y|$CACLS $f2 \/E \/G $USER:F
  99             # Revoke everyone else
 100             $REVOKEALL $f2
 101             # Display ACLs
 102             $CACLS $f2
 103         else
 104             chmod 600 $f2
 105         fi
 106    done
 107 }
 108 
 109 restoreFilePermissions() 
 110 {
 111     for f in $@
 112     do
 113         suffix=`basename $f .in`
 114         f2="${TESTCLASSES}${FILESEP}${suffix}"
 115 
 116         if [ "$OS" = "Windows_NT" ]; then
 117             # Grant everyone full control
 118             $CACLS $f2 \/E \/G Everyone:F
 119         else
 120             chmod 777 $f2
 121         fi
 122 
 123     done
 124 }
 125