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