28d90a6d7f972ccb0fc4dc528857d8824cf1b8c2
[pkgusr] / etc / pkgusr / handy_funcs
1 # -*- shell-script -*-
2 # Copyright (C) 2007 Steve Youngs <steve@sxemacs.org>
3
4 # What lies here is a collection of handy bash shell functions that
5 # make life a little easier for pkgusr.
6
7 ## The build logs
8 alogs()
9 {
10         ls -l ${HOME}/*.{err,log}
11 }
12
13 lerr()
14 {
15         ls -l ${HOME}/*.err
16 }
17
18 llog()
19 {
20         ls -l ${HOME}/*.log
21 }
22
23 verr()
24 {
25         local arg=$1
26
27         if [ -z "$arg" ]; then
28                 arg=all
29         fi
30
31         case $arg in
32                    conf) less ${HOME}/configure.err ;;
33                 install) less ${HOME}/install.err ;;
34                   check) less ${HOME}/check.err ;;
35                    make) less ${HOME}/make.err ;;
36                     upd) less ${HOME}/upd.err ;;
37                     ver) less ${HOME}/verupd.err ;;
38                     all) less ${HOME}/*.err ;;
39         esac
40 }
41
42 vlog()
43 {
44         local arg=$1
45
46         if [ -z "$arg" ]; then
47                 arg=all
48         fi
49
50         case $arg in
51                    conf) less ${HOME}/configure.log ;;
52                 install) less ${HOME}/install.log ;;
53                   check) less ${HOME}/check.log ;;
54                    make) less ${HOME}/make.log ;;
55                     upd) less ${HOME}/upd.log ;;
56                     ver) less ${HOME}/verupd.log ;;
57                     all) less ${HOME}/*.log ;;
58         esac
59 }
60
61 verrlog()
62 {
63         local arg=$1
64
65         if [ -z "$arg" ]; then
66                 arg=all
67         fi
68
69         case $arg in
70                    conf) less ${HOME}/configure.{err,log} ;;
71                 install) less ${HOME}/install.{err,log} ;;
72                   check) less ${HOME}/check.{err,log} ;;
73                    make) less ${HOME}/make.{err,log} ;;
74                     upd) less ${HOME}/upd.{err,log} ;;
75                     ver) less ${HOME}/verupd.{err,log} ;;
76                     all) less ${HOME}/*.{err,log} ;;
77         esac
78 }
79
80 dlog()
81 {
82     for log in configure make check install upd verupd; do
83             [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
84             [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
85     done
86 }
87
88 updver()
89 {
90         local arg=${1}
91         sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
92         echo -n "Version updated... "
93         grep --colour Version:.*$ ${HOME}/.project
94 }
95
96 showinst()
97 {
98         local top=$(pinky -l $(whoami)|grep -n "^Install Notes:$"|cut -d: -f1)
99         local bot=$(pinky -l $(whoami)|grep -n "^General Notes:$"|cut -d: -f1)
100
101         pinky -l $(whoami)|sed -n ${top},${bot}p
102 }
103
104 showgen()
105 {
106         local top=$(pinky -l $(whoami)|grep -n "^General Notes:$"|cut -d: -f1)
107         local bot=$(pinky -l $(whoami)|grep -n "^CONTENTS:$"|cut -d: -f1)
108
109         pinky -l $(whoami)|sed -n ${top},${bot}p
110 }
111
112 listp()
113 {
114         pinky -l $(whoami)|less
115 }
116
117 srepo()
118 {
119         pinky -l $(whoami)|grep --colour Repo_Location:.*$
120 }
121
122 rawrepo()
123 {
124     srepo|awk '{print $2;}'|tr -d '<>'
125 }
126
127 trepo()
128 {
129         pinky -l $(whoami)|grep --colour Repo_Type:.*$
130 }
131
132 web()
133 {
134         pinky -l $(whoami)|grep --colour Web_Site:.*$
135 }
136
137 rawweb()
138 {
139     web|awk '{print $2;}'|tr -d '<>'
140 }
141
142 xtar()
143 {
144         local opts
145         local type
146         local fname=$1
147
148         if [ -z "${fname}" ]; then
149                 echo No filename specified >&2
150                 return 1
151         fi
152
153         type=$(file ${fname}|cut -d' ' -f2)
154
155         case $type in
156                 tar)    opts=xf ;;
157                 gzip)   opts=zxf ;;
158                 bzip2)  opts=jxf ;;
159                 xz)     opts=Jxf ;;
160                 *)
161                         # try lzma
162                         if lzmainfo ${fname} &>/dev/null; then
163                                 opts="--lzma -xf"
164                         else
165                                 printf "Unknown file type: %s\n" $type >&2
166                                 return 2
167                         fi
168                         ;;
169         esac
170
171         tar ${opts} ${fname}
172 }
173
174 vtar()
175 {
176         local opts
177         local type
178         local fname=$1
179
180         if [ -z "${fname}" ]; then
181                 echo No filename specified >&2
182                 return 1
183         fi
184
185         type=$(file ${fname}|cut -d' ' -f2)
186
187         case $type in
188                 tar)    opts=tvvvf ;;
189                 gzip)   opts=ztvvvf ;;
190                 bzip2)  opts=jtvvvf ;;
191                 xz)     opts=Jtvvvf ;;
192                 *)
193                         # lzma.  Here because lzmainfo is too stupid
194                         if lzmainfo ${fname} &>/dev/null; then
195                                 opts="--lzma -tvvvf"
196                         else
197                                 printf "Unknown file type: %s\n" $type >&2
198                                 return 2
199                         fi
200                         ;;
201         esac
202
203         tar ${opts} ${fname}|less
204 }
205
206 ebld()
207 {
208         nano -w ${HOME}/build
209 }
210
211 epro()
212 {
213         nano -w ${HOME}/.project
214 }
215
216 ebp()
217 {
218         nano -w ${HOME}/{build,.project}
219 }
220
221 H-pkg()
222 {
223         cat<<EOF
224
225         alogs           List of build logs (showing size)
226         lerr            List just the error logs
227         llog            List just the .log logs
228         verr [LOG]      Display LOG, which can be:
229                                \`conf' -- configure.err
230                               \`check' -- check.err
231                             \`install' -- install.err
232                                \`make' -- make.err
233                                 \`upd' -- upd.err
234                                 \`ver' -- verupd.err
235                                 \`all' -- all error logs (default)
236         vlog [LOG]      Same as for \`verr', but for the .log files.
237         verrlog [LOG]   Same as for \`verr', but displays both the .err,
238                         and the .log files.
239         dlog            Removes all build logs
240         updver [NEWVER]
241                         Updates the version in the .project.  It MUST be
242                         quoted to protect it from shell expansion.
243         showinst        Displays the \`Install Notes'.
244         showgen         Displays the \`General Notes'.
245         listp           Displays the entire package info (piped through less(1))
246         srepo           Display the package's source repo location.
247         rawrepo         Output just the repo URL (to use with lynx, curl, etc)
248         trepo           Display the type of repo (tla, git, svn, mercurial etc)
249         web             Display the package's homepage URL.
250         rawweb          Output just the web URL (to use with lynx etc)
251         xtar [TARBALL]  Extract TARBALL, automatically choosing the appropriate
252                         tar(1) options.
253         vtar [TARBALL]  List the contents of TARBALL, automatically choosing 
254                         appropriate options and piping through less(1).
255         ebld            Edit the build script.
256         epro            Edit the .project file.
257         ebp             Edit the build script and the .project file.
258
259 EOF
260 }