|
Packit |
90a5c9 |
#!/bin/sh
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
# contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
# this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
# (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
# the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
# See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
# limitations under the License.
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# buildinfo.sh -- Determine Build Information
|
|
Packit |
90a5c9 |
# Initially written by Ralf S. Engelschall <rse@apache.org>
|
|
Packit |
90a5c9 |
# for the Apache's Autoconf-style Interface (APACI)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# argument line handling
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
error=no
|
|
Packit |
90a5c9 |
if [ $# -ne 1 -a $# -ne 2 ]; then
|
|
Packit |
90a5c9 |
error=yes
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
if [ $# -eq 2 -a "x$1" != "x-n" ]; then
|
|
Packit |
90a5c9 |
error=yes
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
if [ "x$error" = "xyes" ]; then
|
|
Packit |
90a5c9 |
echo "$0:Error: invalid argument line"
|
|
Packit |
90a5c9 |
echo "$0:Usage: $0 [-n] <format-string>"
|
|
Packit |
90a5c9 |
echo "Where <format-string> can contain:"
|
|
Packit |
90a5c9 |
echo " %u ...... substituted by determined username (foo)"
|
|
Packit |
90a5c9 |
echo " %h ...... substituted by determined hostname (bar)"
|
|
Packit |
90a5c9 |
echo " %d ...... substituted by determined domainname (.com)"
|
|
Packit |
90a5c9 |
echo " %D ...... substituted by determined day (DD)"
|
|
Packit |
90a5c9 |
echo " %M ...... substituted by determined month (MM)"
|
|
Packit |
90a5c9 |
echo " %Y ...... substituted by determined year (YYYYY)"
|
|
Packit |
90a5c9 |
echo " %m ...... substituted by determined monthname (Jan)"
|
|
Packit |
90a5c9 |
exit 1
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
if [ $# -eq 2 ]; then
|
|
Packit |
90a5c9 |
newline=no
|
|
Packit |
90a5c9 |
format_string="$2"
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
newline=yes
|
|
Packit |
90a5c9 |
format_string="$1"
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# initialization
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
username=''
|
|
Packit |
90a5c9 |
hostname=''
|
|
Packit |
90a5c9 |
domainname=''
|
|
Packit |
90a5c9 |
time_day=''
|
|
Packit |
90a5c9 |
time_month=''
|
|
Packit |
90a5c9 |
time_year=''
|
|
Packit |
90a5c9 |
time_monthname=''
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# determine username
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
username="$LOGNAME"
|
|
Packit |
90a5c9 |
if [ "x$username" = "x" ]; then
|
|
Packit |
90a5c9 |
username="$USER"
|
|
Packit |
90a5c9 |
if [ "x$username" = "x" ]; then
|
|
Packit |
90a5c9 |
username="`(whoami) 2>/dev/null |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$username" = "x" ]; then
|
|
Packit |
90a5c9 |
username="`(who am i) 2>/dev/null |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$username" = "x" ]; then
|
|
Packit |
90a5c9 |
username='unknown'
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# determine hostname and domainname
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
hostname="`(uname -n) 2>/dev/null |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$hostname" = "x" ]; then
|
|
Packit |
90a5c9 |
hostname="`(hostname) 2>/dev/null |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$hostname" = "x" ]; then
|
|
Packit |
90a5c9 |
hostname='unknown'
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
case $hostname in
|
|
Packit |
90a5c9 |
*.* )
|
|
Packit |
90a5c9 |
domainname=".`echo $hostname | cut -d. -f2-`"
|
|
Packit |
90a5c9 |
hostname="`echo $hostname | cut -d. -f1`"
|
|
Packit |
90a5c9 |
;;
|
|
Packit |
90a5c9 |
esac
|
|
Packit |
90a5c9 |
if [ "x$domainname" = "x" ]; then
|
|
Packit |
90a5c9 |
if [ -f /etc/resolv.conf ]; then
|
|
Packit |
90a5c9 |
domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
|
|
Packit |
90a5c9 |
sed -e 's/.*domain//' \
|
|
Packit |
90a5c9 |
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
|
|
Packit |
90a5c9 |
-e 's/^\.//' -e 's/^/./' |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$domainname" = "x" ]; then
|
|
Packit |
90a5c9 |
domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
|
|
Packit |
90a5c9 |
sed -e 's/.*search//' \
|
|
Packit |
90a5c9 |
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
|
|
Packit |
90a5c9 |
-e 's/ .*//' -e 's/ .*//' \
|
|
Packit |
90a5c9 |
-e 's/^\.//' -e 's/^/./' |\
|
|
Packit |
90a5c9 |
awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# determine current time
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
time_day="`date '+%d' | awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
time_month="`date '+%m' | awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
if [ "x$time_year" = "x" ]; then
|
|
Packit |
90a5c9 |
time_year="`date '+%y' | awk '{ printf("%s", $1); }'`"
|
|
Packit |
90a5c9 |
case $time_year in
|
|
Packit |
90a5c9 |
[5-9][0-9]) time_year="19$time_year" ;;
|
|
Packit |
90a5c9 |
[0-4][0-9]) time_year="20$time_year" ;;
|
|
Packit |
90a5c9 |
esac
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
case $time_month in
|
|
Packit |
90a5c9 |
1|01) time_monthname='Jan' ;;
|
|
Packit |
90a5c9 |
2|02) time_monthname='Feb' ;;
|
|
Packit |
90a5c9 |
3|03) time_monthname='Mar' ;;
|
|
Packit |
90a5c9 |
4|04) time_monthname='Apr' ;;
|
|
Packit |
90a5c9 |
5|05) time_monthname='May' ;;
|
|
Packit |
90a5c9 |
6|06) time_monthname='Jun' ;;
|
|
Packit |
90a5c9 |
7|07) time_monthname='Jul' ;;
|
|
Packit |
90a5c9 |
8|08) time_monthname='Aug' ;;
|
|
Packit |
90a5c9 |
9|09) time_monthname='Sep' ;;
|
|
Packit |
90a5c9 |
10) time_monthname='Oct' ;;
|
|
Packit |
90a5c9 |
11) time_monthname='Nov' ;;
|
|
Packit |
90a5c9 |
12) time_monthname='Dec' ;;
|
|
Packit |
90a5c9 |
esac
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
# create result string
|
|
Packit |
90a5c9 |
#
|
|
Packit |
90a5c9 |
if [ "x$newline" = "xyes" ]; then
|
|
Packit |
90a5c9 |
echo $format_string |\
|
|
Packit |
90a5c9 |
sed -e "s;%u;$username;g" \
|
|
Packit |
90a5c9 |
-e "s;%h;$hostname;g" \
|
|
Packit |
90a5c9 |
-e "s;%d;$domainname;g" \
|
|
Packit |
90a5c9 |
-e "s;%D;$time_day;g" \
|
|
Packit |
90a5c9 |
-e "s;%M;$time_month;g" \
|
|
Packit |
90a5c9 |
-e "s;%Y;$time_year;g" \
|
|
Packit |
90a5c9 |
-e "s;%m;$time_monthname;g"
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
echo "${format_string}&" |\
|
|
Packit |
90a5c9 |
sed -e "s;%u;$username;g" \
|
|
Packit |
90a5c9 |
-e "s;%h;$hostname;g" \
|
|
Packit |
90a5c9 |
-e "s;%d;$domainname;g" \
|
|
Packit |
90a5c9 |
-e "s;%D;$time_day;g" \
|
|
Packit |
90a5c9 |
-e "s;%M;$time_month;g" \
|
|
Packit |
90a5c9 |
-e "s;%Y;$time_year;g" \
|
|
Packit |
90a5c9 |
-e "s;%m;$time_monthname;g" |\
|
|
Packit |
90a5c9 |
awk '-F&' '{ printf("%s", $1); }'
|
|
Packit |
90a5c9 |
fi
|
|
Packit |
90a5c9 |
|