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