]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - shrc.sh
rename to shrc.sh to be more meaningful filename
[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                 if [ -z "$(git tag --points-at $branch 2>/dev/null)" ]; then
28                         echo >&2 "There's no tag pointing to current $branch; refusing to delete branch"
29                         return 1
30                 fi
31                 git push --delete origin $branch
32         fi
33
34         git tag -f $branch
35         git push origin $branch
36 }
37
38 # undo spec utf8
39 # note: it will do it blindly, so any lang other than -pl is most likely broken
40 specutfundo() {
41         local spec="$1"
42         iconv -futf8 -tlatin2 "$spec" > m
43         sed -e 's/\.UTF-8//' m > "$spec"
44         rm -f m
45 }
46
47 dist-requires() {
48         local opts deps
49         while [ $# -gt 0 ]; do
50                 case "$1" in
51                 --sn)
52                         opts="$opts $1 $2"
53                         shift
54                         ;;
55                 -*)
56                         opts="$opts $1"
57                         ;;
58                 *)
59                         deps="$deps $1"
60                         ;;
61                 esac
62                 shift
63         done
64
65         case "$dist" in
66         ac)
67                 opts="$opts --sn=$dist-updates"
68                 ;;
69         esac
70
71         poldek -q -Q --sn $dist $opts --cmd what-requires $deps
72 }
73
74 dist-verify() {
75         local args sn
76         sn="--sn $dist"
77
78         case "$dist" in
79         ac)
80                 sn="$sn --sn $dist-updates"
81
82                 local a ignore
83                 # typo
84                 ignore="$ignore kdenetwork-kopete-tool-conectionstatus"
85                 # obsoleted
86                 ignore="$ignore gimp-plugin-swfdec wine-drv-arts ntp-ntptrace"
87                 # quake2@MAIN is now quake2forge, original quake2 restored to quake2
88                 ignore="$ignore quake2-3dfx quake2-sdl quake2-sgl quake2-snd-alsa quake2-snd-ao quake2-snd-oss quake2-snd-sdl quake2-static"
89                 # obsoleted
90                 ignore="$ignore mozilla-firefox-lang-en apache1-mod_perl-devel libyasm-static"
91                 # renamed (courier-authlib.spec, r1.54)
92                 ignore="$ignore courier-authlib-userdb courier-authlib-pipe"
93                 # obsoleted, squid 2.6
94                 ignore="$ignore squid-winbind_acl squid-winbind_auth"
95                 # obsoleted with 1.0.4
96                 ignore="$ignore python-numpy-FFT python-numpy-MA python-numpy-RNG"
97                 # subpkgs renamed
98                 ignore="$ignore apache1-doc apache1-index"
99                 # obsoleted by kadu-module-mediaplayer-amarok
100                 ignore="$ignore kadu-module-amarok"
101                 # obsoleted by kadu-module-mediaplayer-xmms
102                 ignore="$ignore kadu-module-xmms"
103                 # obsoleted by kadu 0.6.0
104                 ignore="$ignore kadu-theme-icons-crystal16 kadu-theme-icons-crystal22 kadu-theme-icons-nuvola16 kadu-theme-icons-nuvola22 kadu-module-iwait4u"
105                 # obsoleted pear test packages
106                 ignore="$ignore php-*-tests"
107                 # obsoleted
108                 ignore="$ignore nmap-X11"
109                 # mksd dependency not distributale
110                 ignore="$ignore samba-vfs-vscan-mks"
111                 # ibbackup is not distributale
112                 ignore="$ignore innobackup"
113                 # use ac-updates
114                 ignore="$ignore ntp-client ntp"
115                 # php4 only(php-pecl-tidy), for php<5.2(php-pecl-filter)
116                 ignore="$ignore php-pecl-tidy php-pecl-filter"
117
118                 # renamed to vim-syntax-txt2tags
119                 ignore="$ignore txt2tags-vim"
120
121                 for a in $ignore; do
122                         args="$args --ignore=$a"
123                 done
124                 ;;
125         esac
126
127         poldek $sn --up --upa -q "$@"
128         poldek $sn --uniq --noignore --verify=deps $args "$@"
129 }
130
131 # displays latest used tag for a specfile
132 autotag() {
133         local out s
134         for s in "$@"; do
135                 # strip branches
136                 s=${s%:*}
137                 # ensure package ends with .spec
138                 s=${s%.spec}.spec
139                 git fetch --tags
140                 out=$(git for-each-ref --count=1 --sort=-authordate refs/tags/auto/$dist \
141                         --format='%(refname:short)')
142                 echo "$s:$out"
143         done
144 }
145
146 get-buildlog() {
147         local p=$1
148         if [ -z "$p" ]; then
149                 echo >&2 "Usage: get-buildlog PACKAGE"
150                 echo >&2 ""
151                 echo >&2 "Grabs buildlogs from pld builder for all arch."
152                 return
153         fi
154
155         local archlist
156         case "$dist" in
157         ac)
158                 archlist='i686 i586 i386 athlon alpha sparc amd64 ppc'
159                 ;;
160         th)
161                 archlist='x86_64 i486 i686'
162                 ;;
163         *)
164                 echo >&2 "get-buildlog: $dist buildlogs are /dev/null"
165                 return
166         esac
167
168         local url arch path ftp=ftp://buildlogs.pld-linux.org
169         for arch in $archlist; do
170                 [ "$arch" ] || continue
171                 path=${url#$ftp}
172                 echo -n "Checking $p.$arch... "
173                 url=$(lftp -c "debug 0;open $ftp; cls --sort=date -r /$dist/$arch/OK/$p,*.bz2 /$dist/$arch/FAIL/$p,*.bz2 | tail -n1")
174                 url=$ftp$url
175
176                 echo -n "$url... "
177                 if wget -q $url -O .$p~; then
178                         echo "OK"
179                         mv -f .$p~ $p.$arch.bz2
180                 else
181                         echo "SKIP"
182                         rm -f .$p~
183                 fi
184         done
185 }
186
187 fi # no $dist set
188
189 alias cv='cvs status -v'
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 # chdir to file location and do 'cvs log'
291 cvslog() {
292         local f="$1"
293         local d="${f%/*}"
294         [ "$d" = "$f" ] && d=.
295         (builtin cd $d && cvs log ${f##*/})
296 }
297
298 # does diff between FILE~ and FILE
299 # the diff can be applied with patch -p1
300 d() {
301         local file="$1"
302         local dir diff
303         if [[ "$file" = /* ]]; then
304                 # full path -- no idea where to strip
305                 dir=.
306                 diff=$file
307         else
308                 # relative path -- keep one path component from current dir
309                 dir=..
310                 diff=${PWD##*/}/${file}
311         fi
312
313         (builtin cd "$dir"; dif $diff{~,})
314 }
315
316 rpmb() {
317         local SPEC SPECDIR arg
318         for arg in "$@"; do
319                 case "$arg" in
320                         *.spec) SPEC="$arg"
321                                 ;;
322                 esac
323         done
324         SPECDIR=$(dirname "$(pwd)/${SPEC:-.}")
325         command rpmbuild --define "_specdir $SPECDIR" --define "_sourcedir $SPECDIR" "$@"
326 }
This page took 0.05528 seconds and 4 git commands to generate.