Add/remove program options [Was Re: cygwin-ENV-Variable]

Igor Pechtchanski pechtcha@cs.nyu.edu
Thu Aug 8 13:06:00 GMT 2002


On Sun, 4 Aug 2002, Christopher Faylor wrote:

> On Sun, Aug 04, 2002 at 09:01:26PM +0200, Sven K?hler wrote:
> >i realized that enigmail doesn't pass the CYGWIN-Variable to gpg when
> >executing. could you imagine chaning the ENV-Variable into a Reg-Key!?
>
> There is already an undocumented way to do this in cygwin via the
> Program Options registry key.  Create a new key:
>
> HKLM\SOFTWARE\Cygnus Solutions\Cygwin\Program Options
>
> under this, you can create an string entry named "default" with data
> containing CYGWIN environment variable options.  If you add an "export"
> option to the end of the data values, a CYGWIN environment variable will
> be regenerated from the registry and visible in the environment.
>
> You can also set options for individual programs by adding an entry like:
>
> Name                    Type            Data
> c:\usr\sbin\inetd.exe   REG_SZ          tty export
>
> That will make cygwin always set the cygwin option to tty and export
> a CYGWIN=tty for every program that inetd invokes.
>
> The main reason this this is not documented is that there is no
> programmatic way to manipulate it and I am not comfortable with telling
> people how to edit the registry "by hand".
>
> However, if you are familiar with the registry, then setting this value
> should not be a big deal.

Hi,
I've whipped up a small script (attached) to add and remove the values for
individual program options.  The script is named cygtweak (courtesy Robert
Collins), but should probably be renamed.  The help should be reasonably
comprehensive.

I'm not sure if this qualifies as a patch, but I think this got overlooked
on the cygwin mailing list, so I'm re-sending it here.  If this is a wrong
place for it, please let me know.  Where and how does one submit new
programs, anyway?  Do they need a ChangeLog entry?
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file

-------------- next part --------------
#!/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.2
#
# Changes in v0.2:
# 	Fix --verbose.
# 	Fix typo in usage.
#

if [ "$1" = debug ]; then
    set -x
    shift
fi

progname=`basename $0`
version='0.2'

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 [ -n "$verbose" ]; then
            echo "$progname: Setting \"$REGKEY/$program\" to \"$cygwin\"."
        fi
        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 [ -n "$verbose" ]; then
            echo "$progname: Removing \"$REGKEY/$program\"."
        fi
        if [ -z "$noexec" ]; then
            $REGTOOL -K@ unset "$REGKEY@$program"
            exit $?
        else
            echo "$REGTOOL -K@ unset \"$REGKEY@$program\""
        fi
        ;;
esac



More information about the Cygwin-patches mailing list