16bcfe0
#!/bin/bash
4a08e5d
debug=""
4a08e5d
#debug="echo"
16bcfe0
5a0d8bf
cd $HOME/src/fedora/rpms/vim/master/
16bcfe0
LANG=C
16bcfe0
SPEC=vim.spec
16bcfe0
16bcfe0
DATE=`date +"%a %b %d %Y"`
16bcfe0
MAJORVERSION=`grep "define baseversion" vim.spec | cut -d ' ' -f 3`
16bcfe0
CHLOG="* $DATE Karsten Hopp <karsten@redhat.com> $MAJORVERSION"
4a08e5d
ORIGPL=`grep "define patchlevel" vim.spec | cut -d ' ' -f 3 | sed -e "s/^0*//g"`
4a08e5d
ORIGPLFILLED=`printf "%03d" $ORIGPL`
16bcfe0
PL=$ORIGPL
16bcfe0
5a0d8bf
git pull
9d2110c
16bcfe0
while true; do
5a0d8bf
    LASTPL=$PL
5a0d8bf
    LASTPLFILLED=`printf "%03d" $LASTPL`
16bcfe0
    PL=$((PL+1))
5a0d8bf
    PLFILLED=`printf "%03d" $PL`
5a0d8bf
    PNAME="$MAJORVERSION.$PLFILLED"
16bcfe0
    URL="ftp://ftp.vim.org/pub/vim/patches/$MAJORVERSION/$PNAME"
16bcfe0
    wget -nc $URL 2>/dev/null
16bcfe0
    if [ "$?" -ne "0" ]; then
16bcfe0
        # Patchlevel not yet available, back down
5a0d8bf
        PL=$LASTPL
5a0d8bf
        PLFILLED=$LASTPLFILLED
5a0d8bf
        LASTPL=$((LASTPL-1))
5a0d8bf
        LASTPLFILLED=`printf "%03d" $LASTPL`
16bcfe0
        if [ "$PL" == "$ORIGPL" ]; then
16bcfe0
            echo "No new patchlevel available"
16bcfe0
            exit
16bcfe0
        fi
16bcfe0
        break
16bcfe0
    else
16bcfe0
        # echo "Got patchlevel $MAJORVERSION.$PL, current CVS is at $MAJORVERSION.$ORIGPL"
4a08e5d
        $debug git add $PNAME
4a08e5d
        $debug git commit -m "- patchlevel $PLFILLED" $PNAME
4a08e5d
        sed -i -e "/Patch$LASTPLFILLED: ftp:\/\/ftp.vim.org\/pub\/vim\/patches\/$MAJORVERSION\/$MAJORVERSION.$LASTPLFILLED/aPatch$PLFILLED: ftp:\/\/ftp.vim.org\/pub\/vim\/patches\/$MAJORVERSION\/$MAJORVERSION.$PLFILLED" $SPEC
4a08e5d
        sed -i -e "/patch$LASTPLFILLED -p0/a%patch$PLFILLED -p0" $SPEC
16bcfe0
    fi
16bcfe0
done
0dbda49
sed -i -e "/Release: /cRelease: 1%{?dist}" $SPEC
4a08e5d
sed -i -e "s/define patchlevel $ORIGPLFILLED/define patchlevel $PLFILLED/" $SPEC
4a08e5d
sed -i -e "/\%changelog/a$CHLOG.$PLFILLED-1\n- patchlevel $PLFILLED\n" $SPEC
16bcfe0
wget ftp://ftp.vim.org/pub/vim/patches/$MAJORVERSION/README -O README.patches
a998f9b
$debug git add vim.spec README.patches
4a08e5d
$debug git commit -m "- patchlevel $PL" 
bba8e96
$debug git push
bba8e96
if [ $? -eq 0 ]; then
bba8e96
    $debug rm -f $HOME/.koji/config
bba8e96
    $debug fedpkg build
bba8e96
    $debug ln -sf $HOME/.koji/s390-config config
bba8e96
else
bba8e96
    echo "GIT push failed"
bba8e96
fi