summaryrefslogtreecommitdiff
path: root/packagesync-ng
diff options
context:
space:
mode:
Diffstat (limited to 'packagesync-ng')
-rwxr-xr-xpackagesync-ng66
1 files changed, 66 insertions, 0 deletions
diff --git a/packagesync-ng b/packagesync-ng
new file mode 100755
index 0000000..664db99
--- /dev/null
+++ b/packagesync-ng
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+
+echo "WARNING: This project will happily delete all your packages if you are not careful!"
+echo "To Proceed acknowledge that you have read this by deleting the \`exit 77\` line in this script"
+exit 77
+
+PACKAGE_NAME=herk
+PACKAGE_MAINTAINER="herk <debian@herkulessi.de>"
+
+set -eu
+umask 077
+TEMPDIR=$(mktemp -d -t packagesync-XXXXXXXX)
+
+cd "$TEMPDIR" || exit 1
+
+MISSING_DEPENDENCIES=()
+command -v yq >/dev/null 2>&1 || MISSING_DEPENDENCIES+=(yq)
+command -v equivs-build >/dev/null 2>&1 || MISSING_DEPENDENCIES+=(equivs)
+command -v stat >/dev/null 2>&1 || MISSING_DEPENDENCIES+=(coreutils)
+command -v mktemp >/dev/null 2>&1 || MISSING_DEPENDENCIES+=(coreutils)
+
+set +u
+if [ "${#MISSING_DEPENDENCIES}" -gt 0 ]; then
+ echo "Installing missing dependencies:" "${MISSING_DEPENDENCIES[@]}" ...
+ apt-get install --no-install-recommends -yq "${MISSING_DEPENDENCIES[@]}"
+ echo "Done installing dependencies."
+fi
+set -u
+
+OLD_VERSION=$(dpkg-query --showformat='${Version}' --show "$PACKAGE_NAME" 2>/dev/null || echo 0)
+NEW_VERSION=$(stat -c %Y /etc/packages.yaml)
+
+if [ "$OLD_VERSION" -ge "$NEW_VERSION" ]; then
+ cd /
+ rm -rf "$TEMPDIR"
+ apt-mark manual "$PACKAGE_NAME"
+ apt-mark showmanual | grep -v "^${PACKAGE_NAME}$" | xargs apt-mark auto || true # ignore empty list
+ apt-get autoremove --purge -yq
+ exit 0
+fi
+
+cat > "$PACKAGE_NAME" << EOF
+Section: misc
+Priority: optional
+Standards-Version: 3.9.2
+
+Package: $PACKAGE_NAME
+Version: $NEW_VERSION
+Maintainer: $PACKAGE_MAINTAINER
+Depends: $(< /etc/packages.yaml yq -r '.install | to_entries | map(.value) | add | map(tostring) | join(", ")'), apt, coreutils, equivs, findutils, yq
+Conflicts: $(< /etc/packages.yaml yq -r '.remove | to_entries | map(.value) | add | map(tostring) | join(", ")')
+Description: Metapackage for all needed packages.
+ This is a dummy package, depending on other packages to make Package Management easier.
+EOF
+
+equivs-build "$PACKAGE_NAME"
+
+apt-get install -yq --no-install-recommends ./${PACKAGE_NAME}_${NEW_VERSION}_all.deb
+
+apt-mark manual "$PACKAGE_NAME"
+apt-mark showmanual | grep -v "^${PACKAGE_NAME}$" | xargs apt-mark auto || true # ignore empty list
+
+apt-get autoremove -yq --purge
+
+cd /
+rm -rf "$TEMPDIR"