set -euo pipefail CWD=$(cd "$(dirname "$0")" && pwd) cd "$CWD" || exit PRGNAM=slacker PKGNAM=${PRGNAM,,} SRCVERSION=0.12.2 VERSION="${SRCVERSION//-/_}" BUILD=${BUILD:-1} TAG=${TAG:-cf} TMP=${TMP:-/tmp/pkg} PKG=$TMP/package-$PKGNAM OUTPUT=${OUTPUT:-/tmp} if [ "${ARCH:=""}" = "" ]; then case "$( uname -m )" in i?86) ARCH=i686 ;; arm*) ARCH=arm ;; *) ARCH=$( uname -m ) ;; esac fi # If the variable PRINT_PACKAGE_NAME is set, then this script will report what # the name of the created package would be, and then exit. This information # could be useful to other scripts. if [ ! -z "${PRINT_PACKAGE_NAME:-""}" ]; then echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz " exit 0 fi if [ "$ARCH" = "i686" ]; then SLKCFLAGS="-O2 -march=pentium4 -mtune=generic" LIBDIRSUFFIX="" elif [ "$ARCH" = "x86_64" ]; then SLKCFLAGS="-O2 -march=x86-64 -mtune=generic -fPIC -pipe" LIBDIRSUFFIX="64" elif [ "$ARCH" = "aarch64" ]; then SLKCFLAGS="-O2 -fPIC" LIBDIRSUFFIX="64" else SLKCFLAGS="-O2" LIBDIRSUFFIX="" fi rm -rf -- "$PKG" mkdir -p -- "$TMP" "$PKG" "$OUTPUT" cd -- "$TMP" rm -rf -- "$PRGNAM-$SRCVERSION-source" tar xvf "$CWD/$PRGNAM-$SRCVERSION.tar.gz" cd -- "$PRGNAM-$SRCVERSION-source" chown -R root:root . find . \ \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 -o -perm 511 \) \ -exec chmod 755 {} \; -o \ \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ -exec chmod 644 {} \; # Apply patches if compgen -G "$CWD/patches/*.patch" > /dev/null; then if [ -f "$CWD/patches/series" ]; then while IFS= read -r PATCH; do [ "$PATCH" = "" ] && continue [ "${PATCH#\#}" != "$PATCH" ] && continue patch -p1 -i "$CWD/patches/$PATCH" done < "$CWD/patches/series" else for PATCH in "$CWD/patches"/*.patch; do patch -p1 -i "$PATCH" done fi fi mkdir -p ".cargo" export CARGO_HOME=".cargo" export CFLAGS="$SLKCFLAGS" export CXXFLAGS="$SLKCFLAGS" TARGET="$(rustc --print host-tuple)" pushd "slacker-cli" cargo fetch \ --locked \ --target "$TARGET" cargo build \ --release \ --frozen \ --offline \ --target "$TARGET" cargo install \ --frozen \ --offline \ --no-track \ --root "$PKG/usr" \ --path="." \ --target "$TARGET" # completion must list exactly the binary's subcommands sh contrib/check-completion-drift.sh "target/$TARGET/release/slacker" # generated completions must match their JSON source python3 contrib/gen-completions.py --check # every mutating command must stay unattended under --yes (container safety) bash contrib/check-yes-noninteractive.sh "target/$TARGET/release/slacker" # Cleanup CARGO_HOME and possible unnecessary artifacts in $PKG. rm -rf "$CARGO_HOME" rm -rf "$PKG/usr/.cargo" rm -f "$PKG"/usr/.crates* # templates/ is not shipped: slacker creates it itself on first # `generate-template` (template.rs: create_dir_all). mkdir -p "$PKG/etc/slacker/templates" echo "https://forge.slackware.nl/rizitis/slacker/wiki/Templates" > "$PKG/etc/slacker/templates/Templates-howto.txt" for f in slacker.conf distro-upgrade.conf mirrors repos blacklist; do install -Dm0644 "CONF/etc-slacker/current/$ARCH/$f" "$PKG/etc/slacker/$f.new" done chmod 644 "$PKG"/etc/slacker/*.new install -dm700 "$PKG/etc/slacker/credentials.d" cp "CONF/README.credentials" "$PKG/etc/slacker/credentials.d/" chmod 0600 "$PKG/etc/slacker/credentials.d/README.credentials" cat > "$PKG/etc/slacker/credentials.cat.new" <<'EOF' # slacker repository credentials (HTTPS Basic) — OPTIONAL. # Public Slackware mirrors need NONE of this for now... # # Per-URL catalog: any repo whose URL starts with a section prefix uses it. # [https://forge.slackware.nl/rizitis] # username = rizitis # password = # # Or a named set in credentials.d/, referenced from the repos line with # `credentials=`. Either way: chmod 600, chown root:root. EOF chmod 600 "$PKG/etc/slacker/credentials.cat.new" # shell completions, generated from contrib/completions.json (see # contrib/gen-completions.py). bash is lazy-loaded by command name; zsh and # fish autoload from their standard vendor dirs. install -Dm0644 "contrib/slacker-completion.bash" "$PKG/usr/share/bash-completion/completions/slacker" install -Dm0644 "contrib/slacker-completion.zsh" "$PKG/usr/share/zsh/site-functions/_slacker" install -Dm0644 "contrib/slacker.fish" "$PKG/usr/share/fish/vendor_completions.d/slacker.fish" popd pushd slacker-gui cargo fetch \ --locked \ --target "$TARGET" cargo build \ --release \ --frozen \ --offline \ --target "$TARGET" cargo install \ --frozen \ --offline \ --no-track \ --root "$PKG/usr" \ --path="." \ --target "$TARGET" install -Dm644 "data/nl.slackware.forge.rizitis.SlackerGui.desktop" \ "$PKG/usr/share/applications/nl.slackware.forge.rizitis.SlackerGui.desktop" install -Dm644 "data/nl.slackware.forge.rizitis.slacker.policy" \ "$PKG/usr/share/polkit-1/actions/nl.slackware.forge.rizitis.slacker.policy" ( cd data/icons && find hicolor -type f ) | while read -r f; do install -Dm644 -o root -g root "data/icons/$f" "$PKG/usr/share/icons/$f" done popd # Don't ship .la files: rm -f "$PKG"/{,usr/}lib"$LIBDIRSUFFIX"/*.la # Stripping ELF binaries and libraries find "$PKG" -type f -print0 | while IFS= read -r -d '' binary; do desc=$(file -b "$binary" 2>/dev/null) || continue case "$desc" in *"current ar archive"*) strip -g "$binary" 2>/dev/null || true ;; *"shared object"*) strip --strip-unneeded "$binary" 2>/dev/null || true ;; *ELF*) strip --strip-all "$binary" 2>/dev/null || true ;; esac done # Compress manual pages, fix symlinks, and remove empty directories if [ -d "$PKG/usr/man" ]; then find -P "$PKG/usr/man" -type f -not -name "*.gz" -exec chmod 644 {} \; -exec gzip -9 {} \; while read -r i; do TARGET=$(readlink "$i") case "$TARGET" in "$PKG"/*) TARGET="${TARGET#"$PKG"}" ;; esac ln -s "${TARGET}.gz" "${i}.gz" && rm "$i" done < <(find -P "$PKG/usr/man" -type l 2>/dev/null) find -P "$PKG/usr/man" -depth -type d -empty -delete fi mkdir -p "$PKG/usr/doc/$PKGNAM-$VERSION/CONF" cp -a LICENSE NEWS README* "$PKG/usr/doc/$PKGNAM-$VERSION" 2>/dev/null || true cp -a slacker-cli/CONF/etc-slacker/current/"$ARCH"/* -t "$PKG/usr/doc/$PRGNAM-$VERSION/CONF/" rm -f "$PKG/usr/doc/$PKGNAM-$VERSION"/INSTALL* cat "$CWD/$PKGNAM.SlackBuild" > "$PKG/usr/doc/$PKGNAM-$VERSION/$PKGNAM.SlackBuild" find "$PKG/usr/doc/$PKGNAM-$VERSION" -type f -exec chmod 644 {} \; find "$PKG/usr/doc/$PKGNAM-$VERSION" -depth \( -type f -o -type d \) -empty -delete mkdir -p "$PKG/install" cat "$CWD/slack-desc" > "$PKG/install/slack-desc" if [ -e "$CWD/slack-required" ]; then cat "$CWD/slack-required" > "$PKG/install/slack-required" fi if [ -e "$CWD/doinst.sh" ]; then cat "$CWD/doinst.sh" > "$PKG/install/doinst.sh" fi cd "$PKG" /sbin/makepkg -l y -c n "$OUTPUT/$PKGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-txz}"