Skip to content

Instantly share code, notes, and snippets.

@ruario ruario/README.md
Last active Jun 16, 2019

Embed
What would you like to do?
Alternative (fake) makepkg to create Slackware packages

These scripts are for people who want an alternative to the official Slackware provided makepkg.

Why would you want that?

  • To be able to create Slackware packages with root-owned files, even when run as a regular user.
  • To be able create Slackware packages on non-Slackware based systems without the need to port Pkgtools and its dependencies (e.g. tar-1.13). Some examples being:
    • Projects (or proprietary software vendors) that want to be able to provide binary Slackware packages, where their build/packaging system is on another distro.
    • People who want to pair a package creation script with spkg to use as a secondary package manger on a non-Slackware based distro. This gives the advantage of simple packaging scripts (.SlackBuilds) for additional, self-compiled software.

Two versions are provided:

  • fmakepkg: This is longer and more heavily commented and provides some level of options compatibility with the official makepkg, so that it can be used as a drop in replacement.
  • mkpkg: A shorter script with no options compatibility with the official makepkg.

Both scripts do everything within a single function. This was done so that either function could be easily copied and pasted into other scripts (e.g. my latest-vivaldi, latest-opera, latest-chrome, latest-firefox and latest-skype scripts).

License

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                  Version 2, December 2004

Copyright (C) 2018 Ruarí Ødegaard, Olso, Norway

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long as
the name is changed.

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
#!/bin/sh
# fmakepkg ("Fake makepkg") Version 0.8
#
# This script can be used in place of Slackware's makepkg. It is able to
# make packages with root owned files even when run as a regular user.
#
# Notes:
# 1. No interactive mode
# 2. Link conversion and pre-pending are always on
# 3. Resetting of permissions and ownership is on by default ("-c y")
# 4. Ownership resetting (root:root) is also applied to files
# Help options.
helptext() {
cat << EOF
Usage: $0 package.tgz
options: -h, --help (show this text)
-l, --linkadd y|n (ignored, symlinks are always moved into
doinst.sh)
-p, --prepend (ignored, symlinks are always prepended to
doinst.sh)
-c, --chown y|n (resets all directory permissions to 755 and
changes file ownership to root:root. The
default is y)
EOF
}
# Explain usage if the user does not specify a package name or requests help.
if [ -z "$1" ]; then
echo "You must specify the name of the package to create!" >&2
helptext
exit 1
elif [ "$1" = "--help" -o "$1" = "-h" ]; then
helptext
exit 0
fi
# I have put all the code into a function so that others can easily copy
# and paste it into another script.
fmakepkg() {
# Handle Slackware's makepkg options
while [ 0 ]; do
if [ "$1" = "-p" -o "$1" = "--prepend" ]; then
# option ignored, links are always prepended
shift 1
elif [ "$1" = "--linkadd" -o "$1" = "-l" ]; then
if [ "$2" = "n" ]; then
echo "\"$1 $2\" ignored, links are always converted" >&2
fi
shift 2
elif [ "$1" = "--chown" -o "$1" = "-c" ]; then
# This option now also changes ownership of all files to root:root
SETPERMS="$2"
shift 2
else
break
fi
done
# Change any symlinks into shell script code
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
# Reset permissions and ownership
if [ "${SETPERMS:-y}" = "y" ]; then
find . -type d -exec chmod 755 {} \;
# Changing file ownership is an unofficial extension to makepkg
TAROWNER="--group 0 --owner 0"
else
TAROWNER=""
fi
# Create package using tar 1.13 directory formatting
case "$1" in
*tbr) cmp="brotli --quality ${BROTLI_QUALITY:-5}" ;; # Experimental support for Brotli compression
*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" ;;
*tz4) cmp=lz4 ;; # Experimental support for lz4 compression
*tzo) cmp=lzop ;; # Experimental support for lzop compression
*) 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."
}
fmakepkg "$@"
#!/bin/sh
# A short alternative to makepkg (Version 0.6)
#
# Usage: Switch into the staging directory containing all the files to
# be packaged and issue:
#
# mkpkg /tmp/package-name-version-arch-buildtag.tgz
#
# Note: All files and folders become root owned by default. To prevent
# this add "-n" as an option, after "mkpkg".
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
*tbr) cmp="brotli --quality ${BROTLI_QUALITY:-5}" ;; # Experimental support for Brotli compression
*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" ;;
*tz4) cmp=lz4 ;; # Experimental support for lz4 compression
*tzo) cmp=lzop ;; # Experimental support for lzop compression
*) 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 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.