#!echo "This is a Bash library, not an executable" ### Set shell options set -p #-u -f ### general variables DARCONFIG="/etc/dar/dar.conf" ### ANSI colors _DE="\033[0;0m" # Default _BK="\033[0;30m" # Black _DB="\033[0;34m" # Dark Blue _SI="\033[0;37m" # Silver _GA="\033[1;30m" # Gray _RE="\033[1;31m" # Red _GR="\033[1;32m" # Green _YE="\033[1;33m" # Yellow _BL="\033[1;34m" # Blue _MA="\033[1;35m" # Magenta _CY="\033[1;36m" # Cyan _WH="\033[1;37m" # White _BK_="\033[40m" # Black BG _RE_="\033[41m" # Red BG _BL_="\033[44m" # Blue BG _WH_="\033[47m" # White BG ### Cleans environment function clean_env { : } ### Give a timestamp function timestamp { echo $(date +'%h %d %H:%M:%S') } ### Just log and fill error-buffer function log { local MSG="$(timestamp) $*" echo "$MSG" >&2 ERRORBUFFER="$ERRORBUFFER\n$MSG" } ### Log only if debugging is on function debug { if [ "$DEBUG" == "yes" ]; then log "DEBUG: $*" else local MSG="$(timestamp) $*" ERRORBUFFER="$ERRORBUFFER\n$MSG" fi } ### Log and put error-boolean on (so die will escalate the problem) function error { ERROR="yes" echo -e "\033[1;31mERROR:\033[0;0m $*" >&2 # log "ERROR: $*" } ### Log and put warning-boolean on (so die will escalate the problem) function warning { ERROR="yes" if [ "$FORCE_VERBOSE" == "yes" ]; then echo -e "\033[1;33mWARNING:\033[0;0m $*" >&2 # log "WARNING: $*" fi } ### Stop running and escalate if problems function die { if [ "$*" -o "$ERROR" == "yes" ]; then log "$* Exiting." exit 1 else debug "Exiting successfully." exit 0 fi } function rpmconf { local CONFIG="$1" if [ "$2" ]; then local SPECFILE="$2" fi if [ -z "$SPECFILE" ]; then return 1 fi if [ "$3" != "nocheck" ]; then if [ "$DISTNICK" ]; then local RPMVER="$(chroot $CHROOTDIR/$DISTNICK rpm --version | cut -d' ' -f3)" fi ( # if [ -z "$DISTNICK" ] || [ "$RPMVER" \< "4.1" ] || ! chroot "$CHROOTDIR/$DISTNICK" /bin/su -lm $BUILD_USER -c "rpmdb -D \"dtag $DISTNAME\" -D \"disttag $DISTNAME\" -D \"$DISTNICK 1\" -D \"$DISTNAME 1\" -E \"%{expand:%(head -n128 $SPECFILE)}\"" | grep -i "^ *$CONFIG *:" | sed -e "s/^ *$CONFIG *: *//i" | head -1; then if [ -z "$DISTNICK" ] || [ "$RPMVER" \< "4.1" ] || ! chroot "$CHROOTDIR/$DISTNICK" /bin/su -lm $BUILD_USER -c "rpmdb -D \"dtag $DISTNAME\" -D \"disttag $DISTNAME\" -D \"$DISTNICK 1\" -D \"$DISTNAME 1\" -E \"%{expand:%(head -n128 $SPECFILE)}\"" | grep -i "^ *$CONFIG *:" | sed -e "s/^ *$CONFIG *: *//i" | head -1; then if ! grep -i "^ *$CONFIG *:" $SPECFILE | sed -e "s/^ *$CONFIG *: *//i" | head -1; then debug "Config $CONFIG not found in $SPECFILE" fi fi ) | perl -p -e " s|\%{real_version}|$RVERSION|; s|\%{real_release}|$RRELEASE|; s|\%{kversion}|kv|; s|\%{krelease}|kr|; s|\%{.*}||g; s|\s+| |g; s|^\s+||; s|\s+$||; " else if ! grep -i "^ *$CONFIG *:" $SPECFILE | sed -e "s/^ *$CONFIG *: *//i" | head -1; then debug "Config $CONFIG not found in $SPECFILE" fi fi } function rpmmacro { CONFIG="$1" if [ "$2" ]; then SPECFILE="$2" fi if [ -z "$SPECFILE" ]; then return 1 fi if ! grep -i "^%define $CONFIG " $SPECFILE | sed -e "s/^%define $CONFIG *//i" | head -1; then debug "Macro $CONFIG not found in $SPECFILE" fi } function metaconf { CONFIG="$1" if [ "$2" ]; then SPECFILE="$2" fi if [ -z "$SPECFILE" ]; then return 1 fi # if ! grep -i "^# *Dar$CONFIG *:" $SPECFILE | sed -e "s/^# *Dar$CONFIG *: *//i" | head -1; then # debug "Config Dar$CONFIG not found in $SPECFILE" # fi if ! grep -i "^# *$CONFIG *:" $SPECFILE | sed -e "s/^# *$CONFIG *: *//i" | head -1; then debug "MetaConfig $CONFIG not found in $SPECFILE" fi } function daropts { OPTIONS="$1"; shift OPTIND=1 while getopts "$OPTIONS" c; do case "$c" in (a) FORCE_ARCHS="$OPTARG";; (d) FORCE_DISTS="$OPTARG";; (f) FORCE_OVERWRITE="yes";; (h) help;; (n) NOSOURCE="yes";; (r) CREATE_REPO="yes";; (s) FORCE_SOURCE_DISTS="$OPTARG";; (t) FORCE_TAG="$OPTARG";; (v) FORCE_VERBOSE="yes";; (q) QUIET="yes";; # (-) c=${OPTARG/#-/}; OPTARG="$(echo $* | cut -d' ' -f$OPTIND)" # case "$c" in # (port) port="$OPTARG"; OPTIND=$((OPTIND+1));; # (*) options="$options --$c $OPTARG"; OPTIND=$((OPTIND+1));; # esac;; # ('?') error "allow: Option \"-$c\" not allowed" >&2;; (*) error "Option \"-$OPTARG\" unknown." esac done shift $((OPTIND-1)) OPTS=$@ } function set_archs { if [ "$FORCE_ARCHS" ]; then ARCHS="${FORCE_ARCHS//[,:;]/ }" elif [ "$(rpmconf Nosource)" != "" ]; then ARCHS="nosrc" else ARCHS="$(metaconf Archs)" fi if [ -z "$ARCHS" ]; then ARCHS="$(rpmconf BuildArch)"; fi if [ -z "$ARCHS" ]; then ARCHS="$DISTARCH"; fi if [ -z "$ARCHS" ]; then ARCHS="$DEFAULT_ARCHS"; fi } function set_dists { unset NODIST if [ "$FORCE_DISTS" ]; then DISTS="${FORCE_DISTS//[,:;]/ }" elif [ "$(rpmconf Nosource)" != "" ]; then NODIST="nodist" DISTS="$(echo "$DISTS" | cut -f1)" else DISTS="$(metaconf Dists)" fi if [ "$(metaconf Dist)" == "nodist" ]; then NODIST="nodist" DISTS="$(echo $DISTS | cut -f1)" fi if [ -z "$DISTS" ]; then DISTS="$DEFAULT_DISTS"; fi } function set_exclude_dist { EXCLUDE_DIST="$(metaconf ExcludeDist)" } function set_exclusive_dist { EXCLUSIVE_DIST="$(metaconf ExclusiveDist)" } function set_source_dists { if [ "$FORCE_SOURCE_DISTS" ]; then SOURCE_DISTS="${FORCE_SOURCE_DISTS//[,:;]/ }" elif [ "$(rpmconf Nosource)" != "" ]; then SOURCE_DISTS="$(echo ${FORCE_DISTS//[,:;]/ } | cut -f1)" else SOURCE_DISTS="$(metaconf SourceDists)" fi } function set_tag { TAGS="$DEFAULT_TAGS" if [ -n "$FORCE_TAG" ]; then TAG="$FORCE_TAG" TAGS="$FORCE_TAG" else TAG="$(metaconf Tag)" fi if [ -z "$DEFAULT_TAG" ]; then DEFAULT_TAG="${DEFAULT_TAGS/ */}"; fi if [ -z "$TAG" ]; then TAG="$DEFAULT_TAG"; fi } function set_soapbox { if [ -n "$FORCE_SOAPBOX" ]; then SOAPBOX="$FORCE_SOAPBOX" else SOAPBOX="$(metaconf Soapbox)" fi if [ -z "$SOAPBOX" ]; then SOAPBOX="$USE_SOAPBOX"; fi } function set_as_root { if [ -n "$FORCE_AS_ROOT" ]; then AS_ROOT="$FORCE_AS_ROOT" else AS_ROOT="$(metaconf BuildAsRoot)" fi if [ -z "$AS_ROOT" ]; then AS_ROOT="$USE_ROOT"; fi } function set_distcc { if [ -n "$FORCE_DISTCC" ]; then DISTCC="$FORCE_DISTCC" else DISTCC="$(metaconf Distcc)" fi if [ -z "$DISTCC" ]; then DISTCC="$USE_DISTCC"; fi } function set_ccache { if [ -n "$FORCE_CCACHE" ]; then CCACHE="$FORCE_CCACHE" else CCACHE="$(metaconf Ccache)" fi if [ -z "$CCACHE" ]; then CCACHE="$USE_CCACHE"; fi } function download_sources { local RC=1 local ERC=0 local i=1 for url in $(spectool -l "$SPECFILE" 2>/dev/null | cut -f2 -d' '); do filename="$SPECDIR/$(basename $url)" if [ ! -s "$filename" ]; then warning "Source \"$(basename $filename)\" not found, downloading [$url]." local i=1 RC=1 while [ $RC -ne 0 -a $i -lt 4 ]; do # wget -v -t5 -T2 -O "$filename" "$url" wget -q -t30 -T2 --user-agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" -O "$filename" "$url" # wget -q -T1 -O "$filename" "$url" # lftpget "$url" -c -o "$filename" # lftpget "$url" -c -O "$(dirname $filename)" -o "$(basename $filename)" RC=$? i=$((i+1)) done if [ $RC -ne 0 ]; then error "Problems downloading source [$url]." ERC=1 fi fi done return $ERC } function build_env { local DISTNICK="$1" local DISTNAME="$2" local OPTIONS="" local RPMVER="$(chroot $CHROOTDIR/$DISTNICK rpm --version | cut -d' ' -f3)" if [ "$RPMVER" \> "4.0.2" ]; then OPTIONS="$OPTIONS --nodigest" fi if [ "$RPMVER" \> "4.0.99" ]; then OPTIONS="$OPTIONS --nosignature" fi chroot $CHROOTDIR/$DISTNICK rpm -qa $OPTIONS --qf "%{name}\t%{version}-%{release}\n"| sort >$STATEDIR/rpmqa-$DISTNAME-$DISTARCH.list 2>/dev/null } function build_htaccess { cat <"$PACKAGEDIR/.htaccess" Options +Indexes DirectoryIndex . #IndexOrderDefault Descending Date #IndexOptions +TrackModified +SuppressDescription IndexOptions +TrackModified EOF for dir in $(ls $PACKAGEDIR); do if [ -d "$PACKAGEDIR/$dir" ]; then SPECFILE="$(ls $PACKAGEDIR/$dir/*.spec | cut -d' ' -f1)" if [ -f "$SPECFILE" ]; then echo "AddDescription \"$(rpmconf Summary)\" $dir" >>"$PACKAGEDIR/.htaccess" fi fi done } function build_content { local DISTNAME="$1" local DISTPATH="$2" # find "$PACKAGEDIR/" -name "*.$TAG.$DIST.*.rpm" \ # -o -name "*.$DIST.$TAG.*.rpm" | \ # sed -e " # s|.\+/\(.\+\)-[0-9].\+-[0-9].*\.$TAG\.$DIST\..\+\.rpm|\1|; # s|.\+/\(.\+\)-[0-9].\+-[0-9].*\.$DIST\.$TAG\..\+\.rpm|\1|; # " | sort | uniq >$STATEDIR/packages-$DIST.list for rpm in $FTPDIR/$DISTPATH/RPMS.$REPO/*.rpm; do rpm="${rpm%-*-*}" echo "${rpm//#*\/}" done | sort | uniq >$STATEDIR/packages-$DISTNAME-$DISTARCH.list } function build_tree_apt { local DISTTAG="$1" local DISTPATH="$2" echo "Building Apt tree." ### Creating directories mkdir -p $FTPDIR/$DISTPATH/{base,RPMS.$REPO}/ ### Make SPEC files readable echo $PACKAGEDIR/*/*.spec | xargs chmod +r ### Removing old packages echo $FTPDIR/$DISTPATH/RPMS.$REPO/*.rpm | xargs rm -f ### FIXME: This should not be done hardcoded, rather have a list of archs inside the dist-config ### FIXME: And iterate through that list for disttag in $DISTTAG nodist 0; do for tag in $TAGS; do case "$DISTARCH" in i386) find $PACKAGEDIR -type f -a \( \ -name "*.$tag.$disttag.noarch.rpm" \ -o -name "*.$tag.$disttag.i?86.rpm" \ -o -name "*.$tag.$disttag.athlon.rpm" \ -o -name "*.$disttag.$tag.noarch.rpm" \ -o -name "*.$disttag.$tag.i?86.rpm" \ -o -name "*.$disttag.$tag.athlon.rpm" \) \ -exec ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ \; # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,i386,i586,i686,athlon}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,i386,i586,i686,athlon}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null ;; # x86_64) # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,i386,i586,i686,athlon,x86_64}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,i386,i586,i686,athlon,x86_64}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null # ;; *) find $PACKAGEDIR -type f -a \( \ -name "*.$tag.$disttag.noarch.rpm" \ -o -name "*.$tag.$disttag.$DISTARCH.rpm" \ -o -name "*.$disttag.$tag.noarch.rpm" \ -o -name "*.$disttag.$tag.$DISTARCH.rpm" \) \ -exec ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ \; # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,$DISTARCH}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,$DISTARCH}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/RPMS.$REPO/ &>/dev/null ;; esac done done } function build_repo_apt { local DISTPATH="$1" echo "Building Apt repo." if [ ! -d "$TEMPDIR/.cache/genbasedir/$DISTNICK/$REPO" ]; then mkdir -p "$TEMPDIR/.cache/genbasedir/$DISTNICK/$REPO" fi ### Build Apt repository genbasedir --flat --bloat --cachedir="$TEMPDIR/.cache/genbasedir/$DISTNICK/$REPO" --bz2only $FTPDIR/$DISTPATH $REPO >/dev/null # genbasedir --progress --flat --bloat $FTPDIR/$DISTPATH $REPO # genbasedir --progress --hashonly $FTPDIR/$DISTPATH $REPO } function build_tree_yum { local DISTTAG="$1" local DISTPATH="$2" echo "Building Yum tree." ### Creating directories mkdir -p $FTPDIR/$DISTPATH/$REPO/{RPMS,headers}/ ### Removing old packages echo $FTPDIR/$DISTPATH/$REPO/RPMS/*.rpm | xargs rm -f echo $FTPDIR/$DISTPATH/$REPO/headers/*.hdr | xargs rm -f ### FIXME: This should not be done hardcoded, rather have a list of archs inside the dist-config ### FIXME: And iterate through that list ### Hardlink files for disttag in $DISTTAG nodist 0; do for tag in $TAGS; do case "$DISTARCH" in i386) find $PACKAGEDIR -type f -a \( \ -name "*.$tag.$disttag.noarch.rpm" \ -o -name "*.$tag.$disttag.i?86.rpm" \ -o -name "*.$tag.$disttag.athlon.rpm" \ -o -name "*.$disttag.$tag.noarch.rpm" \ -o -name "*.$disttag.$tag.i?86.rpm" \ -o -name "*.$disttag.$tag.athlon.rpm" \) \ -exec ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ \; # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,i386,i586,i686,athlon}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,i386,i586,i686,athlon}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null ;; # x86_64) # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,i386,i586,i686,athlon,x86_64}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,i386,i586,i686,athlon,x86_64}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null # ;; *) find $PACKAGEDIR -type f -a \( \ -name "*.$tag.$disttag.noarch.rpm" \ -o -name "*.$tag.$disttag.$DISTARCH.rpm" \ -o -name "*.$disttag.$tag.noarch.rpm" \ -o -name "*.$disttag.$tag.$DISTARCH.rpm" \) \ -exec ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ \; # echo $PACKAGEDIR/*/*.$tag.$disttag.{noarch,$DISTARCH}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null # Backward compatibility # echo $PACKAGEDIR/*/*.{$disttag,0}.$tag.{noarch,$DISTARCH}.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DISTPATH/$REPO/RPMS/ &>/dev/null ;; esac done done # ln -f $PACKAGEDIR/*/*.$TAG.src.rpm $FTPDIR/$DISTPATH/$REPO/SRPMS/ &>/dev/null } function build_repo_yum { local DISTPATH="$1" echo "Building Yum repo." ### Build Yum repository # yum-arch -q -z -d -c $FTPDIR/$DISTPATH/$REPO/ yum-arch -q -z $FTPDIR/$DISTPATH/$REPO/ &>/dev/null } function build_repo { local DISTPATH="$1" local REPODATA="$FTPDIR/$DISTPATH/$REPO/repodata/" local DISTDESC="$2" echo "Building repomd." if [ "$DISTNICK" ]; then local RPMVER="$(chroot $CHROOTDIR/$DISTNICK rpm --version | cut -d' ' -f3)" fi local OPTIONS="" if [ "$RPMVER" \< "4.2.1" ]; then OPTIONS="-n" fi if [ -d "$FTPDIR/$DISTPATH/$REPO/.olddata/" ]; then rm -rf "$FTPDIR/$DISTPATH/$REPO/.olddata/" fi if [ ! -d "$TEMPDIR/.cache/createrepo/$DISTNICK/$REPO" ]; then mkdir -p "$TEMPDIR/.cache/createrepo/$DISTNICK/$REPO" fi createrepo -q $OPTIONS --checkts -c "$TEMPDIR/.cache/createrepo/$DISTNICK/$REPO" "$FTPDIR/$DISTPATH/$REPO" sync echo "" >"$REPODATA/repomd.xml" echo "" >>"$REPODATA/repomd.xml" for file in other filelists primary; do echo "### Generated by DAR, http://dag.wieers.com/home-made/dar/" >>"$REPODATA/repomd.xml" echo " " >>"$REPODATA/repomd.xml" echo " " >>"$REPODATA/repomd.xml" gunzip "$REPODATA/$file.xml.gz" echo " $(sha1sum "$REPODATA/$file.xml" | cut -f1 -d' ')" >>"$REPODATA/repomd.xml" gzip -9 --rsyncable -f "$REPODATA/$file.xml" echo " $(sha1sum "$REPODATA/$file.xml.gz" | cut -f1 -d' ')" >>"$REPODATA/repomd.xml" echo " $(stat -c "%Y" "$REPODATA/$file.xml.gz")" >>"$REPODATA/repomd.xml" echo " " >>"$REPODATA/repomd.xml" done echo "" >>"$REPODATA/repomd.xml" # echo "Building repoview." # repoview --quiet --title="RPMforge: $DISTDESC" "$FTPDIR/$DISTPATH/$REPO" # repoview --quiet --url="http://apt.sw.be/$DISTPATH/" "$FTPDIR/$DISTPATH/$REPO" } function build_repo_srpms { local DIR="$1" mkdir -p $FTPDIR/$DIR echo $FTPDIR/$DIR/*.src.rpm | xargs rm -f for tag in $TAGS; do echo $PACKAGEDIR/*/*.$tag.src.rpm | xargs -n 1 | xargs -i ln -f {} $FTPDIR/$DIR/ &>/dev/null done # genbasedir --bloat --bz2only $FTPDIR/$DISTPATH/ $REPO } #export LD_ASSUME_KERNEL="2.4.9" export LD_ASSUME_KERNEL ### Main if [ -r "$DARCONFIG" ]; then clean_env source "$DARCONFIG" else die "Cannot access configfile ($DARCONFIG)." fi if [ -r ~/".dar.conf" ]; then source ~/".dar.conf" fi