]> git.pld-linux.org Git - packages/vim.git/blob - update-source.sh
update-source: also reset fractal releases
[packages/vim.git] / update-source.sh
1 #!/bin/sh
2 # Usage:
3 # ./update-source.sh
4 # env variables controlling behaviour
5 #  build_package=[0|1] - build package when new version is fetched
6 #  publish_packages=[0|1] - publish built packages in ~/public_html/$dist/$arch
7 #  quiet=[0|1] - discard stdout of process
8
9 # work in package dir
10 dir=$(dirname "$0")
11 cd "$dir"
12
13 # abort on errors
14 set -e
15
16 # setup $quiet, you may override with env it
17 quiet=${quiet:-$(tty -s && echo 0 || echo 1)}
18 if [ "$quiet" = "1" ]; then
19         # we do not want output when running on cron
20         exec 1>/dev/null
21 fi
22
23 pkg=vim
24 specfile=$pkg.spec
25 basever=7.4
26 baseurl=ftp://ftp.vim.org/pub/editors/vim/patches/$basever
27 sources=ftp://ftp.vim.org/pub/editors/vim/patches/$basever/MD5SUMS
28
29 status=$(git status --porcelain sources)
30 if [ "$status" ]; then
31         echo >&2 "WARNING: sources status not clean; commit or stash any pending changes"
32         echo "$status"
33 fi
34
35 if [ "$1" ]; then
36         ver=$1
37 else
38         echo "Fetching latest patches list..."
39         wget -nv $sources -O sources.tmp 2>&1
40         sort -k 2 -V < sources.tmp > sources.new
41         # exclude files already in git tree
42         git ls-files "$basever.*" | sed -e 's/\./\\./g;s/$/$/'| grep -vf - sources.new > sources
43         rm sources.new sources.tmp
44         # also update patches README
45         wget -nv $baseurl/README -O README.patches 2>&1
46         ver=$(tail -n1 sources | awk '{print $NF}')
47 fi
48
49 curpatch=$(awk '/^%define[      ]+patchlevel[   ]+/{print $NF}' $specfile)
50 curver=$basever.$curpatch
51
52 if [ "$curver" != "$ver" ]; then
53         echo "Updating $specfile to $ver"
54         patch=${ver#$basever.}
55         if [ -z "$patch" ]; then
56                 echo >&2 "Will not set empty patchlevel"
57                 exit 1
58         fi
59         sed -i -e "
60                 s/^\(%define[ \t]\+patchlevel[ \t]\+\)[0-9]\+\$/\1$patch/
61                 s/^\(%define[ \t]\+rel[ \t]\+\)[0-9.]\+\$/\11/
62         " $specfile
63
64         # fetch missing/mismatching files manually. faster than builder script does that
65         md5sum -c sources 2>/dev/null | awk -F: '$NF != " OK" {print $1}' | while read file; do
66                 echo "$baseurl/$file"
67         done | wget -nv -i -
68
69         WGET_OPTS="-nv" ../builder -g $specfile
70
71         if [ "$build_package" != 0 ]; then
72                 dist=$(rpm -E %{pld_release})
73                 arch=$(rpm -E %{_host_cpu})
74                 outdir=$(readlink -f $dir)/BUILD-$dist-$arch
75                 logfile=$outdir/$pkg.log
76                 rpmdir=$outdir/RPMS
77                 install -d $rpmdir
78
79                 # setup custom logfile via $HOME_ETC hack
80                 # TODO: just add --logfile support for builder
81                 cat > $outdir/.builderrc <<-EOF
82                         if [ -n "$HOME_ETC" ]; then
83                                 . "$HOME_ETC/.builderrc"
84                         elif [ -r ~/.builderrc ]; then
85                                 . ~/.builderrc
86                         fi
87                         LOGFILE='$logfile'
88                 EOF
89
90                 > $logfile
91                 HOME_ETC=$outdir \
92                         ../builder -bb --clean \
93                         --define "_unpackaged_files_terminate_build 1" \
94                         --define '_enable_debug_packages 0' \
95                         --define "_builddir $outdir" \
96                         --define "_rpmdir $rpmdir" \
97                         $specfile || {
98                         echo "Package build failed" >&2
99                         tail -n 1000 $logfile >&2
100                         exit 1
101                 }
102                 echo >&2 "Package build OK"
103
104                 rpmdest=~/public_html/$dist/$arch/
105                 if [ "$publish_packages" ] && [ "$(ls $rpmdir/*.rpm 2>/dev/null)" ]; then
106                         install -d $rpmdest
107                         umask 022
108                         chmod 644 $rpmdir/*.rpm
109                         mv -v $rpmdir/*.rpm $rpmdest/
110                         poldek --cachedir=$HOME/tmp --mkidx -s $rpmdest/ --mt=pndir
111                 fi
112         fi
113
114         # autocommit
115         msg=$(mktemp)
116         echo "updated to $ver" > $msg
117         echo "" >> $msg
118         over=$(git diff sources | awk '/^\+[0-9a-f]+/{over=$NF; gsub(/\./, "\\.",over); print over; exit}')
119         sed -ne "/$over/,\$p" README.patches | sed -re 's,^[ 0-9]+ ,,' >> $msg
120         git commit -F $msg $specfile sources
121         rm -f $msg
122 else
123         echo "$specfile already up to $ver"
124 fi
This page took 0.102348 seconds and 4 git commands to generate.