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