+++ /dev/null
-#!/bin/sh
-
-. ~/pld-ftp-admin/scripts/functions
-
-move_noarch()
-{
- rpmname="$1"
- srcname="$2"
- f_arch="$3"
-
- # TODO: check if noarch differ and if so - mail the request sender or sth
- alreadypresent=`grep "^file:noarch:$rpmname$" $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info`
- if [ -n "$alreadypresent" ]; then
- rpm -qlp $rpmname > ~/tmp/files.new
- rpm -qRp $rpmname|sort|uniq > ~/tmp/reqs.new
-
- noarchs_differ="no"
- diff_file=~/tmp/noarchs_difference
- echo -ne "" > $diff_file
- if ! diff ~/tmp/{noarch-cache/$rpmname.filelist,files.new} >/dev/null; then
- noarchs_differ="yes"
- echo "_FILES_" >> $diff_file
- diff -u ~/tmp/{noarch-cache/$rpmname.filelist,files.new}>>$diff_file
- fi
-
- if ! diff ~/tmp/{noarch-cache/$rpmname.reqlist,reqs.new} >/dev/null; then
- noarchs_differ="yes"
- echo "_REQS_" >> $diff_file
- diff -u ~/tmp/{noarch-cache/$rpmname.reqlist,reqs.new} >> $diff_file
- fi
-
- if [ "$noarchs_differ" == "yes" ]; then
- send_noarch_msg $srcname $rpmname $diff_file
- fi
-
- rm $rpmname
- else
- rpm -qlp $rpmname > ~/tmp/noarch-cache/$rpmname.filelist
- rpm -qRp $rpmname|sort|uniq > ~/tmp/noarch-cache/$rpmname.reqlist
- chmod a+r $rpmname
- mv $rpmname $FTP_DIR/$DEFAULT_TO/noarch/RPMS/
- echo -e "file:noarch:$rpmname\ninfo:noarch_arch:$rpmname:$f_arch" >> \
- $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info
- fi
-}
-
-move_arch()
-{
- f_arch="$1" # arch
- f_name="$2" # filename
- moved="no"
-
- # Check if uploadinfo is fully uploaded
- FINISHED=`grep '^END$' $f_name`
- if [ -z "$FINISHED" ]; then
- return
- fi
-
- srcname=`grep '^file:SRPMS' $f_name|cut -d: -f 3`
- if [ ! -f $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info ]; then
- # TODO: Do something more interesting here... or not
- return
- fi
-
- remove="no"
- alreadypresent=`grep "^file:$f_arch:" $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info`
- if [ -n "$alreadypresent" ]; then
- log "files from $srcname for arch $f_arch already present in $DEFAULT_TO; removing newer files"
- remove="yes"
- fi
-
- for x in `grep '^file:ARCH:' $f_name|cut -d: -f 3`; do
- if [ "$remove" == "yes" ]; then
- rm $x
- else
- if [ -n "`echo $x|grep noarch.rpm$`" ]; then
- # Huston, we've got a noarch
- move_noarch $x $srcname $f_arch
- else
- # Move the files
- chmod a+r $x
- mv $x $FTP_DIR/$DEFAULT_TO/$f_arch/RPMS/
- echo "file:$f_arch:$x" >> \
- $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info
- fi
- fi
- done
-
- rm $f_name
-}
-
-lock_tree $DEFAULT_TO "quiet"
-
-cd $INCOMING_DIR/SRPMS
-for i in *uploadinfo; do
- if [ "$i" == "*uploadinfo" ]; then
- continue
- fi
- # Check if uploadinfo is fully uploaded
- FINISHED=`grep '^END$' $i`
- if [ -z "$FINISHED" ]; then
- continue
- fi
-
- srcname=`grep '^file:SRPMS' $i|cut -d: -f 3`
- dstinfofile="$FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info"
- if [ -f "$dstinfofile" ]; then
- log "$srcname.info already present in $DEFAULT_TO; removing newer files"
- echo "`grep ^info: $i`" >> $dstinfofile
- rm $srcname
- rm $i
- continue
- fi
-
- chmod a+r $srcname
- mv $srcname $FTP_DIR/$DEFAULT_TO/SRPMS/RPMS/
- echo "`grep ^info: $i`" > $dstinfofile
- echo "file:SRPMS:$srcname" >> $dstinfofile
- rm $i
-done
-
-for arch in $FTP_ARCHS; do
- cd $INCOMING_DIR/$arch
- for i in *uploadinfo; do
- if [ "$i" == "*uploadinfo" ]; then
- continue
- fi
- move_arch "$arch" "$i"
- done
-done
-
-unlock_tree $DEFAULT_TO
-
+++ /dev/null
-
-# Note: all functions expect to get N-V-R strings as pkg arguments (unless
-# it's obvious they shouldn't get them of course)
-
-# Read config
-if [ ! -f ~/.ftpadmrc ]; then
- echo "Config not found"
- exit
-fi
-
-. ~/.ftpadmrc
-
-# For logging
-scriptname=`basename $0`
-
-# Log a message... useful for debugging
-log() {
- echo `date "+%F %T"` "[$scriptname]" "--" "$@" >>~/pld-ftp-admin/var/log
-}
-
-# Wrapper so that we can test stuff without actually doing (allmost) anything
-if [ "$DEBUG" == "yes" ]; then
- rm()
- {
- echo "RM: $@" >&2
- }
- mv()
- {
- echo "MV: $@" >&2
- }
- cd()
- {
- command cd $1
- echo "CD: $1" >&2
- }
-fi
-
-# Lock a tree (and if already locked print a msg and exit)
-# Args: 1 - tree name
-# 2 - "quiet" mode
-lock_tree()
-{
- if [ -f ~/pld-ftp-admin/var/lock-$1 ]; then
- if [ "$2" != "quiet" ]; then
- echo "Lock for tree $1 already present. Exiting."
- fi
- exit
- fi
- touch ~/pld-ftp-admin/var/lock-$1
-}
-
-# Unlock a tree
-# Args: 1 - tree name
-unlock_tree()
-{
- rm -f ~/pld-ftp-admin/var/lock-$1
-}
-
-# Send an email to request senders about broken noarchs
-# Args: 1 - src.rpm
-# 2 - rpm name
-# 3 - file with message's body
-send_noarch_msg()
-{
- srcname="$1"
- rpmname="$2"
- m_body="$3"
-
- req_email="`cat $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info| \
- grep '^info:requester_email:'|cut -d: -f 3|head -1`"
- cur_arch="`cat $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info| \
- grep ^info:noarch_arch:$rpmname:|cut -d: -f 4`"
- m_subject="Noarch error: $rpmname files differ between builders"
-
- cc_list="`cat $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info| \
- grep '^info:requester_email:'|cut -d: -f 3|grep -v ^$req_email$| \
- sort|uniq|xargs echo|sed -e 's/ /, /g'`"
-
- req_buildid="`cat $FTP_DIR/$DEFAULT_TO/SRPMS/.metadata/$srcname.info| \
- grep ^info:buildid:|cut -d: -f 3`"
-
- (echo -ne "From: $FROM_FIELD
-To: $req_email
-Cc: $cc_list
-X-PLD-Builder: $XPLDBUILDER
-References: <$req_buildid@pld.src.builder>
-In-Reply-To: <$req_buildid@pld.src.builder>
-Subject: $m_subject\n\n";
- cat "$m_body"| sed \
- -e "s,^_FILES_,Difference between $cur_arch (currently in $DEFAULT_TO) and $f_arch FILES," \
- -e "s,^_REQS_,Difference between $cur_arch (currently in $DEFAULT_TO) and $f_arch REQS," | \
- grep -v '^---\|^+++') | /usr/sbin/sendmail -t
-}
-
-errnum="0"
-pkglist=""
-# Fill $pkglist
-# Args: 1 - ftp tree to check against
-# 2 - list of args
-init_pkglist()
-{
- for i in $2; do
- pkg=`echo $i|sed -e 's,.src.rpm$,,'`
- if [ ! -f "$FTP_DIR/$1/SRPMS/.metadata/$pkg.src.rpm.info" ]; then
- errnum=$(($errnum+1))
- echo "$pkg was not found in source tree"
- else
- pkglist="$pkglist $pkg"
- fi
- done
-}
-
-# Check if all builders said they're finished with the package
-# Args: 1 - ftp tree
-# pkglist
-check_buildids()
-{
- cd ~/tmp
- rm -f queue.txt
- wget -nv "http://ep09.pld-linux.org/~builderth/queue.txt"
- echo "------------------------------------------"
- cat queue.txt|grep '^group:\|builders:'| \
- sed -e 's,^[ ]*,,' -e 's,^group.*id=\(.*\) pri=.*$,\1:,' |\
- perl -e '$_=join("",<STDIN>);~s/\nbuilders://g;print;'>q.txt
-
- cd "$FTP_DIR/$1/SRPMS/.metadata/"
- for pkg in $pkglist; do
- for buildid in `grep ^info:buildid: $pkg.src.rpm.info|cut -d: -f 3`; do
- if [ -n "`grep ^$buildid: ~/tmp/q.txt|grep '?'`" ]; then
- errnum=$(($errnum+1))
- echo "Building of package $pkg (buildid $buildid) not finished"
- fi
- done
- done
-}
-
-# Check if we won't remove some arch when moving
-# Args: pkglist, srctree, dsttree
-check_built_archs()
-{
- cd "$FTP_DIR/$dsttree/SRPMS/.metadata/"
- for pkg in $pkglist; do
- olderpkgs=`find_other_pkgs "$dsttree" "$pkg"`
- if [ -z "$olderpkgs" ]; then
- continue
- fi
- # Archs that are already provided by the package that's in dest tree
- availablearchs=""
- for oldpkg in $olderpkgs; do
- tmparchs="`cat $oldpkg.src.rpm.info|grep ^file:| \
- cut -d: -f 2|sort|uniq`"
- availablearchs="$tmparchs $availablearchs"
- done
- availablearchs="`echo \"$availablearchs\"|sort|uniq`"
- grepstring=`echo $availablearchs| \
- sed -e 's,^,^,' -e 's,$,$,' -e 's, ,$\\\|^,g'`
- newarchs="`cat $FTP_DIR/$srctree/SRPMS/.metadata/$pkg.src.rpm.info| \
- grep ^file:|cut -d: -f 2|sort|uniq`"
- # Number of archs already provided by the package that's in dest tree
- availablearchsnum="`echo \"$availablearchs\"|wc -l`"
- # Number of archs supported by dst pkg that are supported by src pkg
- diffnum="`echo \"$newarchs\"|grep $grepstring|wc -l`"
-
- if [ $availablearchsnum != $diffnum ]; then
- errnum=$(($errnum+1))
- echo "$availablearchs">~/tmp/a.list
- echo "$newarchs" > ~/tmp/n.list
- missingarchs=`diff ~/tmp/{a,n}.list |grep '^<'|sed -e 's,^..,,'`
- echo "Moving package $pkg would remove archs: $missingarchs"
- fi
- done
-}
-
-
-# Return a list of packages that differ only by version than the one given
-# Args: $1 - the package we're intersted in (in N-V-R format)
-# Note1: we assume we're in .metadata dir
-# Note2: the list returned is newline, not space, separated
-# Note3: sets $glob_basename to basename (without V-R) if anybody need's it
-glob_packages()
-{
- # Get just the name without the version tag
- basename=`echo $1|sed -e 's,-[^-]*-[^-]*$,,'`
- # Find packages beginning with that name
- allpkgs=`echo $basename*`
- if [ "$allpkgs" == "$basename*" ]; then
- # No files found
- return
- fi
- allpkgs=`echo "$allpkgs"|sed -e 's, ,\n,g' -e 's,.src.rpm.info,,g'`
- # Filter out pkgs that just begin with basename, but ain't other
- # versions of that package
- allpkgs=`echo "$allpkgs"|grep "$basename-[^-]*-[^-]*$"`
- echo "$allpkgs"
-}
-
-# Generate a list of older packages
-# Args: $1 - ftp tree
-# $2 - packages we're interested in
-find_older_pkgs()
-{
- cd "$FTP_DIR/$1/SRPMS/.metadata/"
- list=""
- for pkg in $2; do
- # "Glob" for other pkgs
- allpkgs=`glob_packages $pkg`
- # Get just the name without the version tag (we need it)
- basename=`echo $pkg|sed -e 's,-[^-]*-[^-]*$,,'`
- # Get only versions
- allpkgs=`echo "$allpkgs"|sed -e "s,^$basename-,,"`
- # Sort (note - this ain't perfect sorting)
- allpkgs=`echo "$allpkgs"|sort -n`
- # Readd names
- allpkgs=`echo "$allpkgs"|sed -e "s,^,$basename-,"`
- # Grep packages < current package
- allpkgs=`echo "$allpkgs"|grep -B 999 "$pkg"|grep -v "^$pkg$"`
- # Add to the list
- allpkgs=`echo $allpkgs`
- list="$list $allpkgs"
- done
- echo $list
-}
-
-# Generate a list of all packages (glob name-*) except the one given
-# Args: $1 - ftp tree
-# $2 - packages we're interested in
-find_other_pkgs()
-{
- cd "$FTP_DIR/$1/SRPMS/.metadata/"
- list=""
- for pkg in $2; do
- # "Glob" for other pkgs
- allpkgs=`glob_packages $pkg`
- # Cut out our own package
- allpkgs=`echo "$allpkgs"|grep -v "^$pkg$"`
- # Add to the list
- allpkgs=`echo $allpkgs`
- list="$list $allpkgs"
- done
- echo $list
-}
-
-# Remove packages in given tree
-# Args: $1 - ftp tree
-# $2 - list of packages to remove
-# $3 - force option
-remove_pkgs() {
- cd "$FTP_DIR/$1/SRPMS/.metadata/"
- rmopt=""
- if [ "$3" == "force" ]; then
- rmopt="-f"
- fi
- for pkg in $2; do
- # Remove all files connected to the old src.rpm
- # (+ the src.rpm itself)
- for i in `grep '^file:' $pkg.src.rpm.info`; do
- arch=`echo $i|cut -d: -f 2`
- file=`echo $i|cut -d: -f 3`
- rm $rmopt "$FTP_DIR/$1/$arch/RPMS/$file"
- done
- # And finally remove the .info file
- rm $rmopt $pkg.src.rpm.info
- done
-}
-
-# vi: syntax=sh