]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - shrc.sh
shrc: ac-tag: fetch tags before checking for tags
[packages/rpm-build-tools.git] / shrc.sh
1 # shell aliases and functions for PLD Developer
2
3 # set $dist, used by functions below
4 [ -n "$dist" ] || dist=$(awk '/PLD Linux/ {print tolower($NF)}' /etc/pld-release 2>/dev/null | tr -d '()')
5
6 case "$dist" in
7 ac|th|ti)
8         ;;
9 *)
10         # invalid one ;)
11         dist=
12 esac
13
14 if [ "$dist" ]; then
15
16 alias ipoldek-$dist="poldek -q --sn $dist --cmd"
17 alias $dist-provides="ipoldek-$dist what-provides"
18 alias $dist-verify=dist-verify
19 alias $dist-requires=dist-requires
20
21 # move AC-branch tag to current checkout
22 # if AC-branch as branch exists, it is first removed
23 ac-tag() {
24         # see if remote has branch present
25         local branch=AC-branch
26         if git show-ref -q refs/remotes/origin/$branch; then
27                 git fetch --tags
28                 if [ -z "$(git tag --points-at $branch 2>/dev/null)" ]; then
29                         echo >&2 "There's no tag pointing to current $branch; refusing to delete branch"
30                         return 1
31                 fi
32                 git push --delete origin $branch
33         fi
34
35         git tag -f $branch
36         git push origin $branch
37 }
38
39 # undo spec utf8
40 # note: it will do it blindly, so any lang other than -pl is most likely broken
41 specutfundo() {
42         local spec="$1"
43         iconv -futf8 -tlatin2 "$spec" > m
44         sed -e 's/\.UTF-8//' m > "$spec"
45         rm -f m
46 }
47
48 dist-requires() {
49         local opts deps
50         while [ $# -gt 0 ]; do
51                 case "$1" in
52                 --sn)
53                         opts="$opts $1 $2"
54                         shift
55                         ;;
56                 -*)
57                         opts="$opts $1"
58                         ;;
59                 *)
60                         deps="$deps $1"
61                         ;;
62                 esac
63                 shift
64         done
65
66         case "$dist" in
67         ac)
68                 opts="$opts --sn=$dist-updates"
69                 ;;
70         esac
71
72         poldek -q -Q --sn $dist $opts --cmd what-requires $deps
73 }
74
75 dist-verify() {
76         local args sn
77         sn="--sn $dist"
78
79         case "$dist" in
80         ac)
81                 sn="$sn --sn $dist-updates"
82
83                 local a ignore
84                 # typo
85                 ignore="$ignore kdenetwork-kopete-tool-conectionstatus"
86                 # obsoleted
87                 ignore="$ignore gimp-plugin-swfdec wine-drv-arts ntp-ntptrace"
88                 # quake2@MAIN is now quake2forge, original quake2 restored to quake2
89                 ignore="$ignore quake2-3dfx quake2-sdl quake2-sgl quake2-snd-alsa quake2-snd-ao quake2-snd-oss quake2-snd-sdl quake2-static"
90                 # obsoleted
91                 ignore="$ignore mozilla-firefox-lang-en apache1-mod_perl-devel libyasm-static"
92                 # renamed (courier-authlib.spec, r1.54)
93                 ignore="$ignore courier-authlib-userdb courier-authlib-pipe"
94                 # obsoleted, squid 2.6
95                 ignore="$ignore squid-winbind_acl squid-winbind_auth"
96                 # obsoleted with 1.0.4
97                 ignore="$ignore python-numpy-FFT python-numpy-MA python-numpy-RNG"
98                 # subpkgs renamed
99                 ignore="$ignore apache1-doc apache1-index"
100                 # obsoleted by kadu-module-mediaplayer-amarok
101                 ignore="$ignore kadu-module-amarok"
102                 # obsoleted by kadu-module-mediaplayer-xmms
103                 ignore="$ignore kadu-module-xmms"
104                 # obsoleted by kadu 0.6.0
105                 ignore="$ignore kadu-theme-icons-crystal16 kadu-theme-icons-crystal22 kadu-theme-icons-nuvola16 kadu-theme-icons-nuvola22 kadu-module-iwait4u"
106                 # obsoleted pear test packages
107                 ignore="$ignore php-*-tests"
108                 # obsoleted
109                 ignore="$ignore nmap-X11"
110                 # mksd dependency not distributale
111                 ignore="$ignore samba-vfs-vscan-mks"
112                 # ibbackup is not distributale
113                 ignore="$ignore innobackup"
114                 # use ac-updates
115                 ignore="$ignore ntp-client ntp"
116                 # php4 only(php-pecl-tidy), for php<5.2(php-pecl-filter)
117                 ignore="$ignore php-pecl-tidy php-pecl-filter"
118
119                 # renamed to vim-syntax-txt2tags
120                 ignore="$ignore txt2tags-vim"
121
122                 for a in $ignore; do
123                         args="$args --ignore=$a"
124                 done
125                 ;;
126         esac
127
128         poldek $sn --up --upa -q "$@"
129         poldek $sn --uniq --noignore --verify=deps $args "$@"
130 }
131
132 # displays latest used tag for a specfile
133 autotag() {
134         local out s
135         for s in "$@"; do
136                 # strip branches
137                 s=${s%:*}
138                 # ensure package ends with .spec
139                 s=${s%.spec}.spec
140                 git fetch --tags
141                 out=$(git for-each-ref --count=1 --sort=-authordate refs/tags/auto/$dist \
142                         --format='%(refname:short)')
143                 echo "$s:$out"
144         done
145 }
146
147 get-buildlog() {
148         local p=$1
149         if [ -z "$p" ]; then
150                 echo >&2 "Usage: get-buildlog PACKAGE"
151                 echo >&2 ""
152                 echo >&2 "Grabs buildlogs from pld builder for all arch."
153                 return
154         fi
155
156         local archlist
157         case "$dist" in
158         ac)
159                 archlist='i686 i586 i386 athlon alpha sparc amd64 ppc'
160                 ;;
161         th)
162                 archlist='x86_64 i486 i686'
163                 ;;
164         *)
165                 echo >&2 "get-buildlog: $dist buildlogs are /dev/null"
166                 return
167         esac
168
169         local url arch path ftp=ftp://buildlogs.pld-linux.org
170         for arch in $archlist; do
171                 [ "$arch" ] || continue
172                 path=${url#$ftp}
173                 echo -n "Checking $p.$arch... "
174                 url=$(lftp -c "debug 0;open $ftp; cls --sort=date -r /$dist/$arch/OK/$p,*.bz2 /$dist/$arch/FAIL/$p,*.bz2 | tail -n1")
175                 url=$ftp$url
176
177                 echo -n "$url... "
178                 if wget -q $url -O .$p~; then
179                         echo "OK"
180                         mv -f .$p~ $p.$arch.bz2
181                 else
182                         echo "SKIP"
183                         rm -f .$p~
184                 fi
185         done
186 }
187
188 fi # no $dist set
189
190 alias adif="dif -x '*.m4' -x ltmain.sh -x install-sh -x depcomp -x 'Makefile.in' -x compile -x 'config.*' -x configure -x missing -x mkinstalldirs -x autom4te.cache"
191 alias pclean="sed -i~ -e '/^\(?\|=\+$\|unchanged:\|diff\|only\|Only\|Files\|Common\|Index:\|RCS file\|retrieving\)/d'"
192
193 # makes diff from PLD CVS urls
194 # requires: cvs, tee
195 urldiff() {
196         local url="$1"
197         if [ -z "$url" ]; then
198                 echo >&2 "Reading STDIN"
199                 read url
200         fi
201
202         echo >&2 "Process $url"
203         local file="$url"
204         file=${file#*SPECS/}
205         file=${file#*SOURCES/}
206         file=${file##*/}
207         local r1=${file#*r1=}
208         local r2=${r1#*r2=}
209         r2=${r2%%[&;]*}
210         r1=${r1%%[&;]*}
211         file=${file%\?*}
212         file=${file%.diff}
213
214         echo >&2 "$file: $r1 -> $r2"
215
216         if [ -t 1 ]; then
217                 cvs diff -u -r$r1 -r$r2 $file | tee m.patch | diffcol
218         else
219                 cvs diff -u -r$r1 -r$r2 $file
220         fi
221 }
222
223 # makes diff from kde svn path
224 # requires: wget, tee
225 kdediff() {
226         local url="$1" r1 r2
227         # --- branches/KDE/3.5/kdepim/kpilot/conduits/vcalconduit/vcalRecord.cc #624744:624745
228         url=${url#*--- }
229         echo >&2 "Process $url"
230         r1=${url#*#}
231         r2=${r1#*:}
232         r1=${r1%:*}
233
234         #  http://websvn.kde.org/branches/KDE/3.5/kdepim/kpilot/conduits/vcalconduit/vcalRecord.cc?rev=624745&r1=612579&r2=624745&makepatch=1&diff_format=u
235         #  http://websvn.kde.org/branches/KDE/3.5/kdenetwork/kopete/protocols/oscar/aim/aimcontact.cpp?r1=609808&r2=673027&view=patch
236         url=http://websvn.kde.org/${url% *}
237         url="$url?r1=$r1&r2=$r2&view=patch"
238
239         if [ -t 1 ]; then
240                 wget "$url" -O -| tee m.patch | diffcol
241         else
242                 wget "$url" -O -
243         fi
244 }
245
246 # merges two patches
247 # requires: patchutils
248 pmerge() {
249         combinediff -p1 $1 $2 > m.patch || return
250         pclean m.patch
251         dif $1 m.patch
252 }
253
254 # downloads sourceforge url from specific mirror
255 sfget() {
256         local url="$1"
257         url="${url%?download}"
258         url="${url%?use_mirror=*}"
259         url="${url#http://downloads.}"
260         url="http://dl.${url#http://prdownloads.}"
261         # use mirror
262         local mirror="http://nchc.dl.sourceforge.net"
263         url="$mirror/sourceforge/${url#http://dl.sourceforge.net/}"
264         wget -c "$url"
265 }
266
267 dif() {
268         if [ -t 1 ]; then
269                 diff -ur -x .svn -x .git -x .bzr -x CVS "$@" | diffcol | less -R
270         else
271                 diff -ur -x .svn -x .git -x .bzr -x CVS "$@"
272         fi
273 }
274
275 diffcol() {
276 sed -e '
277         s,\e,\e[44m^[\e[49m,g;
278         s,\a,\e[44m^G\e[49m,g;
279         s,^\(Index:\|diff\|---\|+++\) .*$,\e[32m&,;
280         s,^@@ ,\e[33m&,;
281         s,^-,\e[35m&,;
282         s,^+,\e[36m&,;
283         s,\r,\e[44m^M\e[49m,g;
284         s,      ,    ,g;
285         s,\([^[:space:]]\)\([[:space:]]\+\)$,\1\e[41m\2\e[49m,g;
286         s,$,\e[0m,
287 ' ${1:+"$@"}
288 }
289
290 # does diff between FILE~ and FILE
291 # the diff can be applied with patch -p1
292 d() {
293         local file="$1"
294         local dir diff
295         if [[ "$file" = /* ]]; then
296                 # full path -- no idea where to strip
297                 dir=.
298                 diff=$file
299         else
300                 # relative path -- keep one path component from current dir
301                 dir=..
302                 diff=${PWD##*/}/${file}
303         fi
304
305         (builtin cd "$dir"; dif $diff{~,})
306 }
307
308 rpmb() {
309         local SPEC SPECDIR arg
310         for arg in "$@"; do
311                 case "$arg" in
312                         *.spec) SPEC="$arg"
313                                 ;;
314                 esac
315         done
316         SPECDIR=$(dirname "$(pwd)/${SPEC:-.}")
317         command rpmbuild --define "_specdir $SPECDIR" --define "_sourcedir $SPECDIR" "$@"
318 }
This page took 0.057974 seconds and 4 git commands to generate.