Beginnings of a patch: /etc/hosts

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


On Wed, 11 Sep 2002, Joe Buehler wrote:

> Paul Johnston wrote:
>
> > if [ "$OS" = "Windows_NT" ]
> > then
> >   WINETC=`/bin/cygpath $SYSTEMROOT`/system32/drivers/etc
> >   FILES="hosts protocol services"
> > fi
> >
> > for FILE in $FILES
> > do
> >   if [ ! -e /etc/$FILE ]
> >   then
> >     /bin/ln -s $VERBOSE ${WINETC}/$FILE /etc/$FILE
> >   fi
> > done
>
> Not likely to happen here, but... beware of whitespace in
> $SYSTEMROOT / $WINETC.
>
> I generally double-quote variable references as a matter of course
> in shell scripts so I don't run into bugs resulting from white
> space in the contents.
>
> Joe Buehler

A very good point.  Another patch (against my previous post) and the new
script are attached.  The new version fixes variable quoting and some
other minor things and incorporates Corinna's suggestion.
(Aside: should I be posting the actual scripts, or can people follow the
trail of patches?)

TODO: The sed script strikes me as a bit inelegant.  Also, I still can't
think of a way to make sure the case of the paths is correct.
Suggestions?
	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 --------------
--- make-etc-links.sh-orig	2002-09-10 15:39:37.000000000 -0400
+++ make-etc-links.sh	2002-09-11 14:07:31.000000000 -0400
@@ -1,23 +1,42 @@
 #!/bin/sh
 #--
 # Creates symbolic links from some /etc files to their windows equivalents
+#
+# Version: 0.3
+#
+# ChangeLog:
+#    v0.3 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
+#       Quote variable references
+#       Use `cygpath -W` instead of "$SYSTEMROOT"
+#       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
 
 OSNAME=`/bin/uname -s`
+WINHOME=`/bin/cygpath -W`
 
 case "$OSNAME" in
-   CYGWIN_NT*) WINETC=`/bin/cygpath $SYSTEMROOT`/system32/drivers/etc ;;
-   CYGWIN_9*) WINETC=`/bin/cygpath $WINBOOTDIR` ;;
+   CYGWIN_NT*) WINETC="$WINHOME"/system32/drivers/etc ;;
+   CYGWIN_9*) WINETC="$WINHOME" ;;
    *) echo "Unknown system type $OSNAME; exiting" >&2; exit 1 ;;
 esac
-FILES="hosts protocol services networks"
+FILES="hosts protocols services networks"
 
 for FILE in $FILES
 do
-  if [ ! -e /etc/$FILE ]
+  if [ ! -e "/etc/$FILE" ]
   then
-    /bin/ln -s $VERBOSE ${WINETC}/$FILE /etc/$FILE
+    # Windows only uses the first 8 characters
+    WFILE=`echo $FILE | sed 's/^\(.\{0,8\}\).*/\1/'`
+    /bin/ln -s $VERBOSE "$WINETC/$WFILE" "/etc/$FILE"
   fi
 done
 
-------------- next part --------------
#!/bin/sh
#--
# Creates symbolic links from some /etc files to their windows equivalents
#
# Version: 0.3
#
# ChangeLog:
#    v0.3 Igor Pechtchanski <pechtcha at cs.nyu.edu>:
#       Quote variable references
#       Use `cygpath -W` instead of "$SYSTEMROOT"
#       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

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
FILES="hosts protocols services networks"

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/'`
    /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