#! /bin/sh

umask 022
export PATH='/bin:/usr/bin:/usr/local/bin'

if [ Packages.* = 'Packages.*' ] 2>/dev/null; then
    if [ ! -d $HOME/diet-pc/all ]; then
	cat 1>&2 <<EOF
$HOME/diet-pc/\$ARCH directories are missing - must run "dpc-pull" first!
EOF
	exit 1
    fi
    cd $HOME/diet-pc
    [ -s ipkg.conf ] && ALTCONF='-f ipkg.conf' || ALTCONF=
    ARCHLIST=`ipkg $ALTCONF -V 0 print_architecture | cut -f2 -d' ' | \
	    tr '\n' ' '`
    /bin/echo -e "Push ${ARCHLIST}to http://dietpc.org/feeds/3/? [y]\c"
    read CONFIRM
    [ "$CONFIRM" != '' -a "$CONFIRM" != 'y' ] && exit 0
    for ARCH in $ARCHLIST; do
	echo "*** Synchronizing \"$ARCH\" feed ... "
	rsync -avc --delete --rsh='ssh -o Port=1009' $* $ARCH/ \
		whitpa@dietpc.org:public_html/feeds/3/$ARCH/
	echo
    done
else
    ARCH=`basename $PWD`
    /bin/echo -e "Push $PWD to http://dietpc.org/feeds/3/${ARCH}? [y]\c"
    read CONFIRM
    [ "$CONFIRM" != '' -a "$CONFIRM" != 'y' ] && exit 0
    exec rsync -avc --delete --rsh='ssh -o Port=1009' $* ./ \
	    whitpa@dietpc.org:public_html/feeds/3/$ARCH/
fi
