# -*- shell-script -*-
-# Copyright (C) 2007 - 2013 Steve Youngs <steve@sxemacs.org>
+# Copyright © 2007 - 2021 Steve Youngs All rights reserved.
+# SPDX-License-Identifier: BSD-3-Clause
-# 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()
+B-tips()
{
- ls -l ${HOME}/*.{err,log}
-}
+ less<<ZOF
+
+Always build outside of the source tree if possible. Meson even
+enforces this, CMake to a lesser degree does as well. This is a good
+thing.
+
+Meson:
+=====
+*** KEEP THE BUILD TREE ***
+
+A big difference with Meson compared to other build systems is that you
+should only ever have to run it once per package. You do not have to
+re-run it every time there is a change in the source tree. To that
+end, here is a reasonable template to use in the 'configure_commands()'
+section of the build script...
+
+ # If you change the options after the build tree has already been
+ # set up and configured, run the build as: 'FORCE=1 ../build'
+ if [[ ! -d meson-info || \${FORCE} -eq 1 ]]; then
+ if [[ \${FORCE} -eq 1 ]]; then
+ _cmd=configure TREE=\${PWD}
+ echo '***' No logs on a FORCE run
+ echo See changes with: \'meson introspect --buildoptions -i\'
+ else
+ TREE=\${SRCTREE}
+ fi
+ meson \$_cmd \\
+ -Dprefix=/usr \\
+ -Dlibdir=lib \\
+ -Dlibexecdir=lib \\
+ -Dbuildtype=release \\
+ -Db_lto=true \\
+ -Db_lto_threads=4 \\
+ any other options here \\
+ \${TREE}
+ fi
+
+The Meson equivalent of configure --help
+
+ meson introspect --buildoptions -i
+
+All "path" options (libdir, datadir, etc) are relative to prefix
+unless the value begins with a '/' and then it is an absolute path.
+
+Another nice thing about Meson is that when you set prefix to '/usr',
+sysconfdir is automatically set to '/etc' and localstatedir to '/var'.
+
+One headache that I have with Meson (and also CMake and Ninja) is
+that file timestamps are very often not updated on install. I use
+timestamps to help with upgrades (see: Upgrading below) and cleaning
+out the old stuff that no longer exists in the current version of a
+package. So here is a template for the 'install_commands()' section
+of the build script...
+
+ ninja install &&
+ # Meson builds tend not to update timestamps
+ meson introspect --installed -i |
+ awk '{print \$2}'|tr -d '",'|xargs touch -ch
+
+Meson install FAILS:
+===================
+Meson has this nifty trick of spawning pkexec (polkit) to gain escalated
+privileges if the install stops because of a permission error. There
+are 2 downsides to this in a pkgusr environment.
+
+ 1) The actual error is hidden.
+ 2) If you do authenticate, the entire package will be installed as
+ root.
+
+The easiest way around this is to temporarily rename /usr/bin/pkexec
+out of the way. Then you will get an actual error message that you
+can deal with. (remember to rename pkexec back once the problem is
+fixed)
+
+CMake:
+=====
+*** KEEP THE BUILD TREE ***
+
+Always use Ninja instead of old crusty unix makefiles. Here is a
+reasonable template for 'configure_commands()'...
+
+ cmake \\
+ -DBUILD_SHARED_LIBS=ON \\
+ -DCMAKE_BUILD_TYPE=Release \\
+ -DCMAKE_INSTALL_PREFIX=/usr \\
+ -DCMAKE_INSTALL_LIBDIR=lib \\
+ -DCMAKE_INSTALL_LIBEXECDIR=lib \\
+ -DCMAKE_INSTALL_LOCALSTATEDIR=/var \\
+ -DCMAKE_INSTALL_RUNSTATEDIR=/run \\
+ -DCMAKE_INSTALL_SYSCONFDIR=/etc \\
+ -Wno-dev \\
+ any other options here \\
+ -G Ninja \${SRCTREE}
+
+CMake equivalent of configure --help
+
+ cmake -LAH -G Ninja ../SRCTREE &>,,conf
+
+Like Meson, CMake path options are relative to prefix unless the value
+begins with a '/' and then it is absolute.
+
+A nice thing about CMake is that it creates targets to edit and
+rebuild the cache (think: reconfigure). 'ninja edit_cache' and
+'ninja rebuld_cache', respectively.
+
+Same headache as with Meson... timestamps not being updated on installs.
+Here is the 'install_commands()' template for CMake builds...
+
+ ninja install &&
+ # CMake builds tend not to update timestamps
+ if [ -f install_manifest.txt ]; then
+ echo>>install_manifest.txt # we need a final newline
+ while read file; do
+ touch -ch "\${file}"
+ done<install_manifest.txt
+ fi
+
+Autotools:
+=========
+install_commands() template...
+
+ make install &&
+ # Libtool .la files are NOT needed on a modern Linux system
+ find /usr/lib -name \\*.la -user \$(whoami) -delete
+
+Upgrading:
+=========
+
+ 1) touch ~/timestampfile
+ 2) build and install the package
+ 3) forall_direntries_from \$(whoami) -not -newer ~/timestampfile
+
+If step 3 turns up libraries that are dependencies of other packages
+and the SO major version has changed move them to /usr/lib/deprecated
+until everything that needs them has been updated/rebuilt. Remember to
+run ldconfig.
+
+Root Interventions:
+==================
+BEFORE install root todo-items template:
+(place at top of run_install() func)
+
+ echo '*** ROOT INTERVENTION REQUIRED ***'
+ cat<<EOF
+ As root in another term, run the following:
+----------------------------------------------------------
+
+ Put any commands you need to run as root before this
+ package is installed here. Watch your shell escapes
+ on backslashes, dollar signs, etc.
+
+--------------------[RETURN when completed to continue]---
+EOF
+ read junk
-lerr()
-{
- ls -l ${HOME}/*.err
-}
+AFTER install root todo-items template:
+(place at top of run_update() func)
-llog()
-{
- ls -l ${HOME}/*.log
-}
+ echo '*** ROOT INTERVENTION REQUIRED ***'
+ cat<<EOF
+ As root in another term, run the following:
+----------------------------------------------------------
-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
-}
-
-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
-}
+ Put any commands you need to run as root after this
+ package is installed here. Watch your shell escapes
+ on backslashes, dollar signs, etc.
-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
-}
-
-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
-}
+--------------------[RETURN when completed to continue]---
+EOF
+ read junk
-updver()
-{
- local arg=${1}
- sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
- echo -n "Version updated... "
- grep --colour Version:.*$ ${HOME}/.project
+### End of Build Tips
+ZOF
}
-showinst()
+verr()
{
- 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 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
}
-showgen()
+vlog()
{
- 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
+ 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
}
-deps()
+verrlog()
{
- grep --colour 'Deps: ' ${HOME}/.project
+ 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
}
-listp()
+instg()
{
- pinky -l $(whoami)|less
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=err
+ fi
+ grep --colour=always '^\*\*\*' ${HOME}/install.${arg}|less
}
-srepo()
+chkg()
{
- grep --colour Repo_Location:.*$ ${HOME}/.project
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=err
+ fi
+ grep --colour=always '^\*\*\*' ${HOME}/check.${arg}|less
}
-rawrepo()
+makeg()
{
- srepo|awk '{print $2;}'|tr -d '<>'
+ local arg=$1
+ if [ -z "$arg" ]; then
+ arg=err
+ fi
+ grep --colour=always '^\*\*\*' ${HOME}/make.${arg}|less
}
-trepo()
+dlog()
{
- grep --colour Repo_Type:.*$ ${HOME}/.project
+ 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
}
-web()
+updver()
{
- grep --colour Web_Site:.*$ ${HOME}/.project
+ local arg=${1}
+ sed -i "s|\(Version: \).*$|\1${arg}|" ${HOME}/.project
+ echo -n "Version updated... "
+ grep --colour Version:.*$ ${HOME}/.project
}
-rawweb()
+ipkg()
{
- web|awk '{print $2;}'|tr -d '<>'
+ 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|less
}
-xtar()
+gpkg()
{
- 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 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|less
}
-vtar()
+## 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()
{
- 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
+ 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
}
-ebld()
+checkupdates()
{
- nano -w ${HOME}/build
+ 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 [[ ${sysbv} > ${pkgbv} ]]; 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
}
-epro()
+## Convenience to allow existing pkgusrs to update their git
+# config
+prep_git()
{
- nano -w ${HOME}/.project
+ install -vdm755 ${HOME}/.config/git &&
+ ln -svf /etc/pkgusr/gitconfig ${HOME}/.config/git/config &&
+ # Nuke the old ~/.gitconfig
+ rm -v ${HOME}/.gitconfig 2>/dev/null || true
}
-ebp()
-{
- nano -w ${HOME}/{build,.project}
-}
+## 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
+## As of 2021-01-18 nano (v5.5) seems FUBAR'd
+alias ebld='vi ${HOME}/build'
+alias epro='vi ${HOME}/.project'
+alias ebp='vi -a ${HOME}/{build,.project}'
+# 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 listp='pinky -l $(whoami)|less'
+alias patches='find ${SLACKPKG}/**/$(whoami)|grep -E "(diff|patch)"'
+alias vtar=less
+alias xtar='tar xf'
H-pkg()
{
- cat<<EOF
+ less<<EOF
+
+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")
+ chkg {err|log} Greps check.err (default) or check.log for
+ pkgusr notifications ("*** some message")
+ makeg {err|log} Greps make.err (default) or make.log for
+ pkgusr notifications ("*** some message")
+
+Package Notes/Content:
+
+ ipkg Displays the \`Install Notes'.
+ gpkg Displays the \`General Notes'.
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)
- trepo Display the type of repo (tla, git, svn, mercurial etc)
+ trepo Display the type of repo (git, svn, mercurial, tla 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
- 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).
+
+Tarball Handling:
+
+ xtar [TARBALL] Extract TARBALL
+ vtar [TARBALL] List the contents of TARBALL
+
+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.
+
+Miscellaneous Bobs & Bits:
+
+ prep_git Sets up ~/.config/git/config
+ In the normal course of events you shouldn't need to
+ use this as it happens during login if it is needed.
+ patches Check for any Slackware patches. (see SLACKPKG var in
+ bash_profile)
+ B-tips A few build tips. Includes templates for Meson and
+ CMake to use in the build script.
+
EOF
}
+
+# Local variables:
+# sh-basic-offset: 4
+# End: