# -*- shell-script -*-
-# Copyright (C) 2007 - 2013 Steve Youngs <steve@sxemacs.org>
+# Copyright (C) 2007 - 2014 Steve Youngs <steve@sxemacs.org>
-# What lies here is a collection of handy bash shell functions that
-# make life a little easier for pkgusr.
+# What lies here is a collection of handy bash shell functions and
+# aliases that make life a little easier for pkgusr.
-## The build logs
-alogs()
+less-or-cat()
{
- ls -l ${HOME}/*.{err,log}
-}
-
-lerr()
-{
- ls -l ${HOME}/*.err
-}
-
-llog()
-{
- ls -l ${HOME}/*.log
+ local arg=$1
+ local al=$(wc -l<${arg})
+ local sl=$(($LINES-2))
+
+ if [ $al -le $sl ]; then
+ cat ${arg}
+ else
+ less ${arg}
+ fi
}
verr()
{
- local arg=$1
-
- if [ -z "$arg" ]; then
- arg=all
- fi
-
- case $arg in
- conf) less ${HOME}/configure.err ;;
- install) less ${HOME}/install.err ;;
- check) less ${HOME}/check.err ;;
- make) less ${HOME}/make.err ;;
- upd) less ${HOME}/upd.err ;;
- ver) less ${HOME}/verupd.err ;;
- all) less ${HOME}/*.err ;;
- esac
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=all
+ fi
+ case $arg in
+ (conf) less-or-cat ${HOME}/configure.err ;;
+ (install) less-or-cat ${HOME}/install.err ;;
+ (check) less-or-cat ${HOME}/check.err ;;
+ (make) less-or-cat ${HOME}/make.err ;;
+ (upd) less-or-cat ${HOME}/upd.err ;;
+ (ver) less-or-cat ${HOME}/verupd.err ;;
+ (all) less ${HOME}/*.err ;;
+ esac
}
vlog()
{
- local arg=$1
-
- if [ -z "$arg" ]; then
- arg=all
- fi
-
- case $arg in
- conf) less ${HOME}/configure.log ;;
- install) less ${HOME}/install.log ;;
- check) less ${HOME}/check.log ;;
- make) less ${HOME}/make.log ;;
- upd) less ${HOME}/upd.log ;;
- ver) less ${HOME}/verupd.log ;;
- all) less ${HOME}/*.log ;;
- esac
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=all
+ fi
+ case $arg in
+ (conf) less-or-cat ${HOME}/configure.log ;;
+ (install) less-or-cat ${HOME}/install.log ;;
+ (check) less-or-cat ${HOME}/check.log ;;
+ (make) less-or-cat ${HOME}/make.log ;;
+ (upd) less-or-cat ${HOME}/upd.log ;;
+ (ver) less-or-cat ${HOME}/verupd.log ;;
+ (all) less ${HOME}/*.log ;;
+ esac
}
verrlog()
{
- local arg=$1
-
- if [ -z "$arg" ]; then
- arg=all
- fi
-
- case $arg in
- conf) less ${HOME}/configure.{err,log} ;;
- install) less ${HOME}/install.{err,log} ;;
- check) less ${HOME}/check.{err,log} ;;
- make) less ${HOME}/make.{err,log} ;;
- upd) less ${HOME}/upd.{err,log} ;;
- ver) less ${HOME}/verupd.{err,log} ;;
- all) less ${HOME}/*.{err,log} ;;
- esac
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=all
+ fi
+ case $arg in
+ (conf) less ${HOME}/configure.{err,log} ;;
+ (install) less ${HOME}/install.{err,log} ;;
+ (check) less ${HOME}/check.{err,log} ;;
+ (make) less ${HOME}/make.{err,log} ;;
+ (upd) less ${HOME}/upd.{err,log} ;;
+ (ver) less ${HOME}/verupd.{err,log} ;;
+ (all) less ${HOME}/*.{err,log} ;;
+ esac
+}
+
+instg()
+{
+ local arg=$1
+ if [ -z "$arg"]; then
+ arg=err
+ fi
+ grep --color '^\*\*\*' ${HOME}/install.${arg}
}
dlog()
{
for log in configure make check install upd verupd; do
- [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
- [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
+ [[ -f ${HOME}/${log}.err ]] && rm -v ${HOME}/${log}.err
+ [[ -f ${HOME}/${log}.log ]] && rm -v ${HOME}/${log}.log
done
}
updver()
{
- local arg=${1}
- sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
- echo -n "Version updated... "
- grep --colour Version:.*$ ${HOME}/.project
+ local arg=${1}
+ sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
+ echo -n "Version updated... "
+ grep --colour Version:.*$ ${HOME}/.project
}
showinst()
{
- local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
- local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
-
- sed -n ${top},${bot}p ${HOME}/.project
+ local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1)
+ local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
+ sed -n ${top},${bot}p ${HOME}/.project
}
showgen()
{
- local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
- local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
-
- sed -n ${top},${bot}p ${HOME}/.project
-}
-
-deps()
-{
- grep --colour 'Deps: ' ${HOME}/.project
-}
-
-listp()
-{
- pinky -l $(whoami)|less
-}
-
-srepo()
-{
- grep --colour Repo_Location:.*$ ${HOME}/.project
-}
-
-rawrepo()
-{
- srepo|awk '{print $2;}'|tr -d '<>'
-}
-
-trepo()
-{
- grep --colour Repo_Type:.*$ ${HOME}/.project
-}
-
-web()
-{
- grep --colour Web_Site:.*$ ${HOME}/.project
-}
-
-rawweb()
-{
- web|awk '{print $2;}'|tr -d '<>'
+ local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1)
+ local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1)
+ sed -n ${top},${bot}p ${HOME}/.project
}
xtar()
{
- local opts
- local type
- local fname=$1
-
- if [ -z "${fname}" ]; then
- echo No filename specified >&2
- return 1
- fi
-
- type=$(file ${fname}|cut -d' ' -f2)
-
- case $type in
- tar) opts=xf ;;
- gzip) opts=zxf ;;
- bzip2) opts=jxf ;;
- xz|XZ) opts=Jxf ;;
- *)
- # try lzma
- if lzmainfo ${fname} &>/dev/null; then
- opts="--lzma -xf"
- else
- printf "Unknown file type: %s\n" $type >&2
- return 2
- fi
- ;;
- esac
-
- tar ${opts} ${fname}
+ local opts
+ local type
+ local fname=$1
+
+ if [ -z "${fname}" ]; then
+ echo No filename specified >&2
+ return 1
+ fi
+
+ type=$(file ${fname}|cut -d' ' -f2)
+
+ case $type in
+ (tar) opts=xf ;;
+ (gzip) opts=zxf ;;
+ (bzip2) opts=jxf ;;
+ (xz|XZ) opts=Jxf ;;
+ (*)
+ # try lzma
+ if lzmainfo ${fname} &>/dev/null; then
+ opts="--lzma -xf"
+ else
+ printf "Unknown file type: %s\n" $type >&2
+ return 2
+ fi
+ ;;
+ esac
+
+ tar ${opts} ${fname}
}
vtar()
{
- local opts
- local type
- local fname=$1
-
- if [ -z "${fname}" ]; then
- echo No filename specified >&2
- return 1
- fi
-
- type=$(file ${fname}|cut -d' ' -f2)
-
- case $type in
- tar) opts=tvvvf ;;
- gzip) opts=ztvvvf ;;
- bzip2) opts=jtvvvf ;;
- xz|XZ) opts=Jtvvvf ;;
- *)
- # lzma. Here because lzmainfo is too stupid
- if lzmainfo ${fname} &>/dev/null; then
- opts="--lzma -tvvvf"
- else
- printf "Unknown file type: %s\n" $type >&2
- return 2
- fi
- ;;
- esac
-
- tar ${opts} ${fname}|less
+ local opts
+ local type
+ local fname=$1
+
+ if [ -z "${fname}" ]; then
+ echo No filename specified >&2
+ return 1
+ fi
+
+ type=$(file ${fname}|cut -d' ' -f2)
+
+ case $type in
+ (tar) opts=tvvvf ;;
+ (gzip) opts=ztvvvf ;;
+ (bzip2) opts=jtvvvf ;;
+ (xz|XZ) opts=Jtvvvf ;;
+ (*)
+ # lzma. Here because lzmainfo is too stupid
+ if lzmainfo ${fname} &>/dev/null; then
+ opts="--lzma -tvvvf"
+ else
+ printf "Unknown file type: %s\n" $type >&2
+ return 2
+ fi
+ ;;
+ esac
+
+ tar ${opts} ${fname}|less
}
-ebld()
+# Used primarily in the build script to update deps.
+find_pkg_deps()
{
- nano -w ${HOME}/build
-}
+ local arg=$1
-epro()
-{
- nano -w ${HOME}/.project
-}
+ [ -z "$arg" ] && arg=$(whoami)
-ebp()
-{
- nano -w ${HOME}/{build,.project}
+ for file in $(forall_direntries_from $arg -type f -executable -readable); do
+ (readelf -d $file ; ldd $file ) |
+ awk '/NEEDED/ { lib=substr($5,2,length($5)-2); LIBS[lib]=$5 } \
+ /.*=>/ {if ( $1 in LIBS ) LIBS[$1]=$3 } END \
+ { for (lib in LIBS) print LIBS[lib] }' |
+ xargs stat --printf "%U:%G\n"
+ done|sort -u|tr -s '\n' ' '
}
+## Aliases
+# Repos/Websites
+alias srepo='grep --colour Repo_Location:.*$ ${HOME}/.project'
+alias rawrepo='srepo|cut -d" " -f2|tr -d "<>"'
+alias trepo='grep --colour Repo_Type:.*$ ${HOME}/.project'
+alias web='grep --colour Web_Site:.*$ ${HOME}/.project'
+alias rawweb='web|tr -s " "|cut -d" " -f3|tr -d "<>"'
+# Logs
+alias alogs='ls -l ${HOME}/*.{err,log}'
+alias lerr='ls -l ${HOME}/*.err'
+alias llog='ls -l ${HOME}/*.log'
+# Util
+alias ebld='nano -w ${HOME}/build'
+alias epro='nano -w ${HOME}/.project'
+alias ebp='nano -w ${HOME}/{build,.project}'
+alias deps='grep --colour "Deps: " ${HOME}/.project'
+alias ipkg=showinst
+alias gpkg=showgen
+alias listp='pinky -l $(whoami)|less'
+alias lc=less-or-cat
+
H-pkg()
{
- cat<<EOF
+ cat<<EOF|less
+
+Logs:
alogs List of build logs (showing size)
lerr List just the error logs
verrlog [LOG] Same as for \`verr', but displays both the .err,
and the .log files.
dlog Removes all build logs
- updver [NEWVER]
- Updates the version in the .project. It MUST be
- quoted to protect it from shell expansion.
- showinst Displays the \`Install Notes'.
- showgen Displays the \`General Notes'.
+ instg {err|log} Greps install.err (default) or install.log for
+ pkgusr notifications ("*** some message")
+
+Package Notes/Content:
+
+ showinst Displays the \`Install Notes'. (alias: ipkg)
+ showgen Displays the \`General Notes'. (alias: gpkg)
listp Displays the entire package info (piped through less(1))
srepo Display the package's source repo location.
rawrepo Output just the repo URL (to use with lynx, curl, etc)
web Display the package's homepage URL.
rawweb Output just the web URL (to use with lynx etc)
deps Display the package's dependencies
+
+Tarball Handling:
+
xtar [TARBALL] Extract TARBALL, automatically choosing the appropriate
tar(1) options.
vtar [TARBALL] List the contents of TARBALL, automatically choosing
appropriate options and piping through less(1).
+
+Build Scripts:
+
ebld Edit the build script.
epro Edit the .project file.
ebp Edit the build script and the .project file.
+ updver [NEWVER] Updates the version in the .project. It MUST be
+ quoted to protect it from shell expansion.
+
EOF
}
+
+# Local variables:
+# sh-basic-offset: 4
+# End: