@@ -96,30 +96,28 @@ host="`echo $host | tr '[[A-Z]]' '[[a-z]]'`"
9696if test -f "template/$host"
9797then TEMPLATE="$host"
9898else
99- # Next try for an exact match to a .similar entry.
100- # There shouldn't be multiple matches, but take the last if there are.
101- GUESS=`grep "^$host=" template/.similar | sed 's/^.*=//' | tail -1`
99+ # Scan template/.similar for a rule that tells us which template to use.
100+ # The format of each line of the file is
101+ # hostnamepattern=templatefilename
102+ # where the hostnamepattern is evaluated per the rules of expr(1) ---
103+ # namely, it is a standard regular expression with an implicit ^ at the
104+ # start. If multiple lines match, we will end up using the last match.
105+ GUESS=""
106+ exec 4<template/.similar
107+ while read LINE <&4
108+ do
109+ SIMHOST=`expr "$LINE" : '\(.*\)='`
110+ MATCH=`expr "$host" : "$SIMHOST"`
111+ if test "$MATCH" != 0
112+ then GUESS=`echo "$LINE" | sed 's/^.*=//'`
113+ fi
114+ done
115+ exec 4<&-
102116 if test "$GUESS"
103117 then TEMPLATE="$GUESS"
104118 else
105- # Next look for a .similar entry that is a prefix of $host.
106- # If there are multiple matches, take the last one.
107- exec 4<template/.similar
108- while read LINE <&4
109- do
110- SIMHOST=`expr "$LINE" : '\(.*\)='`
111- MATCH=`expr "$host" : "$SIMHOST"`
112- if test "$MATCH" != 0
113- then GUESS=`echo "$LINE" | sed 's/^.*=//'`
114- fi
115- done
116- exec 4<&-
117- if test "$GUESS"
118- then TEMPLATE="$GUESS"
119- else
120- # Last chance ... maybe uname -s will match an entry.
121- TEMPLATE=`uname -s | tr '[[A-Z]]' '[[a-z]]'`
122- fi
119+ # Last chance ... maybe uname -s will match an entry.
120+ TEMPLATE=`uname -s | tr '[[A-Z]]' '[[a-z]]'`
123121 fi
124122fi
125123 ])
@@ -130,7 +128,7 @@ if test ! -f "template/$TEMPLATE"; then
130128echo ""
131129echo "$TEMPLATE does not exist"
132130echo ""
133- echo "Available Templates (set using --with-template):"
131+ echo "Available Templates (select one using --with-template):"
134132echo ""
135133ls template
136134echo ""