Beginnings of a patch: /etc/hosts

Igor Pechtchanski pechtcha@cs.nyu.edu
Wed Sep 11 15:37:00 GMT 2002


Hi,
Script attached; comments below.

On Wed, 11 Sep 2002, Paul Johnston wrote:

> Hi,
> Brilliant to see so much progress on this!
> Are you sure that "CYGWIN_9*)" correctly catches Windows ME?

No, I'm not.  I'm incorporating Warren Young's suggestion.  Unless someone
with ME can confirm that 'uname -s' returns CYGWIN_9*?  Nicholas?

> I think we're safe with the case issue, given that cygpath -W seems to
> return the correct case.

Yes, but we are assuming that the file names are all lowercase.

> However, I think adding this belt-and-braces check might be a good idea:
>
> if [ ! -d "$WINETC" ]
> then
>   echo "ERROR: Directory $WINETC not found" >&2
>   exit 2
> fi

Done, but without the error code.  Should we still print a message,
though?

> Apart from that, seems just about ready to go. Not sure if the change
> history is necessary though, at least not until it's first checked-in.
>
> Paul

The change history was for me to keep track of what I've done.  It should
probably be deleted when this is submitted as an official patch...  This
is my alternative to setting up a cvs repository for one file (probably
should have, though, same effort, and fewer complaints :-) ).

On Wed, 11 Sep 2002, Warren Young wrote:

> Paul Johnston wrote:
> >
> > Are you sure that "CYGWIN_9*)" correctly catches Windows ME?
>
> You might take a look at my alternate patch in the patches list.  It
> doesn't rely on that sort of thing -- it relies instead on well-known
> environment variables: $SYSTEMROOT and $WINDIR.  It still has some
> OS-specific knowledge in it, in that it knows that only NT-derived OSes
> define SYSTEMROOT and uses WINDIR as a fallback for 9x systems.  I don't
> know which approach is superior.

I've incorporated yours for now.  If people confirm that `uname -s`
returns either CYGWIN_NT* or CYGWIN_9* on all relevant systems, we could
revert to that mechanism.

> > However, I think adding this belt-and-braces check might be a good idea:
>
> I'm not a fan of the "if X, scream and die" bit in this original script
> or the one you've proposed.  Postinstall scripts shouldn't fail.  I
> think they should give best effort, and if they can't do what you want,
> they should simply quietly skip that bit.  Besides, this patch may be
> put into some other postinstall script, and you don't want to avoid
> doing the other tasks in that script just because the /etc/hosts part
> can't find the Windows system directory.

Well, we should at least refrain from making the symlinks then...
On another note, I'm not sure why you were checking for the presence of
the windows files.  We could still create dangling symlinks if they are
missing, which will allow the files to be created by editing/saving the
symlink.
	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
#--
# Creates symbolic links from some /etc files to their windows equivalents
#
# Version: 0.4
#
# ChangeLog:
#    v0.4 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
#       Use $SYSTEMROOT and $WINDIR to determine the OS (thx Warren Young)
#       Check for existence of $WINETC directory (thx Paul Johnston)
#       Use `expr substr` instead of `echo | sed` (thx Joe Buehler)
#    v0.3 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
#       Quote variable references (thx Joe Buehler)
#       Use `cygpath -W` instead of "$SYSTEMROOT" (thx Corinna Vinschen)
#       Change protocol to protocols on cygwin
#       Add ChangeLog
#    v0.2 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
#       Use `uname -s` instead of "$OS"
#       Add Win9x support
#       Add networks file
#    v0.1 Paul Johnston <paj at pajhome.org.uk>:
#       Initial version
#--

VERBOSE=-v

WINHOME=`/bin/cygpath -W`

if [ -n "$SYSTEMROOT" ]
then
  WINETC="$WINHOME/system32/drivers/etc"
elif [ -n "$WINDIR" ]
then
  WINETC="$WINHOME"
else
  exit 0
fi
FILES="hosts protocols services networks"

if [ ! -d "$WINETC" ]
then
  exit 0
fi

for FILE in $FILES
do
  if [ ! -e "/etc/$FILE" ]
  then
    # Windows only uses the first 8 characters
    WFILE=`expr substr "$FILE" 1 8`
    /bin/ln -s $VERBOSE "$WINETC/$WFILE" "/etc/$FILE"
  fi
done

-------------- next part --------------
--- make-etc-links.sh-orig	2002-09-11 14:07:31.000000000 -0400
+++ make-etc-links.sh	2002-09-11 18:08:39.000000000 -0400
@@ -2,12 +2,16 @@
 #--
 # Creates symbolic links from some /etc files to their windows equivalents
 #
-# Version: 0.3
+# Version: 0.4
 #
 # ChangeLog:
+#    v0.4 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
+#       Use $SYSTEMROOT and $WINDIR to determine the OS (thx Warren Young)
+#       Check for existence of $WINETC directory (thx Paul Johnston)
+#       Use `expr substr` instead of `echo | sed` (thx Joe Buehler)
 #    v0.3 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
-#       Quote variable references
-#       Use `cygpath -W` instead of "$SYSTEMROOT"
+#       Quote variable references (thx Joe Buehler)
+#       Use `cygpath -W` instead of "$SYSTEMROOT" (thx Corinna Vinschen)
 #       Change protocol to protocols on cygwin
 #       Add ChangeLog
 #    v0.2 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
@@ -20,22 +24,30 @@
 
 VERBOSE=-v
 
-OSNAME=`/bin/uname -s`
 WINHOME=`/bin/cygpath -W`
 
-case "$OSNAME" in
-   CYGWIN_NT*) WINETC="$WINHOME"/system32/drivers/etc ;;
-   CYGWIN_9*) WINETC="$WINHOME" ;;
-   *) echo "Unknown system type $OSNAME; exiting" >&2; exit 1 ;;
-esac
+if [ -n "$SYSTEMROOT" ]
+then
+  WINETC="$WINHOME/system32/drivers/etc"
+elif [ -n "$WINDIR" ]
+then
+  WINETC="$WINHOME"
+else
+  exit 0
+fi
 FILES="hosts protocols services networks"
 
+if [ ! -d "$WINETC" ]
+then
+  exit 0
+fi
+
 for FILE in $FILES
 do
   if [ ! -e "/etc/$FILE" ]
   then
     # Windows only uses the first 8 characters
-    WFILE=`echo $FILE | sed 's/^\(.\{0,8\}\).*/\1/'`
+    WFILE=`expr substr "$FILE" 1 8`
     /bin/ln -s $VERBOSE "$WINETC/$WFILE" "/etc/$FILE"
   fi
 done
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list