makepending 4.06 KB
Newer Older
Ruben Rodriguez's avatar
Ruben Rodriguez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/bin/bash
#
#    Copyright (C) 2009,2010,2011  Ruben Rodriguez <ruben@trisquel.info>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
#
#
#    This script compares two Sources.gz files, and reports available updates

23 24 25
if [ $(git status -s | wc -l) != 0 ]
then
    echo You have uncommited git changes, stopping
26
    [ 1$1 = 1"test" ] || exit 1
27 28
fi

Ruben Rodriguez's avatar
Ruben Rodriguez committed
29 30 31
PAIRS="taranis-lucid toutatis-precise belenos-trusty"
CODENAMES="taranis toutatis belenos"
UPSTREAMS="lucid precise trusty"
32

Ruben Rodriguez's avatar
Ruben Rodriguez committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
[ 1$1 = 1"test" ] && TEST=echo

WD=$PWD
LOGS=$PWD/logs
[ -d $LOGS ] || mkdir $LOGS
export LANG=C
FILE=$(mktemp)
TMP=$(mktemp -d)
cd $TMP

echo "List of packages with available updates:
" > $FILE

listmirror (){
DIST=$1
COMPONENT=$2
echo -n Downloading Sources.gz from $MIRROR/dists/$DIST/$COMPONENT/source/Sources.gz >&2
wget $MIRROR/dists/$DIST/$COMPONENT/source/Sources.gz -q -O - | zcat | egrep dsc$ | cut -d" " -f 4|sed 's/\.dsc//'
echo " Done" >&2
}

update(){

MIRROR="http://archive.ubuntu.com/ubuntu"

58
for i in $UPSTREAMS
Ruben Rodriguez's avatar
Ruben Rodriguez committed
59 60 61 62 63 64 65 66 67
do
    listmirror $i main >> $i
    listmirror $i-updates main >> $i
    listmirror $i-security main >> $i
    listmirror $i universe >> $i
    listmirror $i-updates universe >> $i
    listmirror $i-security universe >> $i
done

68
for i in  $CODENAMES
Ruben Rodriguez's avatar
Ruben Rodriguez committed
69
do
70
    MIRROR="http://archive.trisquel.info/trisquel"
Ruben Rodriguez's avatar
Ruben Rodriguez committed
71 72 73 74
    listmirror $i main >> $i
    listmirror $i-updates main >> $i
    listmirror $i-security main >> $i

75 76 77
    MIRROR="http://devel.trisquel.info/trisquel/$i"
    listmirror $i main >> $i
done
Ruben Rodriguez's avatar
Ruben Rodriguez committed
78 79 80 81 82 83 84 85 86 87 88 89

}

higher(){
LIST="$(echo $* |sed 's/:/./g; s/+/./g') EOL"

HI=$(echo $LIST | cut -d" " -f1)
LIST=$(echo $LIST | cut -d" " -f2-)

while [ "$LIST" != "EOL" ]
do
    TEST=$(echo $LIST | cut -d" " -f1)
90
    dpkg --compare-versions $HI lt $TEST 2>/dev/null && HI=$TEST
Ruben Rodriguez's avatar
Ruben Rodriguez committed
91 92 93 94 95 96 97 98 99 100 101 102 103
    LIST=$(echo $LIST | cut -d" " -f2-)
done
echo $HI
}

check(){
for package in $PACKAGES
do
LIST=$(egrep ^${package}_ $DISTRO)
current=$( higher $LIST)
LIST=$(egrep ^${package}_ $UPSTREAM)
upstream=$( higher $LIST)

104
if dpkg --compare-versions $current lt $upstream 2>/dev/null
Ruben Rodriguez's avatar
Ruben Rodriguez committed
105 106 107 108 109 110 111 112
then

 #   echo Current version in $DISTRO: $current 1>&2
 #   echo Upstream version in $UPSTREAM: $upstream 1>&2

    echo Current version in $DISTRO: $current
    echo Upstream version in $UPSTREAM: $upstream
    [ $current = "EOL" ] && continue
113
    if [ $package = "grub2" ]
Ruben Rodriguez's avatar
Ruben Rodriguez committed
114
    then
115
        echo WARNING! grub2 packages need to be manually compiled!
Ruben Rodriguez's avatar
Ruben Rodriguez committed
116 117 118 119
        echo
        continue
    fi

120 121 122 123
    cd $WD
    $TEST git checkout $DISTRO
    $TEST git merge master
    cd $TMP
124 125 126 127
    echo Upgrading $current at $DISTRO with ${UPSTREAM}_$upstream 1>&2
    echo Running makepackage $package $DISTRO at $(date) $LOGS/$DISTRO-$package-$(date +%Y%m%d).log
    echo Running makepackage $package $DISTRO at $(date) $LOGS/$DISTRO-$package-$(date +%Y%m%d).log 1>&2
    $TEST sh $WD/makepackage $package $DISTRO > $LOGS/$DISTRO-$package-$(date +%Y%m%d).log && echo -n Done! || echo -n FAILED!
Ruben Rodriguez's avatar
Ruben Rodriguez committed
128 129 130 131 132 133 134 135
    echo " ($(date))"
    echo
fi
done
}

update

136 137 138 139 140
for pair in $PAIRS
do
DISTRO=${pair/-*/}
UPSTREAM=${pair/*-/}
PACKAGES=$(git --git-dir=/home/systems/devel/.git ls-tree -r --name-only $DISTRO|grep helpers/make-|sed 's/.*make-//')
Ruben Rodriguez's avatar
Ruben Rodriguez committed
141
check >> $FILE
142
done
Ruben Rodriguez's avatar
Ruben Rodriguez committed
143 144 145 146 147 148 149 150

report () {
#address=trisquel-devel@listas.trisquel.info
address=ruben@trisquel.info

echo "Subject: Compiling updates
To: $address

151
$(cat $FILE)"  | $TEST /usr/sbin/sendmail -f watchdog@devel.trisquel.info -h correo.sognus.com -t $address
Ruben Rodriguez's avatar
Ruben Rodriguez committed
152 153 154 155
}

grep -q makepackage $FILE && $TEST report
rm $FILE $TMP -rf