#!/bin/sh set -eu if [ "$(id -u)" != 0 ]; then echo "This script needs root permissions!" 1>&2 exit 1 fi if [ "$#" -lt 2 ]; then echo "Usage: $0 [-a arch] [-v version] [-m mirror] [-b localmirror]" 1>&2 exit 1 fi version='14.2' arch="$(uname -m)" mirror='https://mirrors.slackware.com/slackware' base='' # Minimal amount of packages required to run installpkg, removepkg and upgradepkg # bzip2 and gzip are optional, but required to support .tgz and .tbz packages # All of these exist in the 'a' package set packages_pkgtools=' aaa_base aaa_elflibs bash bzip2 coreutils etc findutils glibc-solibs grep gzip pkgtools sed tar util-linux xz ' # Minimal amount of packages required to run slackpkg without the dialog interface # gnupg is optional, but required to verify the GPG signatures of packages # ca-certificates, openssl, bin and perl are optional, but required for HTTPS support # These exist over the 'a', 'ap' and 'n' package sets # perl exists in the 'd' package set # openssl and ca-certificates need to be installed last (after perl and bin, at least) for the doinst.sh to run correctly packages_slackpkg=' bin diffutils gawk gnupg openssl-solibs perl slackpkg wget which openssl ca-certificates ' # Parse arguments while getopts "v:a:m:b:" opt; do case "$opt" in v) version="$OPTARG" ;; a) arch="$OPTARG" ;; m) mirror="$OPTARG" ;; b) base="$(realpath "$OPTARG")" # Path to local mirror, to get the files from. esac done # Build final variables case "$arch" in x86_64) pkgmain='slackware64' ;; *) pkgmain='slackware' ;; esac release="$pkgmain-$version" initrd='isolinux/initrd.img' checksums='CHECKSUMS.md5' # Create working directory temp="$(mktemp -d -t "$(basename "$0")".XXXXXX)" trap "rm -rf '$temp'" EXIT destdir="$PWD" cd "$temp" # Function to download (or copy) a file get() { if [ "$base" ]; then cp "$base/$1" "$2" else wget "$mirror/$release/$1" -O "$2" fi } # Function to verify files based on the checksums file check() { printf '%s' "$(tail +13 CHECKSUMS.md5 | grep "^[0-9a-f]* ./$1$" | cut -d ' ' -f 1) $2" | md5sum -c --quiet - } # Get the full path to a package package() { tail +13 CHECKSUMS.md5 | grep "^[0-9a-f]* ./$pkgmain/[^/]*/$1-[^-]*-[^-]*-[^-]*\.t.z$" | cut -d ' ' -f 3- | cut -c 3- } # Download checksums get "$checksums" CHECKSUMS.md5 # Download installer initrd.img get "$initrd" initrd.img check "$initrd" initrd.img # Unpack and prepare the installer zcat initrd.img | cpio -id rm -rf initrd.img mnt pkg mkdir -p mnt/pkg pkg # Download packages for pkg in $packages_pkgtools; do path="$(package "$pkg")" name="$(basename "$path")" get "$path" "pkg/$name" check "$path" "pkg/$name" echo "$name" >> pkg/_ done for pkg in $packages_slackpkg; do path="$(package "$pkg")" name="$(basename "$path")" get "$path" "mnt/pkg/$name" check "$path" "mnt/pkg/$name" echo "$name" >> mnt/pkg/_ done # Bootstrap pkgtools and it's dependencies env -i chroot . sh -l -c 'while read pkg; do /usr/lib/setup/installpkg --root /mnt --terse "/pkg/$pkg"; done < /pkg/_' # Install slackpkg and it's dependencies env -i chroot mnt sh -l -c 'while read pkg; do /sbin/installpkg --terse "/pkg/$pkg"; done < /pkg/_' # Configuration printf '%s\n' "$mirror/$release/" >> mnt/etc/slackpkg/mirrors # Compress the package tar cvJf "$destdir/$release.tar.xz" --sort=name --exclude=./pkg -C mnt .