#!/bin/bash # # --- ROCK-COPYRIGHT-NOTE-BEGIN --- # # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # Please add additional copyright information _after_ the line containing # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by # the ./scripts/Create-CopyPatch script. Do not edit this copyright text! # # ROCK Linux: rock-src/scripts/Emerge-Pkg # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. A copy of the GNU General Public # License can be found at Documentation/COPYING. # # Many people helped and are helping developing ROCK Linux. Please # have a look at https://www.rocklinux.org/ and the Documentation/TEAM # file for details. # # --- ROCK-COPYRIGHT-NOTE-END --- exec 2>&1 options='' config=default builddep=0 debug=0 ignore_chksum=0 update=1 dryrun=0 rebuild=1 repositories="" # # ---- Functions # . scripts/functions help_msg() { spacer=" " echo echo "Usage: ./scripts/Emerge-Pkg" \ "[ -cfg ] [ -dep ] [ -dry-run ]" echo "$spacer [ -noupdate ] [ -ignore-chksum ] [ -norebuild ]" echo "$spacer [ -repository ] [ -debug ]" echo "$spacer [ pkg-name(s) ]" echo echo " Compile/build single packages or whole repositories on the host system. By" echo " default only new/updated packages will be built. Modified files of packages" echo " (e.g. configuration files) to build will be backed up before and restored" echo " after each build." echo echo " -cfg the configuration to use" echo " -dep also build packages specified packages depend on" echo " -dry-run don't actually build packages; just print what" echo " would happen" echo " -noupdate don't backup/restore modified package files" echo " -ignore-chksum ignore checksums on package source directories (i.e." echo " package/base/*/) when looking for updated packages" echo " -norebuild don't build a package if its previous build failed" echo " -repository " echo " build all packages in the specified repository" echo " -debug print various debug information" echo echo " pkg-name(s) are only optional if a repository is specified!" echo } # # ---- Parse options + config # if [ $# = 0 ]; then help_msg exit 1 fi while [ "$1" ] ; do case "$1" in -cfg) options="$options $1 $2" ; config="$2" ; shift ;; -debug) debug=1 ;; -dep) builddep=1 ;; -dry-run) dryrun=1 ;; -noupdate) update=0 ;; -ignore-chksum) ignore_chksum=1 ;; -norebuild) rebuild=0 ;; -repository) repositories="$repositories $2" ; shift ;; -*) help_msg ; exit 1 ;; *) break ;; esac shift done . ./scripts/parse-config check4update() { addlist="" for package in $deplist ; do [ "$debug" = 1 ] && echo "checking $package ..." confdir="" for x in package/*/$package/$package.desc ; do if [ -f "$x" ] ; then if [ -z "$confdir" ] ; then confdir=${x/$package.desc/} else confdir=X fi fi done if [ -z "$confdir" ] ; then [ $debug = 1 ] && \ echo " $package: No such package." elif [ "$confdir" = X ] ; then [ $debug = 1 ] && \ echo " $package: Package in multiple trees." elif [ ! -f /var/adm/packages/$package ] ; then [ $debug = 1 ] && \ echo " $package: Not installed. Added." addlist="$addlist $package" else o_ver=$(grep '^Package Name and Version' \ /var/adm/packages/$package | cut -f6 -d' ') n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ') if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ] ; then [ $debug = 1 ] && \ echo " $package: New version ($o_ver -> $n_ver). Added." addlist="$addlist $package" else o_ck=$(grep '^ROCK Linux Package Source Checksum' \ /var/adm/packages/$package | cut -f6 -d' ') n_ck=$(md5sum package/*/$package/* 2> /dev/null | \ grep -v '\.cache$' | md5sum | cut -f1 -d' ') if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ] ; then [ $debug = 1 ] && \ echo " $package: New source checksum ($n_ck). Added." addlist="$addlist $package" else if [ -f /var/adm/cache/$package ] ; then if ! grep -q BUILDTIME /var/adm/cache/$package ; then [ $debug = 1 ] && \ echo -n " $package: Former build was broken." if [ $rebuild = 1 ] ; then [ $debug = 1 ] && echo " Added." addlist="$addlist $package" else [ $debug = 1 ] && echo " Skipped." fi fi else [ $debug = 1 ] && \ echo " $package: Equal source checksum ($n_ck), skipped." fi fi fi fi done deplist="$addlist" } dep4pkg() { gawk -v package=$1 ' function check_package() { found_new = 0; for ( package in build_list ) { if ( debug ) print "#DEBUG PACKAGE: " package; if ( ! package in database ) { if (debug) print "# " package " not in database"; } else { if (debug) print "# " package " in database"; split(database[package], a); for (d in a) { # if ( a[c] == package ) continue; if ( strtonum(d) <= 3 ) continue; dep = a[d]; if ( debug && 0) print "# dep: " dep; if ( dep in build_list ) { if ( debug && 0) print "# dep: " dep " already parsed"; } else { if (debug) print "# dep: " dep " now added"; build_list [ dep ] = (package); found_new = 1; } } } } if (found_new) check_package(); } BEGIN { config="'$config'"; debug='$debug'; depdb_file = "scripts/dep_db.txt"; while ( (getline depline < depdb_file) > 0 ) { $0 = depline; sub(/:/, "", $1); database[$1]=$0; } close(depdb_file); build_list [ package ] = 1; check_package(); if (debug) { for ( bp in build_list ) { print "# " bp " (" build_list[bp] ")" } } for ( bp in build_list ) { print bp } } ' } # all packages deplist="$deplist $@" # packages from repositories for x in $repositories ; do deplist="$deplist ` egrep "^X .* $x .*" config/$config/packages | \ cut -d ' ' -f 5`" # only build packages that need an update check4update done if [ $builddep = 1 ] ; then # we have to create a complete dependency graph ... tmp="`mktemp`" for x in $deplist ; do dep4pkg $x >> $tmp done [ "$debug" = 1 ] && grep '^#' $tmp deplist="$deplist `grep -v '^#' $tmp`" rm $tmp # only build packages that need an update check4update fi echo "Packages scheduled to build: $deplist" [ $dryrun = 1 ] && exit # the deplist is quite unsorted (in alphabetically sorted chunks) # so we need to work arround this here ... [ $update = 1 ] && options="$options -update" for package in $deplist ; do if ./scripts/Download $package ; then ./scripts/Build-Pkg $options $package else echo "The download for package $package failed!" exit -1 fi done