home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / buildinfo.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-09-16  |  4.4 KB  |  161 lines

  1. #!/bin/sh
  2. ##
  3. ##  buildinfo.sh -- Determine Build Information
  4. ##  Written by Ralf S. Engelschall <rse@apache.org>
  5. ##  for the Apache's Autoconf-style Interface (APACI) 
  6. ##
  7. #
  8. # This script falls under the Apache License.
  9. # See http://www.apache.org/docs/LICENSE
  10.  
  11.  
  12. #
  13. #   argument line handling
  14. #
  15. error=no
  16. if [ $# -ne 1 -a $# -ne 2 ]; then
  17.     error=yes
  18. fi
  19. if [ $# -eq 2 -a ".$1" != ".-n" ]; then
  20.     error=yes
  21. fi
  22. if [ $error = yes ]; then
  23.     echo "$0:Error: invalid argument line"
  24.     echo "$0:Usage: $0 [-n] <format-string>"
  25.     echo "Where <format-string> can contain:"
  26.     echo "   %u ...... substituted by determined username    (foo)"
  27.     echo "   %h ...... substituted by determined hostname    (bar)"
  28.     echo "   %d ...... substituted by determined domainname  (.com)"
  29.     echo "   %D ...... substituted by determined day         (DD)"
  30.     echo "   %M ...... substituted by determined month       (MM)"
  31.     echo "   %Y ...... substituted by determined year        (YYYYY)"
  32.     echo "   %m ...... substituted by determined monthname   (Jan)"
  33.     exit 1
  34. fi
  35. if [ $# -eq 2 ]; then
  36.     newline=no
  37.     format_string="$2"
  38. else
  39.     newline=yes
  40.     format_string="$1"
  41. fi
  42.  
  43. #
  44. #   initialization
  45. #
  46. username=''
  47. hostname=''
  48. domainname=''
  49. time_day=''
  50. time_month=''
  51. time_year=''
  52. time_monthname=''
  53.  
  54. #
  55. #   determine username
  56. #
  57. username="$LOGNAME"
  58. if [ ".$username" = . ]; then
  59.     username="$USER"
  60.     if [ ".$username" = . ]; then
  61.         username="`whoami 2>/dev/null |\
  62.                    awk '{ printf("%s", $1); }'`"
  63.         if [ ".$username" = . ]; then
  64.             username="`who am i 2>/dev/null |\
  65.                        awk '{ printf("%s", $1); }'`"
  66.             if [ ".$username" = . ]; then
  67.                 username='unknown'
  68.             fi
  69.         fi
  70.     fi
  71. fi
  72.  
  73. #
  74. #   determine hostname and domainname
  75. #
  76. hostname="`uname -n 2>/dev/null |\
  77.            awk '{ printf("%s", $1); }'`"
  78. if [ ".$hostname" = . ]; then
  79.     hostname="`hostname 2>/dev/null |\
  80.                awk '{ printf("%s", $1); }'`"
  81.     if [ ".$hostname" = . ]; then
  82.         hostname='unknown'
  83.     fi
  84. fi
  85. case $hostname in
  86.     *.* )
  87.         domainname=".`echo $hostname | cut -d. -f2-`"
  88.         hostname="`echo $hostname | cut -d. -f1`"
  89.         ;;
  90. esac
  91. if [ ".$domainname" = . ]; then
  92.     if [ -f /etc/resolv.conf ]; then
  93.         domainname="`egrep '^[     ]*domain' /etc/resolv.conf | head -1 |\
  94.                      sed -e 's/.*domain//' \
  95.                          -e 's/^[     ]*//' -e 's/^ *//' -e 's/^    *//' \
  96.                          -e 's/^\.//' -e 's/^/./' |\
  97.                      awk '{ printf("%s", $1); }'`"
  98.         if [ ".$domainname" = . ]; then
  99.             domainname="`egrep '^[     ]*search' /etc/resolv.conf | head -1 |\
  100.                          sed -e 's/.*search//' \
  101.                              -e 's/^[     ]*//' -e 's/^ *//' -e 's/^    *//' \
  102.                              -e 's/ .*//' -e 's/    .*//' \
  103.                              -e 's/^\.//' -e 's/^/./' |\
  104.                          awk '{ printf("%s", $1); }'`"
  105.         fi
  106.     fi
  107. fi
  108.  
  109. #
  110. #   determine current time
  111. #
  112. time_day="`date '+%d' | awk '{ printf("%s", $1); }'`"
  113. time_month="`date '+%m' | awk '{ printf("%s", $1); }'`"
  114. time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
  115. if test ".$time_year" = .; then
  116.     time_year="`date '+%y' | awk '{ printf("%s", $1); }'`"
  117.     case $time_year in
  118.         9[0-9]*) time_year="19$time_year" ;;
  119.               *) time_year="20$time_year" ;;
  120.     esac
  121. fi
  122. case $time_month in
  123.     1|01) time_monthname='Jan' ;;
  124.     2|02) time_monthname='Feb' ;;
  125.     3|03) time_monthname='Mar' ;;
  126.     4|04) time_monthname='Apr' ;;
  127.     5|05) time_monthname='May' ;;
  128.     6|06) time_monthname='Jun' ;;
  129.     7|07) time_monthname='Jul' ;;
  130.     8|08) time_monthname='Aug' ;;
  131.     9|09) time_monthname='Sep' ;;
  132.       10) time_monthname='Oct' ;;
  133.       11) time_monthname='Nov' ;;
  134.       12) time_monthname='Dec' ;;
  135. esac
  136.  
  137. #
  138. #   create result string
  139. #
  140. if [ ".$newline" = .yes ]; then
  141.     echo $format_string |\
  142.     sed -e "s;%u;$username;g" \
  143.         -e "s;%h;$hostname;g" \
  144.         -e "s;%d;$domainname;g" \
  145.         -e "s;%D;$time_day;g" \
  146.         -e "s;%M;$time_month;g" \
  147.         -e "s;%Y;$time_year;g" \
  148.         -e "s;%m;$time_monthname;g"
  149. else
  150.     echo "${format_string}&" |\
  151.     sed -e "s;%u;$username;g" \
  152.         -e "s;%h;$hostname;g" \
  153.         -e "s;%d;$domainname;g" \
  154.         -e "s;%D;$time_day;g" \
  155.         -e "s;%M;$time_month;g" \
  156.         -e "s;%Y;$time_year;g" \
  157.         -e "s;%m;$time_monthname;g" |\
  158.     awk '-F&' '{ printf("%s", $1); }'
  159. fi
  160.  
  161.