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