xref: /freebsd/contrib/ntp/sntp/scripts/genLocInfo (revision b5ff185e19f6013ca565b2a15bc2d6abce933f46)
12b15cb3dSCy Schubert#! /bin/sh
22b15cb3dSCy Schubert
32b15cb3dSCy Schubertargs=`getopt d:f:v $*`
42b15cb3dSCy Schubertset -- $args
52b15cb3dSCy Schubert
62b15cb3dSCy SchubertLF=
72b15cb3dSCy SchubertV=": "
82b15cb3dSCy Schubert
92b15cb3dSCy Schubertfor i
102b15cb3dSCy Schubertdo
112b15cb3dSCy Schubert    case "$i" in
122b15cb3dSCy Schubert     -d) sdir="$2" ; shift 2 ;;
132b15cb3dSCy Schubert     -f) locfile="$2" ; shift 2 ;;
142b15cb3dSCy Schubert     -v) V= ; shift ;;
152b15cb3dSCy Schubert     --) shift ; break ;;
162b15cb3dSCy Schubert    esac
172b15cb3dSCy Schubertdone
182b15cb3dSCy Schubert
192b15cb3dSCy Schubertcase "$sdir" in
202b15cb3dSCy Schubert '')
212b15cb3dSCy Schubert    sdir=.
222b15cb3dSCy Schubertesac
232b15cb3dSCy Schubert
242b15cb3dSCy Schubertcase "$locfile" in
252b15cb3dSCy Schubert */*)
262b15cb3dSCy Schubert    LF=$locfile
272b15cb3dSCy Schubert    ;;
282b15cb3dSCy Schubert '')
292b15cb3dSCy Schubert    ;;
302b15cb3dSCy Schubert *)
312b15cb3dSCy Schubert    lf=loc/$locfile
322b15cb3dSCy Schubert    if test -f $lf
332b15cb3dSCy Schubert    then
342b15cb3dSCy Schubert	LF=$lf
352b15cb3dSCy Schubert    fi
362b15cb3dSCy Schubert    ;;
372b15cb3dSCy Schubertesac
382b15cb3dSCy Schubert
392b15cb3dSCy Schubert# If we have a file to use (ie, LF is not empty) then look for one.
402b15cb3dSCy Schubertcase "$LF" in
412b15cb3dSCy Schubert '')
422b15cb3dSCy Schubert    PATH=$PATH:libevent/build-aux
432b15cb3dSCy Schubert    export PATH
442b15cb3dSCy Schubert    set `scripts/cvo.sh @osname@ @osver@` || exit 1
452b15cb3dSCy Schubert
462b15cb3dSCy Schubert    CVO_OSNAME=$1
472b15cb3dSCy Schubert    CVO_OSVER=$2
482b15cb3dSCy Schubert
492b15cb3dSCy Schubert    x=$CVO_OSVER
502b15cb3dSCy Schubert
512b15cb3dSCy Schubert    while true
522b15cb3dSCy Schubert    do
532b15cb3dSCy Schubert	case "$x" in
542b15cb3dSCy Schubert	 '') break ;;
552b15cb3dSCy Schubert	esac
562b15cb3dSCy Schubertlf=loc/$CVO_OSNAME$x
572b15cb3dSCy Schubert${V}echo "Looking for <$lf>" >&2
582b15cb3dSCy Schubert	if test -f $lf
592b15cb3dSCy Schubert	then
602b15cb3dSCy Schubert	    LF=$lf
612b15cb3dSCy Schubert	    break
622b15cb3dSCy Schubert	fi
632b15cb3dSCy Schubert	case "$x" in
642b15cb3dSCy Schubert	 *.*) x=`echo $x | sed -e 's/\.[^.]*$//'` ;;
652b15cb3dSCy Schubert	 *) x= ;;
662b15cb3dSCy Schubert	esac
672b15cb3dSCy Schubert    done
682b15cb3dSCy Schubert    case "$LF" in
692b15cb3dSCy Schubert     '')
702b15cb3dSCy Schubert	lf=loc/$CVO_OSNAME
712b15cb3dSCy Schubert${V}echo "Looking for <$lf>" >&2
722b15cb3dSCy Schubert	if test -f $lf
732b15cb3dSCy Schubert	then
742b15cb3dSCy Schubert	    LF=$lf
752b15cb3dSCy Schubert	fi
762b15cb3dSCy Schubert	;;
772b15cb3dSCy Schubert    esac
782b15cb3dSCy Schubert    # Handle some "aliases"
792b15cb3dSCy Schubert    case "$LF" in
802b15cb3dSCy Schubert     '')
812b15cb3dSCy Schubert	case "$CVO_OSNAME" in
82*276da39aSCy Schubert	 raspbian*)
83*276da39aSCy Schubert	    lf=loc/debian
84*276da39aSCy Schubert${V}echo "Looking for <$lf>" >&2
85*276da39aSCy Schubert	    if test -f $lf
86*276da39aSCy Schubert	    then
87*276da39aSCy Schubert		LF=$lf
88*276da39aSCy Schubert	    fi
89*276da39aSCy Schubert	    ;;
902b15cb3dSCy Schubert	 redhat* | fedora*)
912b15cb3dSCy Schubert	    lf=loc/redhat
922b15cb3dSCy Schubert${V}echo "Looking for <$lf>" >&2
932b15cb3dSCy Schubert	    if test -f $lf
942b15cb3dSCy Schubert	    then
952b15cb3dSCy Schubert		LF=$lf
962b15cb3dSCy Schubert	    fi
972b15cb3dSCy Schubert	    ;;
982b15cb3dSCy Schubert	esac
992b15cb3dSCy Schubert	;;
1002b15cb3dSCy Schubert    esac
1012b15cb3dSCy Schubert
1022b15cb3dSCy Schubert    # This might be a good place to see if uname returns "Linux",
1032b15cb3dSCy Schubert    # and if so, use a generic file for that.
1042b15cb3dSCy Schubert    case "$LF" in
1052b15cb3dSCy Schubert     '')
1062b15cb3dSCy Schubert	case "`uname`" in
1072b15cb3dSCy Schubert	 Linux)
1082b15cb3dSCy Schubert	    lf=loc/linux
1092b15cb3dSCy Schubert${V}echo "Looking for <$lf>" >&2
1102b15cb3dSCy Schubert	    if test -f $lf
1112b15cb3dSCy Schubert	    then
1122b15cb3dSCy Schubert		LF=$lf
1132b15cb3dSCy Schubert	    fi
1142b15cb3dSCy Schubert	    ;;
1152b15cb3dSCy Schubert	esac
1162b15cb3dSCy Schubert	;;
1172b15cb3dSCy Schubert    esac
1182b15cb3dSCy Schubert
1192b15cb3dSCy Schubert    # Finally, 'legacy'
1202b15cb3dSCy Schubert    case "$LF" in
1212b15cb3dSCy Schubert     '')
1222b15cb3dSCy Schubert	lf=loc/legacy
1232b15cb3dSCy Schubert${V}echo "Looking for <$lf>" >&2
1242b15cb3dSCy Schubert	if test -f $lf
1252b15cb3dSCy Schubert	then
1262b15cb3dSCy Schubert	    LF=$lf
1272b15cb3dSCy Schubert	fi
1282b15cb3dSCy Schubert	;;
1292b15cb3dSCy Schubert    esac
1302b15cb3dSCy Schubert
1312b15cb3dSCy Schubert    case "$LF" in
1322b15cb3dSCy Schubert     '')
1332b15cb3dSCy Schubert	echo "No loc/XXX file found!" >&2
1342b15cb3dSCy Schubert	exit 1
1352b15cb3dSCy Schubert	;;
1362b15cb3dSCy Schubert    esac
1372b15cb3dSCy Schubert    ;;
1382b15cb3dSCy Schubertesac
1392b15cb3dSCy Schubert
1402b15cb3dSCy Schubert${V}echo "Using <$LF>" >&2
1412b15cb3dSCy Schubertecho "GENLOCINFOFILE=$LF"
1422b15cb3dSCy Schubert
1432b15cb3dSCy Schubert###
1442b15cb3dSCy Schubert
1452b15cb3dSCy Schubertrm -f $sdir/genLocInfo.rc?
1462b15cb3dSCy Schubert
1472b15cb3dSCy SchubertoIFS=$IFS
1482b15cb3dSCy SchubertIFS=","
1492b15cb3dSCy Schubert
1502b15cb3dSCy Schubertwhile true
1512b15cb3dSCy Schubertdo
1522b15cb3dSCy Schubert    if read c d s x
1532b15cb3dSCy Schubert    then
1542b15cb3dSCy Schubert	# echo "Got <$c><$d><$s><$x>" >&2
1552b15cb3dSCy Schubert	case "$c" in
1562b15cb3dSCy Schubert	 \#*) continue ;;
1572b15cb3dSCy Schubert	esac
1582b15cb3dSCy Schubert	case "$x" in
1592b15cb3dSCy Schubert	 '') ;;
1602b15cb3dSCy Schubert	 *) echo "Unrecognized input: <$c,$d,$s,$x>" >&2
1612b15cb3dSCy Schubert	    touch $sdir/genLocInfo.rc1
1622b15cb3dSCy Schubert	    continue
1632b15cb3dSCy Schubert	    ;;
1642b15cb3dSCy Schubert	esac
1652b15cb3dSCy Schubert	case "$c,$d,$s" in
1662b15cb3dSCy Schubert	 [Mm][Aa][Nn],,)
1672b15cb3dSCy Schubert	    echo "MANTAGFMT=man"
1682b15cb3dSCy Schubert	    continue
1692b15cb3dSCy Schubert	    ;;
1702b15cb3dSCy Schubert	 [Mm][Dd][Oo][Cc],,)
1712b15cb3dSCy Schubert	    echo "MANTAGFMT=mdoc"
1722b15cb3dSCy Schubert	    continue
1732b15cb3dSCy Schubert	    ;;
1742b15cb3dSCy Schubert	esac
1752b15cb3dSCy Schubert
1762b15cb3dSCy Schubert	case "$c,$d,$s" in
1772b15cb3dSCy Schubert	 *,bin,*)  DB=bin ; DL= ; DS= ; NI= ;;
1782b15cb3dSCy Schubert	 *,libexec,*)  DB= ; DL=libexec ; DS= ; NI= ;;
1792b15cb3dSCy Schubert	 *,noinst,*)  DB= ; DL= ; DS= ; NI=noinst ;;
1802b15cb3dSCy Schubert	 *,sbin,*) DB= ; DL= ; DS=sbin ; NI= ;;
1812b15cb3dSCy Schubert	 *) echo "Unrecognized input: <$c,$d,$s>" >&2
1822b15cb3dSCy Schubert	    touch $sdir/genLocInfo.rc1
1832b15cb3dSCy Schubert	    continue
1842b15cb3dSCy Schubert	    ;;
1852b15cb3dSCy Schubert	esac
1862b15cb3dSCy Schubert	case "$c,$d,$s" in
1872b15cb3dSCy Schubert	 *,*,1) ;;
1882b15cb3dSCy Schubert	 *,*,1m) ;;
1892b15cb3dSCy Schubert	 *,*,1M) ;;
1902b15cb3dSCy Schubert	 *,*,8) ;;
1912b15cb3dSCy Schubert	 *) echo "Unrecognized input: <$c,$d,$s>" >&2
1922b15cb3dSCy Schubert	    touch $sdir/genLocInfo.rc1
1932b15cb3dSCy Schubert	    continue
1942b15cb3dSCy Schubert	    ;;
1952b15cb3dSCy Schubert	esac
1962b15cb3dSCy Schubert
1972b15cb3dSCy Schubert	# Should be OK, mostly...
1982b15cb3dSCy Schubert	C=`echo $c | sed -e 'y/abcdefghijklmnopqrstuvwxyz-/ABCDEFGHIJKLMNOPQRSTUVWXYZ_/'`
1992b15cb3dSCy Schubert	# echo "c: <$c>, C: <$C>, DB: <$DB>, DL: <$DL>, DS: <$DS>" >&2
2002b15cb3dSCy Schubert
2012b15cb3dSCy Schubert	case "$d" in
2022b15cb3dSCy Schubert	 bin)
2032b15cb3dSCy Schubert	    eval ${C}_DB=$c
2042b15cb3dSCy Schubert	    eval ${C}_DL=
2052b15cb3dSCy Schubert	    eval ${C}_DS=
2062b15cb3dSCy Schubert	    eval ${C}_NI=
2072b15cb3dSCy Schubert	    ;;
2082b15cb3dSCy Schubert	 libexec)
2092b15cb3dSCy Schubert	    eval ${C}_DB=
2102b15cb3dSCy Schubert	    eval ${C}_DL=$c
2112b15cb3dSCy Schubert	    eval ${C}_DS=
2122b15cb3dSCy Schubert	    eval ${C}_NI=
2132b15cb3dSCy Schubert	    ;;
2142b15cb3dSCy Schubert	 noinst)
2152b15cb3dSCy Schubert	    eval ${C}_DB=
2162b15cb3dSCy Schubert	    eval ${C}_DL=
2172b15cb3dSCy Schubert	    eval ${C}_DS=
2182b15cb3dSCy Schubert	    eval ${C}_NI=$c
2192b15cb3dSCy Schubert	    ;;
2202b15cb3dSCy Schubert	 sbin)
2212b15cb3dSCy Schubert	    eval ${C}_DB=
2222b15cb3dSCy Schubert	    eval ${C}_DL=
2232b15cb3dSCy Schubert	    eval ${C}_DS=$c
2242b15cb3dSCy Schubert	    eval ${C}_NI=
2252b15cb3dSCy Schubert	    ;;
2262b15cb3dSCy Schubert	 *) echo "$0: installdir <$d> must be bin, sbin, libexec, or noinst" >&2
2272b15cb3dSCy Schubert	    exit 1
2282b15cb3dSCy Schubert	    ;;
2292b15cb3dSCy Schubert	esac
2302b15cb3dSCy Schubert	eval ${C}_MS=$s
2312b15cb3dSCy Schubert
2322b15cb3dSCy Schubert	# echo "<$c> gets installed in <$d> with a <$s> manpage suffix" >&2
2332b15cb3dSCy Schubert	# echo "${C}_DB is <`eval echo '$'${C}_DB`>" >&2
2342b15cb3dSCy Schubert	# echo "${C}_DL is <`eval echo '$'${C}_DL`>" >&2
2352b15cb3dSCy Schubert	# echo "${C}_DS is <`eval echo '$'${C}_DS`>" >&2
2362b15cb3dSCy Schubert	# echo "${C}_NI is <`eval echo '$'${C}_NI`>" >&2
2372b15cb3dSCy Schubert	# echo "${C}_MS is <`eval echo '$'${C}_MS`>" >&2
2382b15cb3dSCy Schubert	echo "${C}_DB=`eval echo '$'${C}_DB`"
2392b15cb3dSCy Schubert	echo "${C}_DL=`eval echo '$'${C}_DL`"
2402b15cb3dSCy Schubert	echo "${C}_DS=`eval echo '$'${C}_DS`"
2412b15cb3dSCy Schubert	echo "${C}_NI=`eval echo '$'${C}_NI`"
2422b15cb3dSCy Schubert	echo "${C}_MS=`eval echo '$'${C}_MS`"
2432b15cb3dSCy Schubert
2442b15cb3dSCy Schubert	touch $sdir/genLocInfo.rc0
2452b15cb3dSCy Schubert    else
2462b15cb3dSCy Schubert	break
2472b15cb3dSCy Schubert    fi
2482b15cb3dSCy Schubertdone < $LF
2492b15cb3dSCy SchubertIFS=$oIFS
2502b15cb3dSCy Schubert
2512b15cb3dSCy Schubertif test -f $sdir/genLocInfo.rc1
2522b15cb3dSCy Schubertthen
2532b15cb3dSCy Schubert    rm $sdir/genLocInfo.rc?
2542b15cb3dSCy Schubert    exit 1
2552b15cb3dSCy Schubertfi
2562b15cb3dSCy Schubert
2572b15cb3dSCy Schubertif test -f $sdir/genLocInfo.rc0
2582b15cb3dSCy Schubertthen
2592b15cb3dSCy Schubert    rm $sdir/genLocInfo.rc?
2602b15cb3dSCy Schubert    echo 'GENLOCINFO=OK'
2612b15cb3dSCy Schubert    exit 0
2622b15cb3dSCy Schubertfi
2632b15cb3dSCy Schubert
2642b15cb3dSCy Schubertexit 1
265