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