952c4b3293bbfb1cd7a82f8ec7032154d2da46fe
[pkgusr] / etc / pkgusr / handy_funcs
1 # -*- shell-script -*-
2 # Copyright (C) 2007 - 2013 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=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
99         local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
100
101         sed -n ${top},${bot}p ${HOME}/.project
102 }
103
104 showgen()
105 {
106         local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
107         local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
108
109         sed -n ${top},${bot}p ${HOME}/.project
110 }
111
112 deps()
113 {
114         grep --colour 'Deps: ' ${HOME}/.project
115 }
116
117 listp()
118 {
119         pinky -l $(whoami)|less
120 }
121
122 srepo()
123 {
124         grep --colour Repo_Location:.*$ ${HOME}/.project
125 }
126
127 rawrepo()
128 {
129         srepo|awk '{print $2;}'|tr -d '<>'
130 }
131
132 trepo()
133 {
134         grep --colour Repo_Type:.*$ ${HOME}/.project
135 }
136
137 web()
138 {
139         grep --colour Web_Site:.*$ ${HOME}/.project
140 }
141
142 rawweb()
143 {
144     web|awk '{print $2;}'|tr -d '<>'
145 }
146
147 xtar()
148 {
149         local opts
150         local type
151         local fname=$1
152
153         if [ -z "${fname}" ]; then
154                 echo No filename specified >&2
155                 return 1
156         fi
157
158         type=$(file ${fname}|cut -d' ' -f2)
159
160         case $type in
161                 tar)    opts=xf ;;
162                 gzip)   opts=zxf ;;
163                 bzip2)  opts=jxf ;;
164                 xz|XZ)     opts=Jxf ;;
165                 *)
166                         # try lzma
167                         if lzmainfo ${fname} &>/dev/null; then
168                                 opts="--lzma -xf"
169                         else
170                                 printf "Unknown file type: %s\n" $type >&2
171                                 return 2
172                         fi
173                         ;;
174         esac
175
176         tar ${opts} ${fname}
177 }
178
179 vtar()
180 {
181         local opts
182         local type
183         local fname=$1
184
185         if [ -z "${fname}" ]; then
186                 echo No filename specified >&2
187                 return 1
188         fi
189
190         type=$(file ${fname}|cut -d' ' -f2)
191
192         case $type in
193                 tar)    opts=tvvvf ;;
194                 gzip)   opts=ztvvvf ;;
195                 bzip2)  opts=jtvvvf ;;
196                 xz|XZ)     opts=Jtvvvf ;;
197                 *)
198                         # lzma.  Here because lzmainfo is too stupid
199                         if lzmainfo ${fname} &>/dev/null; then
200                                 opts="--lzma -tvvvf"
201                         else
202                                 printf "Unknown file type: %s\n" $type >&2
203                                 return 2
204                         fi
205                         ;;
206         esac
207
208         tar ${opts} ${fname}|less
209 }
210
211 ebld()
212 {
213         nano -w ${HOME}/build
214 }
215
216 epro()
217 {
218         nano -w ${HOME}/.project
219 }
220
221 ebp()
222 {
223         nano -w ${HOME}/{build,.project}
224 }
225
226 H-pkg()
227 {
228         cat<<EOF
229
230         alogs           List of build logs (showing size)
231         lerr            List just the error logs
232         llog            List just the .log logs
233         verr [LOG]      Display LOG, which can be:
234                                \`conf' -- configure.err
235                               \`check' -- check.err
236                             \`install' -- install.err
237                                \`make' -- make.err
238                                 \`upd' -- upd.err
239                                 \`ver' -- verupd.err
240                                 \`all' -- all error logs (default)
241         vlog [LOG]      Same as for \`verr', but for the .log files.
242         verrlog [LOG]   Same as for \`verr', but displays both the .err,
243                         and the .log files.
244         dlog            Removes all build logs
245         updver [NEWVER]
246                         Updates the version in the .project.  It MUST be
247                         quoted to protect it from shell expansion.
248         showinst        Displays the \`Install Notes'.
249         showgen         Displays the \`General Notes'.
250         listp           Displays the entire package info (piped through less(1))
251         srepo           Display the package's source repo location.
252         rawrepo         Output just the repo URL (to use with lynx, curl, etc)
253         trepo           Display the type of repo (tla, git, svn, mercurial etc)
254         web             Display the package's homepage URL.
255         rawweb          Output just the web URL (to use with lynx etc)
256         deps            Display the package's dependencies
257         xtar [TARBALL]  Extract TARBALL, automatically choosing the appropriate
258                         tar(1) options.
259         vtar [TARBALL]  List the contents of TARBALL, automatically choosing 
260                         appropriate options and piping through less(1).
261         ebld            Edit the build script.
262         epro            Edit the .project file.
263         ebp             Edit the build script and the .project file.
264
265 EOF
266 }