#!/bin/bash set -e basics='etckeeper git par ssh tmux vim w3m debhelper' docs='info bash-doc make-doc' xorg='xorg xterm x11vnc xserver-xephyr xtightvncviewer xdotool' media='libdbus-glib-1-2 mpv pulseaudio imagemagick' main() { [ "$(id -u)" = 0 ] || exec sudo bash "$0" "$@" apt install -q --show-progress --no-upgrade $basics $docs $xorg $media apt_backport /usr/local/src https://salsa.debian.org/i3-team/i3-wm.git i3-wm } apt() { (set -x; command apt "$@") } all_files_exist() { for f in "$@" do [ -e "$f" ] || return done true } # Clone into temporary directory then move to final dest -- to preserve # idempotence in case of git failure. git_clone() { local src dst tmpdst local src="$1" local dst="$(realpath "$2")" || return local tmpdst="$(mktemp -d "$dst"~tmp~XXXXXX)" || return if git clone --depth=1 -- "$src" "$tmpdst" then mv -T -- "$tmpdst" "$dst" else r=$? rm -rf -- "$tmpdst" return $r fi } apt_backport() { ( set -e 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 git_clone "$TARGET_URL" "$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 if ! all_files_exist $debs then build_deps=$(get_build_deps) if [ "$build_deps" ] then apt install --mark-auto $build_deps fi fakeroot ./debian/rules binary fi apt install $debs ) } get_build_deps() { # credit: Archemar @ https://unix.stackexchange.com/a/648927 dpkg-checkbuilddeps 2>&1 | sed -n -e 's/dpkg-checkbuilddeps: error: Unmet build dependencies: //gp' \ -e 's/([^)]*) //g' } main "$@"