3
# Licensed to the Apache Software Foundation (ASF) under one or more
4
# contributor license agreements. See the NOTICE file distributed with
5
# this work for additional information regarding copyright ownership.
6
# The ASF licenses this file to You under the Apache License, Version 2.0
7
# (the "License"); you may not use this file except in compliance with
8
# the License. You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
19
# buildinfo.sh -- Determine Build Information
20
# Initially written by Ralf S. Engelschall <rse@apache.org>
21
# for the Apache's Autoconf-style Interface (APACI)
24
# argument line handling
27
if [ $# -ne 1 -a $# -ne 2 ]; then
30
if [ $# -eq 2 -a "x$1" != "x-n" ]; then
33
if [ "x$error" = "xyes" ]; then
34
echo "$0:Error: invalid argument line"
35
echo "$0:Usage: $0 [-n] <format-string>"
36
echo "Where <format-string> can contain:"
37
echo " %u ...... substituted by determined username (foo)"
38
echo " %h ...... substituted by determined hostname (bar)"
39
echo " %d ...... substituted by determined domainname (.com)"
40
echo " %D ...... substituted by determined day (DD)"
41
echo " %M ...... substituted by determined month (MM)"
42
echo " %Y ...... substituted by determined year (YYYYY)"
43
echo " %m ...... substituted by determined monthname (Jan)"
69
if [ "x$username" = "x" ]; then
71
if [ "x$username" = "x" ]; then
72
username="`(whoami) 2>/dev/null |\
73
awk '{ printf("%s", $1); }'`"
74
if [ "x$username" = "x" ]; then
75
username="`(who am i) 2>/dev/null |\
76
awk '{ printf("%s", $1); }'`"
77
if [ "x$username" = "x" ]; then
85
# determine hostname and domainname
87
hostname="`(uname -n) 2>/dev/null |\
88
awk '{ printf("%s", $1); }'`"
89
if [ "x$hostname" = "x" ]; then
90
hostname="`(hostname) 2>/dev/null |\
91
awk '{ printf("%s", $1); }'`"
92
if [ "x$hostname" = "x" ]; then
98
domainname=".`echo $hostname | cut -d. -f2-`"
99
hostname="`echo $hostname | cut -d. -f1`"
102
if [ "x$domainname" = "x" ]; then
103
if [ -f /etc/resolv.conf ]; then
104
domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
105
sed -e 's/.*domain//' \
106
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
107
-e 's/^\.//' -e 's/^/./' |\
108
awk '{ printf("%s", $1); }'`"
109
if [ "x$domainname" = "x" ]; then
110
domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
111
sed -e 's/.*search//' \
112
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
113
-e 's/ .*//' -e 's/ .*//' \
114
-e 's/^\.//' -e 's/^/./' |\
115
awk '{ printf("%s", $1); }'`"
121
# determine current time
123
time_day="`date '+%d' | awk '{ printf("%s", $1); }'`"
124
time_month="`date '+%m' | awk '{ printf("%s", $1); }'`"
125
time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`"
126
if [ "x$time_year" = "x" ]; then
127
time_year="`date '+%y' | awk '{ printf("%s", $1); }'`"
129
[5-9][0-9]) time_year="19$time_year" ;;
130
[0-4][0-9]) time_year="20$time_year" ;;
134
1|01) time_monthname='Jan' ;;
135
2|02) time_monthname='Feb' ;;
136
3|03) time_monthname='Mar' ;;
137
4|04) time_monthname='Apr' ;;
138
5|05) time_monthname='May' ;;
139
6|06) time_monthname='Jun' ;;
140
7|07) time_monthname='Jul' ;;
141
8|08) time_monthname='Aug' ;;
142
9|09) time_monthname='Sep' ;;
143
10) time_monthname='Oct' ;;
144
11) time_monthname='Nov' ;;
145
12) time_monthname='Dec' ;;
149
# create result string
151
if [ "x$newline" = "xyes" ]; then
152
echo $format_string |\
153
sed -e "s;%u;$username;g" \
154
-e "s;%h;$hostname;g" \
155
-e "s;%d;$domainname;g" \
156
-e "s;%D;$time_day;g" \
157
-e "s;%M;$time_month;g" \
158
-e "s;%Y;$time_year;g" \
159
-e "s;%m;$time_monthname;g"
161
echo "${format_string}&" |\
162
sed -e "s;%u;$username;g" \
163
-e "s;%h;$hostname;g" \
164
-e "s;%d;$domainname;g" \
165
-e "s;%D;$time_day;g" \
166
-e "s;%M;$time_month;g" \
167
-e "s;%Y;$time_year;g" \
168
-e "s;%m;$time_monthname;g" |\
169
awk '-F&' '{ printf("%s", $1); }'