#!/bin/bash set -e apt() { (set -x; command apt "$@") } [ "$(id -u)" = 0 ] || exec sudo bash "$0" "$@" basics='etckeeper git info par ssh tmux vim w3m' #xorg='xorg xterm i3' xorg='xorg xterm' media='libdbus-glib-1-2 mpv pulseaudio' apt install --no-upgrade $basics $xorg $media apt_backport() { ( set -e apt install --no-upgrade debhelper SOURCES_DIR=$1 TARGET_URL=$2 TARGET_PKG=$3 case "$TARGET_PKG" in '' | */*) exit 1 ;; esac mkdir -p "$SOURCES_DIR" cd "$SOURCES_DIR" if [ -e "$TARGET_PKG" ] then cd "$TARGET_PKG" git pull --ff-only else rm -rf "$TARGET_PKG"~tmp git clone --depth=1 "$TARGET_URL" "$TARGET_PKG"~tmp mv -T "$TARGET_PKG"~tmp "$TARGET_PKG" cd "$TARGET_PKG" fi arch=$(dpkg-architecture -q DEB_BUILD_ARCH) version=$(dpkg-parsechangelog --show-field Version) pkgs=$(dh_listpackages) debs= for pkg in $pkgs do debs="$debs ${pkg}_${version}_${arch}.deb" done for deb in $debs do [ -e ../"$deb" ] && continue || true # We are missing a deb, therefore build. if command -v mk-build-deps >/dev/null then mk-build-deps "$TARGET_PKG" --install else # We could 'apt install devscripts' but it pulls # in like 50MB of perl deps, possibly nullifying # the savings from removing unneeded build deps. # However, we cannot simply use 'apt build-dep' # because that would use the build-deps from the # version of the package in the repo, which may # differ from the source version. # Arguably we do want to try that though, since # it's a backport... if [ "$try_newer_build_deps" ] then build_deps=$(get_build_deps) apt install $build_deps else apt build-dep "$TARGET_PKG" fi fi fakeroot ./debian/rules binary break done set -- for deb in $debs do set -- "$@" ../"$deb" done apt install "$@" ) } get_build_deps() { # credit: Archemar @ https://unix.stackexchange.com/a/648927 build_deps=$(dpkg-checkbuilddeps 2>&1 | sed -n -e 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies: //gp' \ -e 's/[\(][^)]*[\)] //g') } try_newer_build_deps=y apt_backport /usr/local/src https://salsa.debian.org/i3-team/i3-wm.git i3-wm