# -*- shell-script -*- # Copyright (C) 2007 - 2014 Steve Youngs # What lies here is a collection of handy bash shell functions and # aliases that make life a little easier for pkgusr. less-or-cat() { 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-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-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 } 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 done } updver() { 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 } 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 } 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} } 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 } ## Check if there is a newer build script, maybe update. # NOTE: Updating needs SXEmacs. It'll work in XEmacs and Emacs too, # but you'll need to change build-update() accordingly. build-update() { if [ -x $(type -p sxemacs) ]; then sxemacs -l /etc/pkgusr/bld-update.el else echo *** Sorry, you do not have SXEmacs installed. echo *** Copying the new build script to ~/build-$(date +%Y%m%d) cp -v /etc/pkgusr/skel-package/build \ ${HOME}/build-$(date +%Y%m%d) fi } checkupdates() { local sysb=/etc/pkgusr/skel-package/build local pkgb=${HOME}/build local sysbv=$(${sysb} -V|awk '/build:/ {print $2;}') local pkgbv=$(${pkgb} -V|awk '/build:/ {print $2;}') if [ ${sysb} -nt ${pkgb} ]; then echo '*****************************************' echo '* *' echo '* B u i l d S c r i p t U p d a t e *' echo '* A v a i l a b l e *' echo '* *' echo '*****************************************' echo ' Your version:' ${pkgbv} echo ' Available Version:' ${sysbv} echo echo 'For a SXEmacs based interactive update, run: "build-update"' echo 'To turn this notice off, set $CHECKUPDATES to: "0"' echo echo -n 'Press [RETURN] to continue...' read junk fi } ## 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<