#!/bin/sh # # cygtweak -- add or remove program-specific values for the CYGWIN # environment variable. # # Copyright (c) 2002, Igor Pechtchanski. # # You may distribute under the terms of the GNU General Public # License. # # Igor Pechtchanski # pechtcha@cs.nyu.edu # Department of Computer Science # New York University # New York, NY 10003 # # cygtweak v0.1 # if [ "$1" = debug ]; then set -x shift fi progname=`basename $0` version='0.1' REGTOOL=/usr/bin/regtool REGKEY="/HKLM/SOFTWARE/Cygnus Solutions/Cygwin/Program Options" if [ ! -x $REGTOOL ]; then echo "$progname: Can't find $REGTOOL, exiting." 1>&2 exit 1 fi while [ $# -ne 0 ]; do case $1 in -v | --verbose) verbose="YES" ;; -n | --noexec) verbose="YES" noexec="YES" ;; -a | --add-program-override) if [ -n "$action" ]; then echo "$progname: Please specify only one action." 1>&2 exit 0 fi action="ADD" program="$2" cygwin="$3" shift shift;; -r | --remove-program-override) if [ -n "$action" ]; then echo "$progname: Please specify only one action." 1>&2 exit 0 fi action="REMOVE" program="$2" shift;; -e | --export) if [ -z "$action" ]; then echo "$progname: Please specify an action first." 1>&2 elif [ "$action" != ADD ]; then echo "$progname: Warning: -e ignored for -r." 1>&2 else export="YES" fi;; -V | -?version) echo $progname: version $version 1>&2 exit 0 ;; -h | -?help) echo "Usage: $progname [-v|-n] action action-specific-params" 1>&2 echo " where action is one of" 1>&2 echo " -a|--add-program-override program \$CYGWIN-value [-e|--export]" 1>&2 echo " adds an override for the value of the CYGWIN variable" 1>&2 echo " when invoking the program" 1>&2 echo " --export exports the value to all children of the given program" 1>&2 echo " -r|--remove-program-override program" 1>&2 echo " removes an override for a given program" 1>&2 echo 1>&2 echo "If --verbose or -v is specified, the registry modification actions are printed" 1>&2 echo "If --noexec or -n is specified, no commands that change the registry will be run" 1>&2 echo " Note that --noexec implies --verbose" 1>&2 echo 1>&2 echo "Examples: $progname -v --add-program-override /usr/sbin/inetd 'tty' -export" 1>&2 echo " $progname --remove-program-override /usr/sbin/sshd" 1>&2 exit 0 ;; *) echo "$progname: Invalid argument(s)." 1>&2 echo "Try '$progname --help' for more information." 1>&2 exit 1 ;; esac shift done if [ -z "$action" ]; then echo "$progname: Missing argument(s)." 1>&2 echo "Try '$progname --help' for more information." 1>&2 exit 1 fi case $program in /*) program=`cygpath -w "$program" | sed 's/\\\\/\\\\\\\\/g'` ;; esac case $action in ADD) # First check if the key exists if ! $REGTOOL -q check "$REGKEY"; then if [ -n "$verbose" ]; then echo "$progname: \"$REGKEY\" not found, adding." fi if [ -z "$noexec" ]; then $REGTOOL add "$REGKEY" else echo "$REGTOOL add \"$REGKEY\"" fi fi # Tack on "export" if needed if [ -n "$export" ]; then cygwin="$cygwin export" fi # Now add the corresponding value if [ -z "$noexec" ]; then $REGTOOL -K@ -s set "$REGKEY@$program" "$cygwin" exit $? else echo "$REGTOOL -K@ -s set \"$REGKEY@$program\" \"$cygwin\"" fi ;; REMOVE) # Remove the corresponding value if [ -z "$noexec" ]; then $REGTOOL -K@ unset "$REGKEY@$program" exit $? else echo "$REGTOOL -K@ unset \"$REGKEY@$program\"" fi ;; esac