Mon, 28 Jan 2013 17:37:18 +0100
Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.
michael@428 | 1 | ## |
michael@428 | 2 | ## OpenPKG Software Stack Generation |
michael@428 | 3 | ## Copyright (c) 2010-2012 OpenPKG GmbH <http://openpkg.com/> |
michael@428 | 4 | ## |
michael@428 | 5 | ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. |
michael@428 | 6 | ## All rights reserved. Licenses which grant limited permission to use, |
michael@428 | 7 | ## copy, modify and distribute this software are available from the |
michael@428 | 8 | ## OpenPKG GmbH. |
michael@428 | 9 | ## |
michael@428 | 10 | ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
michael@428 | 11 | ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@428 | 12 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@428 | 13 | ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@428 | 14 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@428 | 15 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@428 | 16 | ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@428 | 17 | ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@428 | 18 | ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@428 | 19 | ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@428 | 20 | ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@428 | 21 | ## SUCH DAMAGE. |
michael@428 | 22 | ## |
michael@428 | 23 | |
michael@428 | 24 | # configuration |
michael@428 | 25 | openpkg="${OPENPKG_PREFIX}/bin/openpkg" |
michael@428 | 26 | curl="${OPENPKG_PREFIX}/bin/openpkg curl" |
michael@428 | 27 | shtool="${OPENPKG_PREFIX}/lib/openpkg/shtool" |
michael@428 | 28 | |
michael@428 | 29 | ## |
michael@428 | 30 | ## COMMAND LINE PARSING |
michael@428 | 31 | ## |
michael@428 | 32 | |
michael@428 | 33 | str_usage="[-h|--help] [-v|--verbose <level>] [-o|--output <dir>] [-D|--define <name>=<value> ...] [-u|--unversioned] [-q|--query] <name>.stk" |
michael@428 | 34 | arg_spec="1=" |
michael@428 | 35 | opt_spec="h.v:o:D+u.q." |
michael@428 | 36 | opt_alias="h:help,v:verbose,o:output,D:define,u:unversioned,q:query" |
michael@428 | 37 | opt_h=no |
michael@428 | 38 | opt_v=4 |
michael@428 | 39 | opt_o="." |
michael@428 | 40 | opt_D="" |
michael@428 | 41 | opt_u=no |
michael@428 | 42 | opt_q=no |
michael@428 | 43 | |
michael@428 | 44 | # parse argument specification string |
michael@428 | 45 | eval `echo $arg_spec |\ |
michael@428 | 46 | sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
michael@428 | 47 | |
michael@428 | 48 | # parse option specification string |
michael@428 | 49 | eval `echo $opt_spec |\ |
michael@428 | 50 | sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
michael@428 | 51 | |
michael@428 | 52 | # parse option alias string |
michael@428 | 53 | eval `echo $opt_alias |\ |
michael@428 | 54 | sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'` |
michael@428 | 55 | |
michael@428 | 56 | # interate over argument line |
michael@428 | 57 | opt_PREV='' |
michael@428 | 58 | while [ $# -gt 0 ]; do |
michael@428 | 59 | # special option stops processing |
michael@428 | 60 | if [ ".$1" = ".--" ]; then |
michael@428 | 61 | shift |
michael@428 | 62 | break |
michael@428 | 63 | fi |
michael@428 | 64 | |
michael@428 | 65 | # determine option and argument |
michael@428 | 66 | opt_ARG_OK=no |
michael@428 | 67 | if [ ".$opt_PREV" != . ]; then |
michael@428 | 68 | # merge previous seen option with argument |
michael@428 | 69 | opt_OPT="$opt_PREV" |
michael@428 | 70 | opt_ARG="$1" |
michael@428 | 71 | opt_ARG_OK=yes |
michael@428 | 72 | opt_PREV='' |
michael@428 | 73 | else |
michael@428 | 74 | # split argument into option and argument |
michael@428 | 75 | case "$1" in |
michael@428 | 76 | --[a-zA-Z0-9]*=*) |
michael@428 | 77 | eval `echo "x$1" |\ |
michael@428 | 78 | sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'` |
michael@428 | 79 | opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
michael@428 | 80 | eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
michael@428 | 81 | ;; |
michael@428 | 82 | --[a-zA-Z0-9]*) |
michael@428 | 83 | opt_OPT=`echo "x$1" | cut -c4-` |
michael@428 | 84 | opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
michael@428 | 85 | eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
michael@428 | 86 | opt_ARG='' |
michael@428 | 87 | ;; |
michael@428 | 88 | -[a-zA-Z0-9]*) |
michael@428 | 89 | eval `echo "x$1" |\ |
michael@428 | 90 | sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
michael@428 | 91 | -e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
michael@428 | 92 | ;; |
michael@428 | 93 | -[a-zA-Z0-9]) |
michael@428 | 94 | opt_OPT=`echo "x$1" | cut -c3-` |
michael@428 | 95 | opt_ARG='' |
michael@428 | 96 | ;; |
michael@428 | 97 | *) |
michael@428 | 98 | break |
michael@428 | 99 | ;; |
michael@428 | 100 | esac |
michael@428 | 101 | fi |
michael@428 | 102 | |
michael@428 | 103 | # eat up option |
michael@428 | 104 | shift |
michael@428 | 105 | |
michael@428 | 106 | # determine whether option needs an argument |
michael@428 | 107 | eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
michael@428 | 108 | if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then |
michael@428 | 109 | if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then |
michael@428 | 110 | opt_PREV="$opt_OPT" |
michael@428 | 111 | continue |
michael@428 | 112 | fi |
michael@428 | 113 | fi |
michael@428 | 114 | |
michael@428 | 115 | # process option |
michael@428 | 116 | case $opt_MODE in |
michael@428 | 117 | '.' ) |
michael@428 | 118 | # boolean option |
michael@428 | 119 | eval "opt_${opt_OPT}=yes" |
michael@428 | 120 | ;; |
michael@428 | 121 | ':' ) |
michael@428 | 122 | # option with argument (multiple occurances override) |
michael@428 | 123 | eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
michael@428 | 124 | ;; |
michael@428 | 125 | '+' ) |
michael@428 | 126 | # option with argument (multiple occurances append) |
michael@428 | 127 | eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" |
michael@428 | 128 | ;; |
michael@428 | 129 | * ) |
michael@428 | 130 | echo "$0: ERROR: unknown option: \`$opt_OPT'" 1>&2 |
michael@428 | 131 | exit 1 |
michael@428 | 132 | ;; |
michael@428 | 133 | esac |
michael@428 | 134 | done |
michael@428 | 135 | if [ ".$opt_PREV" != . ]; then |
michael@428 | 136 | echo "$0: ERROR: missing argument to option \`$opt_PREV'" 1>&2 |
michael@428 | 137 | exit 1 |
michael@428 | 138 | fi |
michael@428 | 139 | |
michael@428 | 140 | # process help option |
michael@428 | 141 | if [ ".$opt_h" = .yes ]; then |
michael@428 | 142 | echo "Usage: $0 $str_usage" |
michael@428 | 143 | exit 0 |
michael@428 | 144 | fi |
michael@428 | 145 | |
michael@428 | 146 | # complain about incorrect number of arguments |
michael@428 | 147 | case $arg_MODE in |
michael@428 | 148 | '=' ) |
michael@428 | 149 | if [ $# -ne $arg_NUMS ]; then |
michael@428 | 150 | echo "$0: ERROR: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
michael@428 | 151 | exit 1 |
michael@428 | 152 | fi |
michael@428 | 153 | ;; |
michael@428 | 154 | '+' ) |
michael@428 | 155 | if [ $# -lt $arg_NUMS ]; then |
michael@428 | 156 | echo "$0: ERROR: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
michael@428 | 157 | exit 1 |
michael@428 | 158 | fi |
michael@428 | 159 | ;; |
michael@428 | 160 | esac |
michael@428 | 161 | |
michael@428 | 162 | ## |
michael@428 | 163 | ## HELPER FUNCTIONS |
michael@428 | 164 | ## |
michael@428 | 165 | |
michael@428 | 166 | # helper function for graceful termination |
michael@428 | 167 | die () { |
michael@428 | 168 | echo "$0: ERROR: $*" |
michael@428 | 169 | exit 1 |
michael@428 | 170 | } |
michael@428 | 171 | |
michael@428 | 172 | # helper function for verbose messages |
michael@428 | 173 | verbose () { |
michael@428 | 174 | lvl="$1" |
michael@428 | 175 | msg="$2" |
michael@428 | 176 | if [ $opt_v -ge $lvl ]; then |
michael@428 | 177 | case "$lvl" in |
michael@428 | 178 | 1 ) str_prefix="**" ;; |
michael@428 | 179 | 2 ) str_prefix="++" ;; |
michael@428 | 180 | 3 ) str_prefix="--" ;; |
michael@428 | 181 | 4 ) str_prefix=".." ;; |
michael@428 | 182 | esac |
michael@428 | 183 | echo "${str_prefix} ${msg}" |
michael@428 | 184 | fi |
michael@428 | 185 | } |
michael@428 | 186 | |
michael@428 | 187 | # expand macros |
michael@428 | 188 | macro_expand () { |
michael@428 | 189 | stk="$1" |
michael@428 | 190 | |
michael@428 | 191 | # load all options and their default values |
michael@428 | 192 | options="" |
michael@428 | 193 | for option in `sed <$stk \ |
michael@428 | 194 | -e "1,/^%options/d" -e '/^%/,$d' \ |
michael@428 | 195 | -e 's/#.*$//' -e 's/^ *//' -e 's/ *$//' -e '/^ *$/d' \ |
michael@428 | 196 | -e 's; *[^ ]*$;;'`; do |
michael@428 | 197 | options="$options $option" |
michael@428 | 198 | done |
michael@428 | 199 | eval `sed <$stk \ |
michael@428 | 200 | -e "1,/^%options/d" -e '/^%/,$d' \ |
michael@428 | 201 | -e 's/#.*$//' -e 's/^ *//' -e '/^ *$/d' \ |
michael@428 | 202 | -e 's:^\([^ ]*\) *\([^ ]*\)$:option_\1="\2";:'` |
michael@428 | 203 | |
michael@428 | 204 | # override options with defined values |
michael@428 | 205 | for define in $opt_D; do |
michael@428 | 206 | name=`echo "$define" | sed -e 's;=.*$;;'` |
michael@428 | 207 | value=`echo "$define" | sed -e 's;^.*=;;'` |
michael@428 | 208 | eval "exists=\"\${option_${name}}\"" |
michael@428 | 209 | if [ ".$exists" = . ]; then |
michael@428 | 210 | die "definition of not-existing option \"$name\"" |
michael@428 | 211 | fi |
michael@428 | 212 | eval "option_${name}=\"${value}\"" |
michael@428 | 213 | done |
michael@428 | 214 | |
michael@428 | 215 | # expand macros |
michael@428 | 216 | cmd="sed" |
michael@428 | 217 | for name in $options; do |
michael@428 | 218 | eval "value=\"\${option_${name}}\"" |
michael@428 | 219 | cmd="$cmd -e 's;%{[?]$name:\\([^}]*\\)};\1;g'" |
michael@428 | 220 | cmd="$cmd -e 's;%{![?]$name:\\([^}]*\\)};;g'" |
michael@428 | 221 | cmd="$cmd -e 's;%{$name};$value;g'" |
michael@428 | 222 | done |
michael@428 | 223 | cmd="$cmd -e 's;%{[?][^:}]*:[^}]*};;g'" |
michael@428 | 224 | cmd="$cmd -e 's;%{![?][^:}]*:\([^}]*\)};\1;g'" |
michael@428 | 225 | eval "$cmd" |
michael@428 | 226 | } |
michael@428 | 227 | |
michael@428 | 228 | # extract macro-expanded header |
michael@428 | 229 | header () { |
michael@428 | 230 | stk="$1" |
michael@428 | 231 | hdr="$2" |
michael@428 | 232 | exists=`egrep "^${hdr}" $stk` |
michael@428 | 233 | if [ ".$exists" != . ]; then |
michael@428 | 234 | egrep "^${hdr}:" $stk | \ |
michael@428 | 235 | sed -e 's;^[^:]*: *;;' -e 's/#.*$//' -e 's/^ *//' -e 's/ *$//' -e '/^ *$/d' | \ |
michael@428 | 236 | macro_expand "$stk" |
michael@428 | 237 | fi |
michael@428 | 238 | } |
michael@428 | 239 | |
michael@428 | 240 | # extract macro-expanded section |
michael@428 | 241 | section () { |
michael@428 | 242 | stk="$1" |
michael@428 | 243 | sec="$2" |
michael@428 | 244 | exists=`egrep "^%${sec}" $stk` |
michael@428 | 245 | if [ ".$exists" != . ]; then |
michael@428 | 246 | sed <$stk \ |
michael@428 | 247 | -e "1,/^%${sec}/d" -e '/^%/,$d' \ |
michael@428 | 248 | -e 's/#.*$//' -e 's/^ *//' -e 's/ *$//' -e '/^ *$/d' | \ |
michael@428 | 249 | macro_expand "$stk" |
michael@428 | 250 | fi |
michael@428 | 251 | } |
michael@428 | 252 | |
michael@428 | 253 | ## |
michael@428 | 254 | ## MAIN |
michael@428 | 255 | ## |
michael@428 | 256 | |
michael@428 | 257 | # determine stack file |
michael@428 | 258 | stk="$1" |
michael@428 | 259 | shift |
michael@428 | 260 | |
michael@428 | 261 | # support stand-alone query operation |
michael@428 | 262 | if [ ".$opt_q" = .yes ]; then |
michael@428 | 263 | name=`header "$stk" "Name"` |
michael@428 | 264 | summary=`header "$stk" "Summary"` |
michael@428 | 265 | packager=`header "$stk" "Packager"` |
michael@428 | 266 | version=`header "$stk" "Version"` |
michael@428 | 267 | release=`header "$stk" "Release"` |
michael@428 | 268 | echo "name=\"$name\";" |
michael@428 | 269 | echo "summary=\"$summary\";" |
michael@428 | 270 | echo "packager=\"$packager\";" |
michael@428 | 271 | echo "version=\"$version\";" |
michael@428 | 272 | echo "release=\"$release\";" |
michael@428 | 273 | sed <$stk \ |
michael@428 | 274 | -e "1,/^%options/d" -e '/^%/,$d' \ |
michael@428 | 275 | -e 's/#.*$//' -e 's/^ *//' -e '/^ *$/d' \ |
michael@428 | 276 | -e 's:^\([^ ]*\) *\([^ ]*\)$:\1="\2";:' |
michael@428 | 277 | exit 0 |
michael@428 | 278 | fi |
michael@428 | 279 | |
michael@428 | 280 | # determine temporary directory |
michael@428 | 281 | tmpdir="${TMPDIR-/tmp}" |
michael@428 | 282 | |
michael@428 | 283 | # provide verbose header |
michael@428 | 284 | verbose 1 "OpenPKG Software Stack Generation" |
michael@428 | 285 | |
michael@428 | 286 | # determine information |
michael@428 | 287 | verbose 2 "determining software stack information" |
michael@428 | 288 | name=`header "$stk" "Name"` |
michael@428 | 289 | summary=`header "$stk" "Summary"` |
michael@428 | 290 | packager=`header "$stk" "Packager"` |
michael@428 | 291 | version=`header "$stk" "Version"` |
michael@428 | 292 | release=`header "$stk" "Release"` |
michael@428 | 293 | verbose 3 "Name: $name" |
michael@428 | 294 | verbose 3 "Summary: $summary" |
michael@428 | 295 | verbose 3 "Packager: $packager" |
michael@428 | 296 | verbose 3 "Version: $version" |
michael@428 | 297 | verbose 3 "Release: $release" |
michael@428 | 298 | if [ ".$opt_u" = .yes ]; then |
michael@428 | 299 | basename="$name" |
michael@428 | 300 | else |
michael@428 | 301 | basename="$name-$version-$release" |
michael@428 | 302 | fi |
michael@428 | 303 | |
michael@428 | 304 | # determine URLs |
michael@428 | 305 | verbose 2 "determining software stack packages" |
michael@428 | 306 | repo=`section "$stk" "repository"` |
michael@428 | 307 | verbose 3 "repository: [URL] $repo" |
michael@428 | 308 | $openpkg build -r "$repo" -Z -u -K -B \ |
michael@428 | 309 | `section "$stk" "packages"` | \ |
michael@428 | 310 | egrep "openpkg curl" | \ |
michael@428 | 311 | sed -e 's;^.* \([^ ]*\) || exit.*$;\1;' \ |
michael@428 | 312 | -e '/\/openpkg-[0-9].*\.src\.rpm/{h;s/\.src\.rpm$/.src.sh/;p;x}' \ |
michael@428 | 313 | >$tmpdir/url.txt |
michael@428 | 314 | |
michael@428 | 315 | # provide header |
michael@428 | 316 | verbose 2 "assembling software stack sources" |
michael@428 | 317 | |
michael@428 | 318 | # download source packages |
michael@428 | 319 | if [ ! -d "$opt_o/$basename.src.d" ]; then |
michael@428 | 320 | verbose 3 "creating: [DIR] $opt_o/$basename.src.d" |
michael@428 | 321 | $shtool mkdir -p -m 755 "$opt_o/$basename.src.d" |
michael@428 | 322 | else |
michael@428 | 323 | verbose 3 "reusing: [DIR] $opt_o/$basename.src.d" |
michael@428 | 324 | fi |
michael@428 | 325 | for url in `cat $tmpdir/url.txt`; do |
michael@428 | 326 | url_file=`echo $url | sed -e 's;^.*/\([^/]*\)$;\1;'` |
michael@428 | 327 | if [ ! -f "$opt_o/$basename.src.d/$url_file" ]; then |
michael@428 | 328 | verbose 3 "downloading: [FILE] $opt_o/$basename.src.d/$url_file" |
michael@428 | 329 | if [ $opt_v -ge 4 ]; then |
michael@428 | 330 | $curl '-#' -L -k -o $opt_o/$basename.src.d/$url_file $url |
michael@428 | 331 | else |
michael@428 | 332 | $curl -s -L -k -o $opt_o/$basename.src.d/$url_file $url |
michael@428 | 333 | fi |
michael@428 | 334 | else |
michael@428 | 335 | verbose 3 "reusing: [FILE] $opt_o/$basename.src.d/$url_file" |
michael@428 | 336 | fi |
michael@428 | 337 | done |
michael@428 | 338 | for path in $opt_o/$basename.src.d/*.src.sh $opt_o/$basename.src.d/*.src.rpm; do |
michael@428 | 339 | if [ ! -f "$path" ]; then |
michael@428 | 340 | continue |
michael@428 | 341 | fi |
michael@428 | 342 | path_file=`echo $path | sed -e 's;^.*/\([^/]*\)$;\1;'` |
michael@428 | 343 | found=no |
michael@428 | 344 | for url in `cat $tmpdir/url.txt`; do |
michael@428 | 345 | url_file=`echo $url | sed -e 's;^.*/\([^/]*\)$;\1;'` |
michael@428 | 346 | if [ ".$url_file" = ".$path_file" ]; then |
michael@428 | 347 | found=yes |
michael@428 | 348 | break |
michael@428 | 349 | fi |
michael@428 | 350 | done |
michael@428 | 351 | if [ ".$found" = .no ]; then |
michael@428 | 352 | verbose 3 "removing: [FILE] $path" |
michael@428 | 353 | rm -f "$path" |
michael@428 | 354 | fi |
michael@428 | 355 | done |
michael@428 | 356 | rm -f $tmpdir/url.txt |
michael@428 | 357 | |
michael@428 | 358 | # generate XML/RDF index for SRPM packages |
michael@428 | 359 | verbose 3 "generating: [FILE] $opt_o/$basename.src.d/00INDEX.rdf" |
michael@428 | 360 | $openpkg index -r "OpenPKG/SRPM" \ |
michael@428 | 361 | -o $opt_o/$basename.src.d/00INDEX.rdf \ |
michael@428 | 362 | -i $opt_o/$basename.src.d |
michael@428 | 363 | |
michael@428 | 364 | # generate deployment utility |
michael@428 | 365 | verbose 3 "generating: [FILE] $opt_o/$basename.sh"; \ |
michael@428 | 366 | section "$stk" "framework" >$tmpdir/framework.txt |
michael@428 | 367 | section "$stk" "prolog" >$tmpdir/prolog.txt |
michael@428 | 368 | section "$stk" "epilog" >$tmpdir/epilog.txt |
michael@428 | 369 | HAVE_PROLOG=no; if [ ".`cat $tmpdir/prolog.txt`" != . ]; then HAVE_PROLOG=yes; fi |
michael@428 | 370 | HAVE_EPILOG=no; if [ ".`cat $tmpdir/epilog.txt`" != . ]; then HAVE_EPILOG=yes; fi |
michael@428 | 371 | $openpkg build -r "$repo" -Z -u -K \ |
michael@428 | 372 | `section "$stk" "packages"` | \ |
michael@428 | 373 | grep -v "^#" | \ |
michael@428 | 374 | grep -v "^echo" | \ |
michael@428 | 375 | grep -v "^rm" | \ |
michael@428 | 376 | egrep -v "^(if|fi)" | \ |
michael@428 | 377 | grep -v "openpkg curl" | \ |
michael@428 | 378 | grep -v "openpkg rpm -Uvh" | \ |
michael@428 | 379 | sed -e 's;.*openpkg rpm ;;' \ |
michael@428 | 380 | -e 's; || exit.*;;' \ |
michael@428 | 381 | -e 's;--rebuild ;;' \ |
michael@428 | 382 | -e 's;/.*/\([^/]*\.src\.rpm\);\1;' \ |
michael@428 | 383 | -e 's;^\(.*\) \([^/]*\.src\.rpm\);\2 \1;' \ |
michael@428 | 384 | -e "s;--define '\\([^ ]*\\) \\([^ ]*\\)';\\1=\\2;g" \ |
michael@428 | 385 | -e 's;\.src\.rpm;;' \ |
michael@428 | 386 | >$tmpdir/packages.txt |
michael@428 | 387 | sed <$0 \ |
michael@428 | 388 | -e '1,/^____/d' \ |
michael@428 | 389 | -e "/^CFG_FRAMEWORK=\"/r $tmpdir/framework.txt" \ |
michael@428 | 390 | -e "/^CFG_PACKAGES=\"/r $tmpdir/packages.txt" \ |
michael@428 | 391 | -e "s;@HAVE_PROLOG@;$HAVE_PROLOG;" \ |
michael@428 | 392 | -e "/%prolog/r $tmpdir/prolog.txt" \ |
michael@428 | 393 | -e "s;@HAVE_EPILOG@;$HAVE_EPILOG;" \ |
michael@428 | 394 | -e "/%epilog/r $tmpdir/epilog.txt" \ |
michael@428 | 395 | -e "/^## SHTOOL ##/r $shtool" \ |
michael@428 | 396 | -e "s;^\\(CFG_NAME=\"\\).*\\(\"\\);\\1$name\\2;" \ |
michael@428 | 397 | -e "s;^\\(CFG_SUMMARY=\"\\).*\\(\"\\);\\1$summary\\2;" \ |
michael@428 | 398 | -e "s;^\\(CFG_PACKAGER=\"\\).*\\(\"\\);\\1$packager\\2;" \ |
michael@428 | 399 | -e "s;^\\(CFG_VERSION=\"\\).*\\(\"\\);\\1$version\\2;" \ |
michael@428 | 400 | -e "s;^\\(CFG_RELEASE=\"\\).*\\(\"\\);\\1$release\\2;" \ |
michael@428 | 401 | -e "s;^\\(CFG_UNVERSIONED=\"\\).*\\(\"\\);\\1$opt_u\\2;" \ |
michael@428 | 402 | >$opt_o/$basename.sh |
michael@428 | 403 | |
michael@428 | 404 | # cleanup |
michael@428 | 405 | rm -f $tmpdir/framework.txt |
michael@428 | 406 | rm -f $tmpdir/packages.txt |
michael@428 | 407 | rm -f $tmpdir/prolog.txt |
michael@428 | 408 | rm -f $tmpdir/epilog.txt |
michael@428 | 409 | |
michael@428 | 410 | # exit gracefully |
michael@428 | 411 | exit 0 |
michael@428 | 412 | |
michael@428 | 413 | ## |
michael@428 | 414 | ## DEPLOYMENT SCRIPT |
michael@428 | 415 | ## |
michael@428 | 416 | |
michael@428 | 417 | ______________________________________________________________________________ |
michael@428 | 418 | #!/bin/sh |
michael@428 | 419 | #![OpenPKG] |
michael@428 | 420 | ## |
michael@428 | 421 | ## OpenPKG Software Stack Deployment |
michael@428 | 422 | ## Copyright (c) 2010-2012 OpenPKG GmbH <http://openpkg.com/> |
michael@428 | 423 | ## |
michael@428 | 424 | ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. |
michael@428 | 425 | ## All rights reserved. Licenses which grant limited permission to use, |
michael@428 | 426 | ## copy, modify and distribute this software are available from the |
michael@428 | 427 | ## OpenPKG GmbH. |
michael@428 | 428 | ## |
michael@428 | 429 | ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
michael@428 | 430 | ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@428 | 431 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@428 | 432 | ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@428 | 433 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@428 | 434 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@428 | 435 | ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@428 | 436 | ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@428 | 437 | ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@428 | 438 | ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@428 | 439 | ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@428 | 440 | ## SUCH DAMAGE. |
michael@428 | 441 | ## |
michael@428 | 442 | |
michael@428 | 443 | ## |
michael@428 | 444 | ## COMMAND LINE PARSING |
michael@428 | 445 | ## |
michael@428 | 446 | |
michael@428 | 447 | str_usage="[-h|--help] [-v|--verbose <level>] [-c|--cleanup <level>] [-D|--define <name>=<value> ...] [-s|--srcdir <dir>] [-o|--outdir <dir>] [-t|--tmpdir <dir>] [-S <sudo>]" |
michael@428 | 448 | arg_spec="0=" |
michael@428 | 449 | opt_spec="h.v:c:D+s:o:t:S:" |
michael@428 | 450 | opt_alias="h:help,v:verbose,c:cleanup,D:define,s:srcdir,o:outdir,t:tmpdir,S:sudo" |
michael@428 | 451 | opt_h=no |
michael@428 | 452 | opt_v=3 |
michael@428 | 453 | opt_c=1 |
michael@428 | 454 | opt_D="" |
michael@428 | 455 | opt_s="" |
michael@428 | 456 | opt_o="" |
michael@428 | 457 | opt_t="${TMPDIR-/tmp}" |
michael@428 | 458 | opt_S="" |
michael@428 | 459 | |
michael@428 | 460 | # parse argument specification string |
michael@428 | 461 | eval `echo $arg_spec |\ |
michael@428 | 462 | sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
michael@428 | 463 | |
michael@428 | 464 | # parse option specification string |
michael@428 | 465 | eval `echo $opt_spec |\ |
michael@428 | 466 | sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
michael@428 | 467 | |
michael@428 | 468 | # parse option alias string |
michael@428 | 469 | eval `echo $opt_alias |\ |
michael@428 | 470 | sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'` |
michael@428 | 471 | |
michael@428 | 472 | # interate over argument line |
michael@428 | 473 | opt_PREV='' |
michael@428 | 474 | while [ $# -gt 0 ]; do |
michael@428 | 475 | # special option stops processing |
michael@428 | 476 | if [ ".$1" = ".--" ]; then |
michael@428 | 477 | shift |
michael@428 | 478 | break |
michael@428 | 479 | fi |
michael@428 | 480 | |
michael@428 | 481 | # determine option and argument |
michael@428 | 482 | opt_ARG_OK=no |
michael@428 | 483 | if [ ".$opt_PREV" != . ]; then |
michael@428 | 484 | # merge previous seen option with argument |
michael@428 | 485 | opt_OPT="$opt_PREV" |
michael@428 | 486 | opt_ARG="$1" |
michael@428 | 487 | opt_ARG_OK=yes |
michael@428 | 488 | opt_PREV='' |
michael@428 | 489 | else |
michael@428 | 490 | # split argument into option and argument |
michael@428 | 491 | case "$1" in |
michael@428 | 492 | --[a-zA-Z0-9]*=*) |
michael@428 | 493 | eval `echo "x$1" |\ |
michael@428 | 494 | sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'` |
michael@428 | 495 | opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
michael@428 | 496 | eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
michael@428 | 497 | ;; |
michael@428 | 498 | --[a-zA-Z0-9]*) |
michael@428 | 499 | opt_OPT=`echo "x$1" | cut -c4-` |
michael@428 | 500 | opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
michael@428 | 501 | eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
michael@428 | 502 | opt_ARG='' |
michael@428 | 503 | ;; |
michael@428 | 504 | -[a-zA-Z0-9]*) |
michael@428 | 505 | eval `echo "x$1" |\ |
michael@428 | 506 | sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
michael@428 | 507 | -e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
michael@428 | 508 | ;; |
michael@428 | 509 | -[a-zA-Z0-9]) |
michael@428 | 510 | opt_OPT=`echo "x$1" | cut -c3-` |
michael@428 | 511 | opt_ARG='' |
michael@428 | 512 | ;; |
michael@428 | 513 | *) |
michael@428 | 514 | break |
michael@428 | 515 | ;; |
michael@428 | 516 | esac |
michael@428 | 517 | fi |
michael@428 | 518 | |
michael@428 | 519 | # eat up option |
michael@428 | 520 | shift |
michael@428 | 521 | |
michael@428 | 522 | # determine whether option needs an argument |
michael@428 | 523 | eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
michael@428 | 524 | if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then |
michael@428 | 525 | if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then |
michael@428 | 526 | opt_PREV="$opt_OPT" |
michael@428 | 527 | continue |
michael@428 | 528 | fi |
michael@428 | 529 | fi |
michael@428 | 530 | |
michael@428 | 531 | # process option |
michael@428 | 532 | case $opt_MODE in |
michael@428 | 533 | '.' ) |
michael@428 | 534 | # boolean option |
michael@428 | 535 | eval "opt_${opt_OPT}=yes" |
michael@428 | 536 | ;; |
michael@428 | 537 | ':' ) |
michael@428 | 538 | # option with argument (multiple occurances override) |
michael@428 | 539 | eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
michael@428 | 540 | ;; |
michael@428 | 541 | '+' ) |
michael@428 | 542 | # option with argument (multiple occurances append) |
michael@428 | 543 | eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" |
michael@428 | 544 | ;; |
michael@428 | 545 | * ) |
michael@428 | 546 | echo "$0: ERROR: unknown option: \`$opt_OPT'" 1>&2 |
michael@428 | 547 | exit 1 |
michael@428 | 548 | ;; |
michael@428 | 549 | esac |
michael@428 | 550 | done |
michael@428 | 551 | if [ ".$opt_PREV" != . ]; then |
michael@428 | 552 | echo "$0: ERROR: missing argument to option \`$opt_PREV'" 1>&2 |
michael@428 | 553 | exit 1 |
michael@428 | 554 | fi |
michael@428 | 555 | |
michael@428 | 556 | # process help option |
michael@428 | 557 | if [ ".$opt_h" = .yes ]; then |
michael@428 | 558 | echo "Usage: $0 $str_usage" |
michael@428 | 559 | exit 0 |
michael@428 | 560 | fi |
michael@428 | 561 | |
michael@428 | 562 | # complain about incorrect number of arguments |
michael@428 | 563 | case $arg_MODE in |
michael@428 | 564 | '=' ) |
michael@428 | 565 | if [ $# -ne $arg_NUMS ]; then |
michael@428 | 566 | echo "$0: ERROR: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
michael@428 | 567 | exit 1 |
michael@428 | 568 | fi |
michael@428 | 569 | ;; |
michael@428 | 570 | '+' ) |
michael@428 | 571 | if [ $# -lt $arg_NUMS ]; then |
michael@428 | 572 | echo "$0: ERROR: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
michael@428 | 573 | exit 1 |
michael@428 | 574 | fi |
michael@428 | 575 | ;; |
michael@428 | 576 | esac |
michael@428 | 577 | |
michael@428 | 578 | # helper function for verbose messages |
michael@428 | 579 | verbose () { |
michael@428 | 580 | lvl="$1" |
michael@428 | 581 | msg="$2" |
michael@428 | 582 | if [ $opt_v -ge $lvl ]; then |
michael@428 | 583 | case "$lvl" in |
michael@428 | 584 | 1 ) str_prefix="**" ;; |
michael@428 | 585 | 2 ) str_prefix="++" ;; |
michael@428 | 586 | 3 ) str_prefix="--" ;; |
michael@428 | 587 | 4 ) str_prefix=".." ;; |
michael@428 | 588 | esac |
michael@428 | 589 | echo "${str_prefix} ${msg}" |
michael@428 | 590 | fi |
michael@428 | 591 | } |
michael@428 | 592 | |
michael@428 | 593 | # helper function for graceful termination |
michael@428 | 594 | die () { |
michael@428 | 595 | echo "$0: ERROR: $*" |
michael@428 | 596 | exit 1 |
michael@428 | 597 | } |
michael@428 | 598 | |
michael@428 | 599 | ## |
michael@428 | 600 | ## MAIN |
michael@428 | 601 | ## |
michael@428 | 602 | |
michael@428 | 603 | # the stack information |
michael@428 | 604 | CFG_NAME="" |
michael@428 | 605 | CFG_SUMMARY="" |
michael@428 | 606 | CFG_PACKAGER="" |
michael@428 | 607 | CFG_VERSION="" |
michael@428 | 608 | CFG_RELEASE="" |
michael@428 | 609 | |
michael@428 | 610 | # the required OpenPKG framework parameters |
michael@428 | 611 | CFG_FRAMEWORK=" |
michael@428 | 612 | " |
michael@428 | 613 | |
michael@428 | 614 | # the required OpenPKG packages |
michael@428 | 615 | # (in topological order and with build options resolved) |
michael@428 | 616 | CFG_PACKAGES=" |
michael@428 | 617 | " |
michael@428 | 618 | |
michael@428 | 619 | # whether unversioned output directory should be used |
michael@428 | 620 | CFG_UNVERSIONED="" |
michael@428 | 621 | |
michael@428 | 622 | # display information |
michael@428 | 623 | verbose 1 "OpenPKG Software Stack Deployment" |
michael@428 | 624 | verbose 2 "determining information" |
michael@428 | 625 | |
michael@428 | 626 | # parse OpenPKG framework parameters |
michael@428 | 627 | params=" |
michael@428 | 628 | prefix |
michael@428 | 629 | user group |
michael@428 | 630 | susr musr rusr nusr |
michael@428 | 631 | sgrp mgrp rgrp ngrp |
michael@428 | 632 | suid muid ruid nuid |
michael@428 | 633 | sgid mgid rgid ngid |
michael@428 | 634 | tag |
michael@428 | 635 | " |
michael@428 | 636 | for param in $params; do |
michael@428 | 637 | eval "CF_$param=''" |
michael@428 | 638 | done |
michael@428 | 639 | for opt in $CFG_FRAMEWORK; do |
michael@428 | 640 | case "$opt" in |
michael@428 | 641 | --[a-zA-Z0-9-]*=* ) |
michael@428 | 642 | name=`echo "$opt" | sed -e 's;^--\([^=]*\)=.*$;\1;'` |
michael@428 | 643 | value=`echo "$opt" | sed -e 's;^--[^=]*=\(.*\)$;\1;'` |
michael@428 | 644 | eval "CF_$name='$value'" |
michael@428 | 645 | ;; |
michael@428 | 646 | esac |
michael@428 | 647 | done |
michael@428 | 648 | for define in $opt_D; do |
michael@428 | 649 | name=`echo "$define" | sed -e 's;=.*$;;'` |
michael@428 | 650 | value=`echo "$define" | sed -e 's;^.*=;;'` |
michael@428 | 651 | eval "CF_$name='$value'" |
michael@428 | 652 | done |
michael@428 | 653 | CFG_FRAMEWORK='' |
michael@428 | 654 | for name in $params; do |
michael@428 | 655 | eval "value=\"\$CF_$name\"" |
michael@428 | 656 | if [ ".$value" != . ]; then |
michael@428 | 657 | if [ ".$CFG_FRAMEWORK" = . ]; then |
michael@428 | 658 | CFG_FRAMEWORK="--$name=$value" |
michael@428 | 659 | else |
michael@428 | 660 | CFG_FRAMEWORK="$CFG_FRAMEWORK --$name=$value" |
michael@428 | 661 | fi |
michael@428 | 662 | fi |
michael@428 | 663 | done |
michael@428 | 664 | if [ ".$CF_musr" = . ]; then CF_musr="$CF_user"; fi |
michael@428 | 665 | if [ ".$CF_mgrp" = . ]; then CF_mgrp="$CF_group"; fi |
michael@428 | 666 | if [ ".$CF_rusr" = . ]; then CF_rusr="$CF_user-r"; fi |
michael@428 | 667 | if [ ".$CF_rgrp" = . ]; then CF_rgrp="$CF_group-r"; fi |
michael@428 | 668 | if [ ".$CF_nusr" = . ]; then CF_nusr="$CF_user-n"; fi |
michael@428 | 669 | if [ ".$CF_ngrp" = . ]; then CF_ngrp="$CF_group-n"; fi |
michael@428 | 670 | verbose 3 "name: $CFG_NAME" |
michael@428 | 671 | verbose 3 "summary: $CFG_SUMMARY" |
michael@428 | 672 | verbose 3 "packager: $CFG_PACKAGER" |
michael@428 | 673 | verbose 3 "version: $CFG_VERSION" |
michael@428 | 674 | verbose 3 "release: $CFG_RELEASE" |
michael@428 | 675 | |
michael@428 | 676 | # determine target parameters |
michael@428 | 677 | if [ ".$CF_prefix" = . ]; then |
michael@428 | 678 | die "OpenPKG Framework parameter \"prefix\" required" |
michael@428 | 679 | fi |
michael@428 | 680 | prefix="$CF_prefix" |
michael@428 | 681 | if [ ".$CF_tag" = . ]; then |
michael@428 | 682 | die "OpenPKG Framework parameter \"tag\" required" |
michael@428 | 683 | fi |
michael@428 | 684 | tag="$CF_tag" |
michael@428 | 685 | shtool="$opt_t/$CFG_NAME-$CFG_VERSION-$CFG_RELEASE.shtool.sh" |
michael@428 | 686 | sed <$0 -e '1,/^## SHTOOL ##.*/d' >$shtool |
michael@428 | 687 | platform=`sh $shtool platform -n -L -S "" -C "+" -F '%<ap>-%<sp>'` |
michael@428 | 688 | verbose 3 "platform: $platform" |
michael@428 | 689 | verbose 3 "tag: $tag" |
michael@428 | 690 | verbose 3 "prefix: $prefix" |
michael@428 | 691 | |
michael@428 | 692 | # determine operation directories |
michael@428 | 693 | srcdir="$opt_s" |
michael@428 | 694 | if [ ".$srcdir" = . ]; then |
michael@428 | 695 | srcdir="$CFG_NAME-$CFG_VERSION-$CFG_RELEASE.src.d" |
michael@428 | 696 | fi |
michael@428 | 697 | tmpdir="$opt_t/$CFG_NAME-$CFG_VERSION-$CFG_RELEASE.d" |
michael@428 | 698 | if [ ! -d "$tmpdir" ]; then |
michael@428 | 699 | ( umask 077 |
michael@428 | 700 | rm -rf "$tmpdir" >/dev/null 2>&1 || true |
michael@428 | 701 | sh $shtool mkdir -p -m 700 "$tmpdir" >/dev/null 2>&1 |
michael@428 | 702 | if [ $? -ne 0 ]; then |
michael@428 | 703 | die "failed to create temporary directory: \"$tmpdir\"" |
michael@428 | 704 | fi |
michael@428 | 705 | ) || exit $? |
michael@428 | 706 | fi |
michael@428 | 707 | outdir="$opt_o" |
michael@428 | 708 | if [ ".$outdir" = . ]; then |
michael@428 | 709 | if [ ".$CFG_UNVERSIONED" = .yes ]; then |
michael@428 | 710 | outdir="$CFG_NAME.$platform-$tag.d" |
michael@428 | 711 | else |
michael@428 | 712 | outdir="$CFG_NAME-$CFG_VERSION-$CFG_RELEASE.$platform-$tag.d" |
michael@428 | 713 | fi |
michael@428 | 714 | fi |
michael@428 | 715 | if [ ! -d "$outdir" ]; then |
michael@428 | 716 | sh $shtool mkdir -p -m 755 "$outdir" >/dev/null 2>&1 |
michael@428 | 717 | if [ $? -ne 0 ]; then |
michael@428 | 718 | die "failed to create output directory: \"$outdir\"" |
michael@428 | 719 | fi |
michael@428 | 720 | fi |
michael@428 | 721 | verbose 3 "srcdir: $srcdir" |
michael@428 | 722 | verbose 3 "outdir: $outdir" |
michael@428 | 723 | verbose 3 "tmpdir: $tmpdir" |
michael@428 | 724 | |
michael@428 | 725 | # execute prolog script |
michael@428 | 726 | if [ ".@HAVE_PROLOG@" = .yes ]; then |
michael@428 | 727 | verbose 2 "execute prolog script" |
michael@428 | 728 | cat >$tmpdir/prolog.sh <<EOT |
michael@428 | 729 | #!/bin/sh |
michael@428 | 730 | #![OpenPKG] |
michael@428 | 731 | # %prolog |
michael@428 | 732 | EOT |
michael@428 | 733 | $opt_S sh $tmpdir/prolog.sh |
michael@428 | 734 | rm -f $tmpdir/prolog.sh |
michael@428 | 735 | fi |
michael@428 | 736 | |
michael@428 | 737 | if [ $opt_c -le 1 -a -x "$prefix/bin/openpkg" ]; then |
michael@428 | 738 | # optionally fresh-up OpenPKG instance |
michael@428 | 739 | pkgs=`$prefix/bin/openpkg rpm -qa | egrep -v '^(openpkg-[0-9]|gpg-pubkey-)'` |
michael@428 | 740 | if [ ".$pkgs" != . ]; then |
michael@428 | 741 | verbose 2 "uninstall already installed OpenPKG packages" |
michael@428 | 742 | for pkg in $pkgs; do |
michael@428 | 743 | verbose 3 "REMOVE: $pkg @ $prefix" |
michael@428 | 744 | done |
michael@428 | 745 | $opt_S $prefix/bin/openpkg rpm -e $pkgs || \ |
michael@428 | 746 | die "failed to uninstall already installed OpenPKG packages" |
michael@428 | 747 | fi |
michael@428 | 748 | fi |
michael@428 | 749 | if [ $opt_c -le 0 -a -x "$prefix/bin/openpkg" ]; then |
michael@428 | 750 | # optionally destroy OpenPKG instance |
michael@428 | 751 | verbose 2 "destroy existing OpenPKG framework" |
michael@428 | 752 | $opt_S $prefix/bin/openpkg rpm -e openpkg || \ |
michael@428 | 753 | die "failed to destroy existing OpenPKG framework" |
michael@428 | 754 | fi |
michael@428 | 755 | |
michael@428 | 756 | # check whether an already existing OpenPKG instance can be reused |
michael@428 | 757 | if [ -x "$prefix/bin/openpkg" ]; then |
michael@428 | 758 | verbose 2 "checking compatibility of existing OpenPKG framework" |
michael@428 | 759 | for name in $params; do |
michael@428 | 760 | case "$name" in |
michael@428 | 761 | user|group ) continue ;; |
michael@428 | 762 | esac |
michael@428 | 763 | eval "value_required=\"\$CF_$name\"" |
michael@428 | 764 | if [ ".$value_required" != . ]; then |
michael@428 | 765 | value_existing=`$prefix/bin/openpkg rpm --eval "%{l_${name}}"` |
michael@428 | 766 | if [ ".$value_existing" != ".$value_required" ]; then |
michael@428 | 767 | die "conflict on parameter \"$name\": value required: \"$value_required\", value existing: \"$value_existing\"" |
michael@428 | 768 | fi |
michael@428 | 769 | fi |
michael@428 | 770 | done |
michael@428 | 771 | fi |
michael@428 | 772 | |
michael@428 | 773 | # install or upgrade all packages |
michael@428 | 774 | verbose 2 "install or upgrade all OpenPKG packages" |
michael@428 | 775 | DIFS="$IFS" |
michael@428 | 776 | OIFS="$IFS"; IFS=" |
michael@428 | 777 | " |
michael@428 | 778 | for spec in $CFG_PACKAGES; do |
michael@428 | 779 | # determine information |
michael@428 | 780 | pkg=`echo "$spec" | sed -e 's;^\([^ ]*\).*$;\1;'` |
michael@428 | 781 | opts=`echo "$spec" | sed -e 's;^[^ ]*;;' -e 's;^ *;;'` |
michael@428 | 782 | name=`echo "$pkg" | sed -e 's;^\(.*\)-[^-][^-]*-[^-][^-]*$;\1;'` |
michael@428 | 783 | version=`echo "$pkg" | sed -e 's;^.*-\([^-][^-]*\)-[^-][^-]*$;\1;'` |
michael@428 | 784 | release=`echo "$pkg" | sed -e 's;^.*-[^-][^-]*-\([^-][^-]*\)$;\1;'` |
michael@428 | 785 | |
michael@428 | 786 | if [ ".$name" = .openpkg ]; then |
michael@428 | 787 | # |
michael@428 | 788 | # OpenPKG Framework |
michael@428 | 789 | # |
michael@428 | 790 | if [ ! -f "$outdir/$pkg.$platform-$tag.sh" \ |
michael@428 | 791 | -o ! -f "$outdir/$pkg.$platform-$tag.rpm" ]; then |
michael@428 | 792 | # build (bootstrap & regular) |
michael@428 | 793 | verbose 3 "BOOTSTRAP-BUILD: $srcdir/$pkg.src.sh" |
michael@428 | 794 | verbose 4 "options: $CFG_FRAMEWORK" |
michael@428 | 795 | if [ ! -f "$srcdir/$pkg.src.sh" ]; then |
michael@428 | 796 | die "source shell package not existing: $srcdir/$pkg.src.sh" |
michael@428 | 797 | fi |
michael@428 | 798 | ( TMPDIR="$tmpdir" |
michael@428 | 799 | srcdir="`cd $srcdir && pwd`" |
michael@428 | 800 | cd "$outdir" || exit $? |
michael@428 | 801 | cmd="sh \"$srcdir/$pkg.src.sh\" $CFG_FRAMEWORK" |
michael@428 | 802 | if [ $opt_v -lt 4 ]; then cmd="$cmd >/dev/null 2>&1"; fi |
michael@428 | 803 | eval "$cmd" || \ |
michael@428 | 804 | die "failed to build package \"$srcdir/$pkg.src.sh\"" |
michael@428 | 805 | rm -f $pkg.src.rpm |
michael@428 | 806 | ) || exit $? |
michael@428 | 807 | fi |
michael@428 | 808 | if [ ! -x "$prefix/bin/openpkg" ]; then |
michael@428 | 809 | # install (bootstrap) |
michael@428 | 810 | if [ ! -f "$outdir/$pkg.$platform-$tag.sh" ]; then |
michael@428 | 811 | die "binary shell package not existing: $outdir/$pkg.$platform-$tag.sh" |
michael@428 | 812 | fi |
michael@428 | 813 | verbose 3 "BOOTSTRAP-INSTALL: $outdir/$pkg.$platform-$tag.sh" |
michael@428 | 814 | cmd="$opt_S sh \"$outdir/$pkg.$platform-$tag.sh\"" |
michael@428 | 815 | if [ $opt_v -lt 4 ]; then cmd="$cmd >/dev/null 2>&1"; fi |
michael@428 | 816 | eval "$cmd" || \ |
michael@428 | 817 | die "failed to install package \"$outdir/$pkg.$platform-$tag.sh\"" |
michael@428 | 818 | else |
michael@428 | 819 | check=`$prefix/bin/openpkg rpm -q openpkg 2>/dev/null` |
michael@428 | 820 | if [ ".$check" != ".$pkg" ]; then |
michael@428 | 821 | # upgrade (regular) |
michael@428 | 822 | if [ ! -f "$outdir/$pkg.$platform-$tag.rpm" ]; then |
michael@428 | 823 | die "binary RPM package not existing: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 824 | fi |
michael@428 | 825 | verbose 3 "UPGRADE: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 826 | rpm_opt="-U"; if [ $opt_v -ge 4 ]; then rpm_opt="${rpm_opt}vh"; fi |
michael@428 | 827 | $opt_S $prefix/bin/openpkg rpm $rpm_opt \ |
michael@428 | 828 | $outdir/$pkg.$platform-$tag.rpm || \ |
michael@428 | 829 | die "failed to upgrade package: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 830 | else |
michael@428 | 831 | # keep as-is |
michael@428 | 832 | verbose 3 "KEEP AS-IS: $pkg @ $prefix" |
michael@428 | 833 | fi |
michael@428 | 834 | fi |
michael@428 | 835 | else |
michael@428 | 836 | # |
michael@428 | 837 | # OpenPKG Packages |
michael@428 | 838 | # |
michael@428 | 839 | if [ ! -x "$prefix/bin/openpkg" ]; then |
michael@428 | 840 | # usually will not happen because of correctly |
michael@428 | 841 | # generated topologically correct package list |
michael@428 | 842 | die "command \"$prefix/bin/openpkg\" has to exit for building a regular OpenPKG package" 1>&2 |
michael@428 | 843 | fi |
michael@428 | 844 | if [ ! -f $outdir/$pkg.$platform-$tag.rpm ]; then |
michael@428 | 845 | # build (regular) |
michael@428 | 846 | if [ ! -f "$srcdir/$pkg.src.rpm" ]; then |
michael@428 | 847 | die "source RPM package not existing: $srcdir/$pkg.src.rpm" |
michael@428 | 848 | fi |
michael@428 | 849 | verbose 3 "BUILD: $srcdir/$pkg.src.rpm" |
michael@428 | 850 | if [ ".$opts" != . ]; then |
michael@428 | 851 | verbose 4 "options: $opts" |
michael@428 | 852 | fi |
michael@428 | 853 | rm -rf "$tmpdir/$pkg" >/dev/null 2>&1 || true |
michael@428 | 854 | sh $shtool mkdir -p -m 755 "$tmpdir/$pkg" >/dev/null 2>&1 |
michael@428 | 855 | cmd="$prefix/bin/openpkg --keep-privileges" |
michael@428 | 856 | cmd="$cmd rpm --rebuild" |
michael@428 | 857 | cmd="$cmd --define \"_specdir $tmpdir/$pkg\"" |
michael@428 | 858 | cmd="$cmd --define \"_sourcedir $tmpdir/$pkg\"" |
michael@428 | 859 | cmd="$cmd --define \"_builddir $tmpdir/$pkg\"" |
michael@428 | 860 | cmd="$cmd --define \"_tmppath $tmpdir/$pkg\"" |
michael@428 | 861 | cmd="$cmd --define \"_srcrpmdir $tmpdir/$pkg\"" |
michael@428 | 862 | cmd="$cmd --define \"_rpmdir $outdir\"" |
michael@428 | 863 | OIFS2="$IFS"; IFS="$DIFS" |
michael@428 | 864 | for opt in $opts; do |
michael@428 | 865 | opt_name=`echo "$opt" | sed -e 's;^\([^=]*\)=.*$;\1;'` |
michael@428 | 866 | opt_value=`echo "$opt" | sed -e 's;^[^=]*=\(.*\)$;\1;'` |
michael@428 | 867 | cmd="$cmd --define \"$opt_name $opt_value\"" |
michael@428 | 868 | done |
michael@428 | 869 | IFS="$OIFS2" |
michael@428 | 870 | cmd="$cmd $srcdir/$pkg.src.rpm" |
michael@428 | 871 | if [ $opt_v -lt 4 ]; then cmd="$cmd >/dev/null 2>&1"; fi |
michael@428 | 872 | eval "$cmd" || \ |
michael@428 | 873 | die "failed to build package \"$srcdir/$pkg.src.rpm\"" |
michael@428 | 874 | fi |
michael@428 | 875 | check=`$prefix/bin/openpkg rpm -q "$name" 2>/dev/null` |
michael@428 | 876 | if [ ".$check" = ".package $name is not installed" ]; then |
michael@428 | 877 | # install (regular) |
michael@428 | 878 | if [ ! -f "$outdir/$pkg.$platform-$tag.rpm" ]; then |
michael@428 | 879 | die "binary RPM package not existing: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 880 | fi |
michael@428 | 881 | verbose 3 "INSTALL: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 882 | rpm_opt="-i"; if [ $opt_v -ge 4 ]; then rpm_opt="${rpm_opt}vh"; fi |
michael@428 | 883 | $opt_S $prefix/bin/openpkg rpm $rpm_opt \ |
michael@428 | 884 | $outdir/$pkg.$platform-$tag.rpm || \ |
michael@428 | 885 | die "failed to install package: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 886 | elif [ ".$check" != ".$pkg" ]; then |
michael@428 | 887 | # upgrade (regular) |
michael@428 | 888 | if [ ! -f "$outdir/$pkg.$platform-$tag.rpm" ]; then |
michael@428 | 889 | die "binary RPM package not existing: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 890 | fi |
michael@428 | 891 | verbose 3 "UPGRADE: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 892 | rpm_opt="-U"; if [ $opt_v -ge 4 ]; then rpm_opt="${rpm_opt}vh"; fi |
michael@428 | 893 | $opt_S $prefix/bin/openpkg rpm $rpm_opt \ |
michael@428 | 894 | $outdir/$pkg.$platform-$tag.rpm || \ |
michael@428 | 895 | die "failed to upgrade package: $outdir/$pkg.$platform-$tag.rpm" |
michael@428 | 896 | else |
michael@428 | 897 | # keep as-is |
michael@428 | 898 | verbose 3 "KEEP AS-IS: $pkg @ $prefix" |
michael@428 | 899 | fi |
michael@428 | 900 | fi |
michael@428 | 901 | done |
michael@428 | 902 | IFS="$OIFS" |
michael@428 | 903 | |
michael@428 | 904 | # optionally remove residue packages from binary RPM package directory |
michael@428 | 905 | if [ $opt_c -lt 3 ]; then |
michael@428 | 906 | verbose 2 "cleanup target directory from residue packages" |
michael@428 | 907 | for pkg in $outdir/*.sh $outdir/*.rpm; do |
michael@428 | 908 | if [ ! -f "$pkg" ]; then |
michael@428 | 909 | continue |
michael@428 | 910 | fi |
michael@428 | 911 | pkg_base=`echo "$pkg" | sed -e 's;^.*/\([^/][^/]*-[0-9][^/-]*-[0-9][0-9.]*\)\.[^/][^/]*$;\1;'` |
michael@428 | 912 | erase=yes |
michael@428 | 913 | for spec in $CFG_PACKAGES; do |
michael@428 | 914 | spec_base=`echo "$spec" | sed -e 's;^\(.*-[^-][^-]*-[^-][^-]*\).*$;\1;'` |
michael@428 | 915 | if [ ".$pkg_base" = ".$spec_base" ]; then |
michael@428 | 916 | erase=no |
michael@428 | 917 | break |
michael@428 | 918 | fi |
michael@428 | 919 | done |
michael@428 | 920 | if [ ".$erase" = .yes ]; then |
michael@428 | 921 | verbose 3 "REMOVE: $pkg" |
michael@428 | 922 | rm -f "$pkg" |
michael@428 | 923 | fi |
michael@428 | 924 | done |
michael@428 | 925 | fi |
michael@428 | 926 | |
michael@428 | 927 | # optionally remove residue packages from OpenPKG instance |
michael@428 | 928 | if [ $opt_c -lt 3 ]; then |
michael@428 | 929 | verbose 2 "cleanup OpenPKG instance from residue packages" |
michael@428 | 930 | for pkg1 in `$prefix/bin/openpkg rpm -qa | egrep -v '^(openpkg-[0-9]|gpg-pubkey-)'`; do |
michael@428 | 931 | name1=`echo "$pkg1" | sed -e 's;^\(.*\)-[^-][^-]*-[^-][^-]*$;\1;'` |
michael@428 | 932 | erase=yes |
michael@428 | 933 | for spec in $CFG_PACKAGES; do |
michael@428 | 934 | name2=`echo "$spec" | sed -e 's;^\(.*\)-[^-][^-]*-[^-][^-]*.*$;\1;'` |
michael@428 | 935 | if [ ".$name1" = ".$name2" ]; then |
michael@428 | 936 | erase=no |
michael@428 | 937 | break |
michael@428 | 938 | fi |
michael@428 | 939 | done |
michael@428 | 940 | if [ ".$erase" = .yes ]; then |
michael@428 | 941 | verbose 3 "REMOVE: pkg1 @ $prefix" |
michael@428 | 942 | $opt_S $prefix/bin/openpkg rpm -e "$pkg1" || \ |
michael@428 | 943 | die "failed to erase residue package \"$pkg1\"" |
michael@428 | 944 | fi |
michael@428 | 945 | done |
michael@428 | 946 | fi |
michael@428 | 947 | |
michael@428 | 948 | # execute epilog script |
michael@428 | 949 | if [ ".@HAVE_EPILOG@" = .yes ]; then |
michael@428 | 950 | verbose 2 "execute epilog script" |
michael@428 | 951 | cat >$tmpdir/epilog.sh <<EOT |
michael@428 | 952 | #!/bin/sh |
michael@428 | 953 | #![OpenPKG] |
michael@428 | 954 | # %epilog |
michael@428 | 955 | EOT |
michael@428 | 956 | $opt_S sh $tmpdir/epilog.sh |
michael@428 | 957 | rm -f $tmpdir/epilog.sh |
michael@428 | 958 | fi |
michael@428 | 959 | |
michael@428 | 960 | # cleanup |
michael@428 | 961 | rm -f $shtool >/dev/null 3>&1 || true |
michael@428 | 962 | rm -rf $tmpdir >/dev/null 2>&1 || true |
michael@428 | 963 | |
michael@428 | 964 | exit 0 |
michael@428 | 965 | |
michael@428 | 966 | ## SHTOOL ################################################################### |
michael@428 | 967 |