--- /usr/ports/contrib/prtsync/prtsync 2005-04-14 16:30:42.000000000 -0500 +++ prtsync 2005-08-11 08:44:33.000000000 -0500 @@ -2,8 +2,7 @@ # # Synchronize several httpup repositories to a centralized collection. # - -. /etc/prtsync.conf +. /home/crux/prtsync/prtsync.conf # Print $1 to stderr and exit. error(){ @@ -23,6 +22,27 @@ fi } +# added by jw/23.05.2005 +conflict_exists() { + if [ ! -f $CONFLICTS ]; then + return 1 + fi + return `grep -q ^$1$ $CONFLICTS` +} + +# Sends a Cc notification email to address(es) $1 with subject $2 +# and body $3. Mails are always sent to $mailer. +notify_to(){ + /usr/sbin/sendmail -t -f$mailer <<-EOF + To: $1 + Subject: $2 + + $3 + + Please rectify the problem. +EOF +} + # Sends a Cc notification email to address(es) $1 with subject $2 # and body $3. Mails are always sent to $mailer. notify(){ @@ -82,10 +102,12 @@ url=`fgrep "URL=" $driver | sed "s/URL=//"` collection=`basename $driver .httpup` - if httpup sync $url $2/$collection >/dev/null 2>&1; then + error=`httpup sync $url $2/$collection 2>&1` + if [ $? -eq 0 ]; then synced="$synced $collection " else #notify of failure - notify "$email" "Sync failed for $collection" "" + notify_to "$email,$prtsync_admin" "Sync failed for $collection: " \ + "$error" failed="$failed $collection " fi done @@ -102,14 +124,15 @@ echo "Merging ports in $2 to $3.." - mv $3/.current $3/.prev 2>/dev/null + mv $2/.current $2/.prev 2>/dev/null if [ "$ignore_tag_files" = "true" ]; then #merge all ports ports=`find $2 -mindepth 2 -type d | sort` else #or only tagged ones ports=`find $2 -mindepth 3 -name .sync | sed 's|/\.sync||' | sort` fi - + + rm -f $CONFLICTS_NEW for port in $ports; do #prune duplicates, notify affected parties p=`basename $port` @@ -122,18 +145,29 @@ drivers=`echo -e "\n\n$paths" | sed "s|^$2/|$1/|; s|/$p|.httpup|g"` emails=`fgrep -h "EMAIL=" $drivers | sed "s/EMAIL=//g"` - notify "$emails" "Duplicate port $p" "Port $p found in:$drivers" + c=`echo $paths|sed -e "s|$2/||g; s|/$p||g"|tr ' ' :` + c="$c:$p" + if conflict_exists $c; then + echo "Ignoring previously announced conflict: $c" + else + notify "$emails" "Duplicate port $p" "Port $p found in:$drivers" + fi duplicated="$duplicated $p " + echo $c >> $CONFLICTS_NEW test -d $4/$p && port=$4/$p || continue #use attic or skip fi - test -d $base/$p -o -d $opt/$p || cp -r $port $3 - echo $p >>$3/.current + # added test against contrib; jw + test -d $base/$p -o -d $opt/$p -o -d $contrib/$p || cp --preserve=timestamps -r $port $3 + echo $p >>$2/.current done + if [ -f $CONFLICTS_NEW ]; then + mv $CONFLICTS_NEW $CONFLICTS + fi - if [ -f $3/.current ]; then #generate REPO, ignoring archive + if [ -f $2/.current ]; then #generate REPO, ignoring archive echo "TARBALL" > $3/.httpup-repgen-ignore httpup-repgen $3 >/dev/null @@ -143,11 +177,11 @@ fi fi - if [ -f $3/.prev ]; then #resolve added/removed - added=`diff $3/.prev $3/.current | grep '>'` - removed=`diff $3/.prev $3/.current | grep '<'` + if [ -f $2/.prev ]; then #resolve added/removed + added=`diff $2/.prev $2/.current | grep '>'` + removed=`diff $2/.prev $2/.current | grep '<'` else #no .prev, all ports were added - added=`cat $3/.current 2>/dev/null` + added=`cat $2/.current 2>/dev/null` fi echo " Added: $added" | sed 's/ /\n/g; s/> //g' @@ -156,6 +190,7 @@ echo } + # # Execution begins. Process arguments and dispatch function calls. # @@ -163,6 +198,8 @@ test "$1" = "-i" && ignore_tag_files="true" && shift test "$1" = "-a" && use_archive="true" && shift + + case $1 in "tag") #client mode, tag/untag ports in $2 or pwd collection=$2; test -d $collection || collection=`pwd` @@ -173,6 +210,12 @@ ;; "sync") #sync repos to $work, notify of errors + # don't do anything if we have no network connection + ping -c1 www.google.com &> /dev/null + if [ $? -ne 0 ]; then + echo "Network seems to be down; not sync'ing" + exit -1 + fi mkdir -p $work; ensure_path $work "w" ensure_path $collections "r" @@ -184,17 +227,19 @@ ensure_path $work "r" ensure_path $base "r" ensure_path $opt "r" + ensure_path $contrib "r" mkdir -p $destination; ensure_path $destination "w" mkdir -p $attic; ensure_path $attic "w" export GLOBIGNORE="TARBALL:.*" #keep archive and dotfiles + rm -rf $attic/* # <- added jw + (cd $destination; mv -f * $attic) chmod 700 $destination $attic #drop permissions for merge - (cd $destination; mv -f * $attic 2>/dev/null) - merge_ports $collections $work $destination $attic chmod 755 $destination $attic #and then restore them + rm -rf $attic/* # <- added jw; don't keep attic after merge ;; *) #show usage and exit echo "Usage: prtsync [options] command" >&2