Try to eliminate false-positives from patches alias.
[pkgusr] / etc / pkgusr / handy_funcs
1 # -*- shell-script -*-
2 # Copyright (C) 2007 - 2021 Steve Youngs <steve@sxemacs.org>
3
4 # What lies here is a collection of handy bash shell functions and
5 # aliases that make life a little easier for pkgusr.
6
7 verr()
8 {
9     local arg=$1
10     if [ -z "$arg" ]; then
11         arg=all
12     fi
13     case $arg in
14         (conf)    less ${HOME}/configure.err ;;
15         (install) less ${HOME}/install.err ;;
16         (check)   less ${HOME}/check.err ;;
17         (make)    less ${HOME}/make.err ;;
18         (upd)     less ${HOME}/upd.err ;;
19         (ver)     less ${HOME}/verupd.err ;;
20         (all)     less ${HOME}/*.err ;;
21     esac
22 }
23
24 vlog()
25 {
26     local arg=$1
27     if [ -z "$arg" ]; then
28         arg=all
29     fi
30     case $arg in
31         (conf)    less ${HOME}/configure.log ;;
32         (install) less ${HOME}/install.log ;;
33         (check)   less ${HOME}/check.log ;;
34         (make)    less ${HOME}/make.log ;;
35         (upd)     less ${HOME}/upd.log ;;
36         (ver)     less ${HOME}/verupd.log ;;
37         (all)     less ${HOME}/*.log ;;
38     esac
39 }
40
41 verrlog()
42 {
43     local arg=$1
44     if [ -z "$arg" ]; then
45         arg=all
46     fi
47     case $arg in
48         (conf)    less ${HOME}/configure.{err,log} ;;
49         (install) less ${HOME}/install.{err,log} ;;
50         (check)   less ${HOME}/check.{err,log} ;;
51         (make)    less ${HOME}/make.{err,log} ;;
52         (upd)     less ${HOME}/upd.{err,log} ;;
53         (ver)     less ${HOME}/verupd.{err,log} ;;
54         (all)     less ${HOME}/*.{err,log} ;;
55     esac
56 }
57
58 instg()
59 {
60     local arg=$1
61     if [ -z "$arg" ]; then
62         arg=err
63     fi
64     grep --colour=always '^\*\*\*' ${HOME}/install.${arg}|less
65 }
66
67 chkg()
68 {
69     local arg=$1
70     if [ -z "$arg" ]; then
71         arg=err
72     fi
73     grep --colour=always '^\*\*\*' ${HOME}/check.${arg}|less
74 }
75
76 makeg()
77 {
78     local arg=$1
79     if [ -z "$arg" ]; then
80         arg=err
81     fi
82     grep --colour=always '^\*\*\*' ${HOME}/make.${arg}|less
83 }
84
85 dlog()
86 {
87     for log in configure make check install upd verupd; do
88         [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
89         [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
90     done
91 }
92
93 updver()
94 {
95     local arg=${1}
96     sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
97     echo -n "Version updated... "
98     grep --colour Version:.*$ ${HOME}/.project
99 }
100
101 ipkg()
102 {
103     local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
104     local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
105     sed -n ${top},${bot}p ${HOME}/.project|less
106 }
107
108 gpkg()
109 {
110     local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
111     local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
112     sed -n ${top},${bot}p ${HOME}/.project|less
113 }
114
115 xtar()
116 {
117     local opts
118     local type
119     local fname=$1
120
121     if [ -z "${fname}" ]; then
122         echo No filename specified >&2
123         return 1
124     fi
125
126     type=$(file ${fname}|cut -d' ' -f2)
127
128     case $type in
129         (tar)    opts=xf ;;
130         (gzip)   opts=zxf ;;
131         (bzip2)  opts=jxf ;;
132         (xz|XZ)  opts=Jxf ;;
133         (*)
134         # try lzma
135         if lzmainfo ${fname} &>/dev/null; then
136             opts="--lzma -xf"
137         else
138             printf "Unknown file type: %s\n" $type >&2
139             return 2
140         fi
141         ;;
142     esac
143
144     tar ${opts} ${fname}
145 }
146
147 vtar()
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=tvvvf ;;
162         (gzip)   opts=ztvvvf ;;
163         (bzip2)  opts=jtvvvf ;;
164         (xz|XZ)  opts=Jtvvvf ;;
165         (*)
166         # lzma.  Here because lzmainfo is too stupid
167         if lzmainfo ${fname} &>/dev/null; then
168             opts="--lzma -tvvvf"
169         else
170             printf "Unknown file type: %s\n" $type >&2
171             return 2
172         fi
173         ;;
174     esac
175
176     tar ${opts} ${fname}|less
177 }
178
179 ## Check if there is a newer build script, maybe update.
180 #  NOTE: Updating needs SXEmacs.  It'll work in XEmacs and Emacs too,
181 #  but you'll need to change build-update() accordingly.
182 build-update()
183 {
184     if [ -x $(type -p sxemacs) ]; then
185         sxemacs -l /etc/pkgusr/bld-update.el
186     else
187         echo *** Sorry, you do not have SXEmacs installed.
188         echo *** Copying the new build script to ~/build-$(date +%Y%m%d)
189         cp -v /etc/pkgusr/skel-package/build \
190             ${HOME}/build-$(date +%Y%m%d)
191     fi
192 }
193
194 checkupdates()
195 {
196     local sysb=/etc/pkgusr/skel-package/build
197     local pkgb=${HOME}/build
198     local sysbv=$(${sysb} -V|awk '/build:/ {print $2;}')
199     local pkgbv=$(${pkgb} -V|awk '/build:/ {print $2;}')
200     
201     if [ ${sysb} -nt ${pkgb} ]; then
202         echo '*****************************************'
203         echo '*                                       *'
204         echo '*  B u i l d  S c r i p t  U p d a t e  *'
205         echo '*          A v a i l a b l e            *'
206         echo '*                                       *'
207         echo '*****************************************'
208         echo '       Your version:' ${pkgbv}
209         echo '  Available Version:' ${sysbv}
210         echo
211         echo 'For a SXEmacs based interactive update, run: "build-update"'
212         echo 'To turn this notice off, set $CHECKUPDATES to: "0"'
213         echo
214         echo -n 'Press [RETURN] to continue...'
215         read junk
216     fi
217 }
218
219 ## Convenience to allow existing pkgusrs to update their git
220 #  config
221 prep_git()
222 {
223     install -vdm755 ${HOME}/.config/git &&
224     ln -svf /etc/pkgusr/gitconfig ${HOME}/.config/git/config &&
225     # Nuke the old ~/.gitconfig
226     rm -v ${HOME}/.gitconfig 2>/dev/null || true
227 }
228
229 ## Aliases
230 # Repos/Websites
231 alias srepo='grep --colour Repo_Location:.*$ ${HOME}/.project'
232 alias rawrepo='srepo|cut -d" " -f2|tr -d "<>"'
233 alias trepo='grep --colour Repo_Type:.*$ ${HOME}/.project'
234 alias web='grep --colour Web_Site:.*$ ${HOME}/.project'
235 alias rawweb='web|tr -s " "|cut -d" " -f3|tr -d "<>"'
236 # Logs
237 alias alogs='ls -l ${HOME}/*.{err,log}'
238 alias lerr='ls -l ${HOME}/*.err'
239 alias llog='ls -l ${HOME}/*.log'
240 # Util
241 ## As of 2021-01-18 nano (v5.5) seems FUBAR'd
242 alias ebld='vi ${HOME}/build'
243 alias epro='vi ${HOME}/.project'
244 alias ebp='vi -a ${HOME}/{build,.project}'
245 # alias ebld='nano -w ${HOME}/build'
246 # alias epro='nano -w ${HOME}/.project'
247 # alias ebp='nano -w ${HOME}/{build,.project}'
248 alias deps='grep --colour "Deps: " ${HOME}/.project'
249 alias listp='pinky -l $(whoami)|less'
250 alias patches='find ${SLACKPKG}/**/$(whoami)|grep -E "(diff|patch)"'
251
252 H-pkg()
253 {
254         cat<<EOF|less
255
256 Logs:
257
258         alogs           List of build logs (showing size)
259         lerr            List just the error logs
260         llog            List just the .log logs
261         verr [LOG]      Display LOG, which can be:
262                                \`conf' -- configure.err
263                               \`check' -- check.err
264                             \`install' -- install.err
265                                \`make' -- make.err
266                                 \`upd' -- upd.err
267                                 \`ver' -- verupd.err
268                                 \`all' -- all error logs (default)
269         vlog [LOG]      Same as for \`verr', but for the .log files.
270         verrlog [LOG]   Same as for \`verr', but displays both the .err,
271                         and the .log files.
272         dlog            Removes all build logs
273         instg {err|log} Greps install.err (default) or install.log for
274                         pkgusr notifications ("*** some message")
275         chkg {err|log}  Greps check.err (default) or check.log for
276                         pkgusr notifications ("*** some message")
277         makeg {err|log} Greps make.err (default) or make.log for
278                         pkgusr notifications ("*** some message")
279
280 Package Notes/Content:
281
282         ipkg            Displays the \`Install Notes'. (alias: ipkg)
283         gpkg            Displays the \`General Notes'. (alias: gpkg)
284         listp           Displays the entire package info (piped through less(1))
285         srepo           Display the package's source repo location.
286         rawrepo         Output just the repo URL (to use with lynx, curl, etc)
287         trepo           Display the type of repo (tla, git, svn, mercurial etc)
288         web             Display the package's homepage URL.
289         rawweb          Output just the web URL (to use with lynx etc)
290         deps            Display the package's dependencies
291
292 Tarball Handling:
293
294         xtar [TARBALL]  Extract TARBALL, automatically choosing the appropriate
295                         tar(1) options.
296         vtar [TARBALL]  List the contents of TARBALL, automatically choosing 
297                         appropriate options and piping through less(1).
298
299 Build Scripts:
300
301         ebld            Edit the build script.
302         epro            Edit the .project file.
303         ebp             Edit the build script and the .project file.
304         updver [NEWVER] Updates the version in the .project.  It MUST be
305                         quoted to protect it from shell expansion.
306
307 Miscellaneous Bobs & Bits:
308
309         prep_git        Sets up ~/.config/git/config
310                         In the normal course of events you shouldn't need to
311                         use this as it happens during login if it is needed.
312         patches         Check for any Slackware patches. (see SLACKPKG var in
313                         bash_profile)
314
315
316 EOF
317 }
318
319 # Local variables:
320 # sh-basic-offset: 4
321 # End: