]> git.pld-linux.org Git - packages/vim.git/blob - update-source.sh
use sources file to detect patch updates
[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.3
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 "sources status not clean; commit or stash any pending changes"
32         echo "$status"
33         exit 1
34 fi
35
36 if [ "$1" ]; then
37         ver=$1
38 else
39         echo "Fetching latest patches list..."
40         wget -nv $sources -O sources
41         git status --porcelain sources
42
43         status=$(git status --porcelain sources)
44         if [ -z "$status" ]; then
45                 echo >&2 "No changes to 'sources'. All done"
46                 echo "$status"
47                 exit 0
48         fi
49         ver=$(tail -n1 sources | awk '{print $NF}')
50 fi
51
52 curpatch=$(awk '/^%define[      ]+patchlevel[   ]+/{print $NF}' $specfile)
53 curver=$basever.$curpatch
54
55 if [ "$curver" != "$ver" ]; then
56         echo "Updating $specfile to $ver"
57         patch=${ver#$basever.}
58         if [ -z "$patch" ]; then
59                 echo >&2 "Will not set empty patchlevel"
60                 exit 1
61         fi
62         sed -i -e "
63                 s/^\(%define[ \t]\+patchlevel[ \t]\+\)[0-9]\+\$/\1$patch/
64         " $specfile
65
66         WGET_OPTS="-nv" ../builder -g $specfile
67
68         if [ "$build_package" != 0 ]; then
69                 dist=$(rpm -E %{pld_release})
70                 arch=$(rpm -E %{_host_cpu})
71                 outdir=$(readlink -f $dir)/BUILD-$dist-$arch
72                 logfile=$outdir/$pkg.log
73                 rpmdir=$outdir/RPMS
74                 install -d $rpmdir
75
76                 # setup custom logfile via $HOME_ETC hack
77                 # TODO: just add --logfile support for builder
78                 cat > $outdir/.builderrc <<-EOF
79                         if [ -n "$HOME_ETC" ]; then
80                                 . "$HOME_ETC/.builderrc"
81                         elif [ -r ~/.builderrc ]; then
82                                 . ~/.builderrc
83                         fi
84                         LOGFILE='$logfile'
85                 EOF
86
87                 > $logfile
88                 HOME_ETC=$outdir \
89                         ../builder -bb --clean \
90                         --define "_unpackaged_files_terminate_build 1" \
91                         --define '_enable_debug_packages 0' \
92                         --define "_builddir $outdir" \
93                         --define "_rpmdir $rpmdir" \
94                         $specfile || {
95                         echo "Package build failed"
96                         tail -n 1000 $logfile >&2
97                         exit 1
98                 }
99
100                 rpmdest=~/public_html/$dist/$arch/
101                 if [ "$publish_packages" ] && [ "$(ls $rpmdir/*.rpm 2>/dev/null)" ]; then
102                         install -d $rpmdest
103                         umask 022
104                         chmod 644 $rpmdir/*.rpm
105                         mv -v $rpmdir/*.rpm $rpmdest/
106                         poldek --cachedir=$HOME/tmp --mkidx -s $rpmdest/ --mt=pndir
107                 fi
108         fi
109 else
110         echo "$specfile already up to $ver"
111 fi
This page took 0.081885 seconds and 4 git commands to generate.