Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active October 18, 2019 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruario/ed192ca998f1025239a067ad57c97102 to your computer and use it in GitHub Desktop.
Save ruario/ed192ca998f1025239a067ad57c97102 to your computer and use it in GitHub Desktop.
A script for those who "Forgot to make a SlackBuild". Following a manual install (e.g. `make install`), use this script to make a Slackware package.
#!/bin/sh -eu
#
# This script allows you to create a Slackware package from software you
# previously installed manually (e.g. via `make install`).
#
# Usage:
#
# ./script name-version /path/to/reference/file [seconds]
#
# Provide the name and version of the package, path to one file that forms
# part of the package, and optionally seconds either side of that reference
# file's creation time. If the third argument is not provided, 10 is assumed
# because unlike compilation, installation happens within a few seconds. On
# completion a Slackware package will be created.
#
# Example:
#
# ./script zstd-1.3.7 /usr/local/bin/zstd
#
if [ "$USER" != "root" ]; then
echo "Run this script as root" >&2
exit 1
fi
NAMEVER="$1"
CTIME=$(stat -c%Z "$2")
RANGE="${3:-10}"
ARCH="${ARCH:-$(uname -m)}"
case "$ARCH" in
arm*) ARCH=arm ;;
esac
PKG="$(mktemp -td f2sb.XXXXXX)"
mkdir "$PKG/pkg"
cd "$PKG/pkg"
find /etc /opt /usr -newerct @$(($CTIME-$RANGE)) ! -newerct @$(($CTIME+$RANGE)) -print0 | cpio --quiet -p0md .
/sbin/makepkg -l y -c n "${OUTPUT:-/tmp}/$NAMEVER-$ARCH-${BUILD:-1}.${PKGTYPE:-tgz}"
cd - >/dev/null
rm -r "$PKG"
#!/bin/sh -eu
#
# Alternate version that does not use makepkg and hence does not require
# root.
#
# NOTE: *This script could fail to find files in directories it has no
# permission to read!*
#
# This script allows you to create a Slackware package from software you
# previously installed manually (e.g. via `make install`).
#
# Usage:
#
# ./script name-version /path/to/reference/file [seconds]
#
# Provide the name and version of the package, path to one file that forms
# part of the package, and optionally seconds either side of that reference
# file's creation time. If the third argument is not provided, 10 is assumed
# because unlike compilation, installation happens within a few seconds. On
# completion a Slackware package will be created.
#
# Example:
#
# ./script zstd-1.3.7 /usr/local/bin/zstd
#
NAMEVER="$1"
CTIME=$(stat -c%Z "$2")
RANGE="${3:-10}"
ARCH="${ARCH:-$(uname -m)}"
case "$ARCH" in
arm*) ARCH=arm ;;
esac
PKG="$(mktemp -td f2sb.XXXXXX)"
mkdir "$PKG/pkg"
cd "$PKG/pkg"
find /etc /opt /usr -newerct @$(($CTIME-$RANGE)) ! -newerct @$(($CTIME+$RANGE)) -print0 2>/dev/null | cpio --quiet -p0md .
mkpkg() {
if [ "$1" = "-n" ]; then
TAROWNER=""
shift 1
else
TAROWNER="--group 0 --owner 0"
fi
if find * -type l | grep -qm1 .; then
mkdir -p install
find * -type l -printf '( cd %h ; rm -rf %f )\n( cd %h ; ln -sf %l %f )\n' -delete > install/symlinks
if [ -f "install/doinst.sh" ]; then
printf '\n' | cat - install/doinst.sh >> install/symlinks
fi
mv install/symlinks install/doinst.sh
fi
case "$1" in
*tbz)
if command -v lbzip2 >/dev/null 2>&1; then
cmp=lbzip2
else
cmp=bzip2
fi
;;
*tgz)
if command -v pigz >/dev/null 2>&1; then
cmp=pigz
else
cmp=gzip
fi
;;
*tlz) cmp=lzma ;;
*txz) cmp="xz -T0" ;;
*) echo "Unknown compression type" >&2 ; exit 1 ;;
esac
if [ -x /bin/tar-1.13 ]; then
tar-1.13 $TAROWNER -cvvf- . | $cmp > "$1"
else
tar cvvf - . --format gnu --xform 'sx^\./\(.\)x\1x' --show-stored-names $TAROWNER | $cmp > "$1"
fi
echo "Slackware package \"$1\" created."
}
mkpkg "${OUTPUT:-/tmp}/$NAMEVER-$ARCH-${BUILD:-1}.${PKGTYPE:-tgz}"
cd - >/dev/null
rm -r "$PKG"
@ruario
Copy link
Author

ruario commented Dec 23, 2018

Based on ideas that are explained in more detail in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment