update Tue May 18 00:37:00 PDT 2010
[pkgsrc.git] / mk / bulk / post-build-conf
1 # $NetBSD: post-build-conf,v 1.14 2007/03/06 10:57:11 rillig Exp $
2 #
3
4 # This file is included after the build.conf file by the "build" and
5 # "pre-build" scripts. It provides functions for printing, checking and
6 # exporting the configuration variables.
7
8 # Note: All functions whose names start with "pbc_" are considered private
9 # to this file. The "pbc" prefix is an abbreviation for "post-build-conf".
10
11 # usage: pbc_showvar varname
12 pbc_showvar() {
13         eval "pbc_isset=\${$1+set}"
14         case $pbc_isset in
15         "set")  eval "fnv_val=\${$1-}"
16                 printf "   %-25s = %s\\n" "$1" "${fnv_val}"
17                 ;;
18         *)      printf "   %-25s (undefined)\\n" "$1"
19                 ;;
20         esac
21 }
22
23 # usage: pbc_section title varname...
24 pbc_section() {
25         printf "%s\\n" "$1"
26         shift
27         for pbc_var in "$@"; do
28                 pbc_showvar "${pbc_var}"
29         done
30         printf "\\n"
31 }
32
33 # usage: show_config_vars
34 show_config_vars() {
35         pbc_section "System information" \
36                 osrev BULK_BUILD_CONF USR_PKGSRC MAKECONF
37         pbc_section "Getting distfiles" \
38                 PRUNEDISTFILES ftp_proxy http_proxy
39         pbc_section "Building the packages" \
40                 PKGLIST NICE_LEVEL
41         pbc_section "Generating the report" \
42                 ADMIN ADMINSIG \
43                 REPORTS_URL REPORTS_DIR \
44                 REPORT_BASEDIR REPORT_HTML_FILE REPORT_TXT_FILE
45         pbc_section "Uploading binary packages" \
46                 UPDATE_VULNERABILITY_LIST PRUNEPACKAGES MKSUMS SIGN_AS \
47                 RSYNC_DST RSYNC_OPTS
48 }
49
50 # usage: export_config_vars
51 export_config_vars() {
52         export osrev BULK_BUILD_CONF USR_PKGSRC
53         export PRUNEDISTFILES ftp_proxy http_proxy
54         export PKGLIST NICE_LEVEL ADMIN ADMINSIG
55         export UPDATE_VULNERABILITY_LIST PRUNEPACKAGES MKSUMS SIGN_AS
56         export RSYNC_DST RSYNC_OPTS
57         case ${MAKECONF+set} in
58         "set")  export MAKECONF;;
59         esac
60 }
61
62 # usage: pbc_die error-message
63 pbc_die() {
64         exec 1>&2
65         printf "error: %s\\n" "$@"
66         printf "       Please check your bulk build configuration file:\\n"
67         case ${BULK_BUILD_CONF+set} in
68         "set")  printf "       %s\\n" "${BULK_BUILD_CONF}"
69         esac
70         exit 1
71 }
72
73 # usage: pbc_checkyesno varname
74 pbc_checkyesno() {
75         eval "pbc_val=\${$1-}"
76         case $pbc_val in
77         [Yy][Ee][Ss]|[Nn][Oo]) ;;
78         *)      pbc_die "$1 must be set to one of YES, yes, NO, no.";;
79         esac
80 }
81
82 # usage: pbc_checkpathname varname
83 pbc_checkpathname() {
84         eval "pbc_val=\${$1-}"
85
86         case $pbc_val in
87         /*)     ;;
88         *)      pbc_die "$1 must be an absolute pathname.";;
89         esac
90 }
91
92 # usage: pbc_checkbasename varname
93 pbc_checkbasename() {
94         eval "pbc_val=\${$1-}"
95
96         case $pbc_val in
97         */*)    pbc_die "$1 must not contain slashes.";;
98         esac
99 }
100
101 # usage: pbc_checkexistingfile varname
102 pbc_checkexistingfile() {
103
104         pbc_checkpathname "$1"
105
106         eval "pbc_val=\${$1-}"
107
108         test -f "${pbc_val}" \
109         || pbc_die "$1 must be the name of an existing file."
110 }
111
112 # usage: pbc_checkexistingdir varname
113 pbc_checkexistingdir() {
114
115         pbc_checkpathname "$1"
116
117         eval "pbc_val=\${$1-}"
118
119         test -d "${pbc_val}" \
120         || pbc_die "$1 must be the name of an existing directory."
121 }
122
123 # usage: pbc_checkurl varname
124 pbc_checkurl() {
125         eval "pbc_val=\${$1-}"
126
127         case $pbc_val in
128         file:///*|ftp://*|http://*)
129                 ;;
130         *)      pbc_die "$1 is not a valid URL.";;
131         esac
132 }
133
134 # usage: pbc_checknonempty varname
135 pbc_checknonempty() {
136         eval "pbc_isset=\${$1+set}"
137         eval "pbc_val=\${$1-}"
138
139         case $pbc_isset in
140         "set")  case $pbc_val in
141                 "")     pbc_die "$1 must be non-empty.";;
142                 esac;;
143         *)      pbc_die "$1 must be defined and non-empty.";;
144         esac
145 }
146
147 # usage: pbc_checkdefined varname
148 pbc_checkdefined() {
149         eval "pbc_val=\${$1+set}"
150
151         case $pbc_val in
152         "set")  ;;
153         *)      pbc_die "$1 must be defined.";;
154         esac
155 }
156
157 # usage: check_config_vars
158 check_config_vars() {
159
160         case ${FTP+set},${REPORTS_DIR+set} in
161         set,set)
162                 pbc_die "FTP and REPORTS_DIR must not be set both.";;
163         esac
164
165         # section "System information"
166         pbc_checknonempty osrev
167         pbc_checkexistingfile BULK_BUILD_CONF
168         pbc_checkexistingdir USR_PKGSRC
169         case ${MAKECONF+set} in
170         "set")  pbc_checkexistingfile MAKECONF;;
171         esac
172
173         # section "Getting distfiles"
174         case ${PRUNEDISTFILES+set} in
175         "set")  pbc_checkyesno PRUNEDISTFILES
176         esac
177         # no checks for ftp_proxy
178         # no checks for http_proxy
179
180         # section "Building the packages"
181         # no checks for PKGLIST
182         # no checks for NICE_LEVEL
183
184         # section "Generating the report"
185         # no checks for ADMIN
186         # no checks for ADMINSIG
187         pbc_checkurl REPORTS_URL
188         pbc_checkpathname REPORTS_DIR
189         pbc_checkbasename REPORT_BASEDIR
190         pbc_checkbasename REPORT_HTML_FILE
191         pbc_checkbasename REPORT_TXT_FILE
192
193
194         # section "Uploading binary packages"
195         pbc_checkyesno UPDATE_VULNERABILITY_LIST
196         case ${PRUNEPACKAGES+set} in
197         "set")  pbc_checkyesno PRUNEPACKAGES
198         esac
199         pbc_checkyesno MKSUMS
200         # no checks for SIGN_AS
201         # no checks for RSYNC_DST
202         # no checks for RSYNC_OPTS
203 }