From 82850c151b5e48c3e2d79ca75715e791ac25150d Mon Sep 17 00:00:00 2001 From: James Swineson Date: Mon, 19 Dec 2022 17:21:24 +0800 Subject: [PATCH] ditch fpm and use nfpm from now on (as per #3 and #9) --- .gitignore | 2 +- README.md | 9 ++-- nfpm.yaml | 40 ++++++++++++++++ package.sh | 27 +++++------ scripts/postinst | 48 +++++++++++++++++++ scripts/postrm | 41 ++++++++++++++++ scripts/prerm | 29 +++++++++++ scripts/purge | 3 -- .../pve-fake-subscription.preset | 1 + .../system/pve-fake-subscription.service | 1 - usr/share/doc/pve-fake-subscription/copyright | 7 +++ 11 files changed, 184 insertions(+), 24 deletions(-) create mode 100644 nfpm.yaml create mode 100755 scripts/postinst create mode 100755 scripts/postrm create mode 100755 scripts/prerm delete mode 100755 scripts/purge create mode 100644 usr/lib/systemd/system-preset/pve-fake-subscription.preset create mode 100644 usr/share/doc/pve-fake-subscription/copyright diff --git a/.gitignore b/.gitignore index 741819a..7842801 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.deb +/out/ # Created by https://www.gitignore.io/api/macos,python,windows,visualstudiocode # Edit at https://www.gitignore.io/?templates=macos,python,windows,visualstudiocode @@ -193,4 +194,3 @@ $RECYCLE.BIN/ *.lnk # End of https://www.gitignore.io/api/macos,python,windows,visualstudiocode - diff --git a/README.md b/README.md index a3c3f73..a5d3f93 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# pve-fake-subscription + Disables the "No valid subscription" dialog on all Proxmox products. > I am really poor and I can't afford a license. I just want to get rid of the annoying dialog. @@ -5,11 +7,13 @@ Disables the "No valid subscription" dialog on all Proxmox products. ## Features Works for: + - Proxmox VE (5.x or later, tested up to 7.2) - Proxmox Mail Gateway (5.x or later) - Proxmox Backup Server (1.x) Highlights: + - Non-intrusive: zero modification of any system file - Future-proof: persists between system updates & major upgrades - Hassle-free: you can uninstall at any time @@ -29,6 +33,7 @@ The initial run will be scheduled within 1 minute of the installation. If you do After installation, please refrain yourself from clicking the "check" button on the "Subscription" page. It will invalidate the cache and temporary revert your instance into an unlicensed status. The fake subscription status doesn't grant you free access to the enterprise repository. You should switch to the no-subscription repository if not already done. Use the following method: + - [Proxmox VE (PVE)](https://pve.proxmox.com/wiki/Package_Repositories#sysadmin_no_subscription_repo) - [Proxmox Mail Gateway (PMG)](https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html#pmg_package_repositories) - [Proxmox Backup Server (PBS)](https://pbs.proxmox.com/docs/installation.html#proxmox-backup-no-subscription-repository) @@ -45,10 +50,8 @@ This will revert your system to a "no subscription key" status. ## Building the Package -Run everything as root on a Debian 10 system: +Install [nFPM](https://nfpm.goreleaser.com/install/), then: ```shell -apt-get install ruby ruby-dev rubygems build-essential -gem install fpm ./package.sh ``` diff --git a/nfpm.yaml b/nfpm.yaml new file mode 100644 index 0000000..d064544 --- /dev/null +++ b/nfpm.yaml @@ -0,0 +1,40 @@ +name: "pve-fake-subscription" +arch: "all" +platform: "linux" +version: "0.0.9" +version_schema: "semver" +version_metadata: "git" + +epoch: 0 +release: 1 +section: "admin" +priority: "optinal" + +maintainer: "Nobody " + +depends: +- python3 +description: | + Pollute the subscription cache of Proxmox VE (>=5.0), Proxmox Mail Gateway (>=5.0) & Proxmox Backup Server (>=1.0) so it won't alert you on dashboard login +vendor: "none" +homepage: "https://github.com/Jamesits/pve-fake-subscription" +license: "GLWTS(Good Luck With That Shit) Public License" + +contents: +- src: "./usr/bin/pve-fake-subscription" + dst: "/usr/bin/pve-fake-subscription" + file_info: + mode: 0755 +- src: "./usr/lib/systemd" + dst: "/usr/lib/systemd" + file_info: + mode: 0644 +- src: "./usr/share/doc/pve-fake-subscription" + dst: "/usr/share/doc/pve-fake-subscription" + file_info: + mode: 0644 + +scripts: + postinstall: "./scripts/postinst" + preremove: "./scripts/prerm" + postremove: "./scripts/postrm" diff --git a/package.sh b/package.sh index 0cf150e..21d60da 100755 --- a/package.sh +++ b/package.sh @@ -2,20 +2,15 @@ set -Eeuo pipefail cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1 -fpm -s dir -t deb --force \ - -n pve-fake-subscription \ - --description "Pollute the subscription cache of Proxmox VE (>=5.0), Proxmox Mail Gateway (>=5.0) & Proxmox Backup Server (>=1.0) so it won't alert you on dashboard login" \ - --url "https://github.com/Jamesits/pve-fake-subscription" \ - -v 0.0.8 \ - --license "GLWTS(Good Luck With That Shit) Public License" \ - --depends "python3" \ - --architecture all \ - --deb-dist "unstable" \ - --deb-priority "optional" \ - --deb-systemd "usr/lib/systemd/system/pve-fake-subscription.timer" \ - --deb-systemd-enable --deb-systemd-auto-start --deb-systemd-restart-after-upgrade \ - --after-remove "scripts/purge" \ - ./usr +OUT_DIR="out" - # temporary removed as of https://github.com/jordansissel/fpm/issues/1472 - #--deb-after-purge "scripts/purge" \ +rm -rf "${OUT_DIR}" +mkdir -p "${OUT_DIR}" + +# build package +nfpm pkg --packager deb --target "${OUT_DIR}" + +# generate checksum +pushd "${OUT_DIR}" >/dev/null +sha256sum -b -- * > sha256sum.txt +popd >/dev/null diff --git a/scripts/postinst b/scripts/postinst new file mode 100755 index 0000000..a39394a --- /dev/null +++ b/scripts/postinst @@ -0,0 +1,48 @@ +#!/bin/sh + +after_upgrade() { + : + + systemctl --system daemon-reload >/dev/null || true + debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) + if ! systemctl is-enabled pve-fake-subscription.timer >/dev/null + then + : # Ensure this if-clause is not empty. If it were empty, and we had an 'else', then it is an error in shell syntax + systemctl preset pve-fake-subscription.timer >/dev/null || true + $debsystemctl start pve-fake-subscription.timer >/dev/null || true + else + $debsystemctl restart pve-fake-subscription.timer >/dev/null || true + fi + + pve-fake-subscription +} + +after_install() { + : + + systemctl --system daemon-reload >/dev/null || true + debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) + systemctl preset pve-fake-subscription.timer >/dev/null || true + $debsystemctl start pve-fake-subscription.timer >/dev/null || true + + pve-fake-subscription +} + +if { [ "${1}" = "configure" ] && [ -z "${2}" ]; } || [ "${1}" = "abort-remove" ]; then + # "after install" here + # "abort-remove" happens when the pre-removal script failed. + # In that case, this script, which should be idemptoent, is run + # to ensure a clean roll-back of the removal. + after_install +elif [ "${1}" = "configure" ] && [ -n "${2}" ]; then + upgradeFromVersion="${2}" + # "after upgrade" here + # NOTE: This slot is also used when deb packages are removed, + # but their config files aren't, but a newer version of the + # package is installed later, called "Config-Files" state. + # basically, that still looks a _lot_ like an upgrade to me. + after_upgrade "${2}" +elif echo "${1}" | grep -E -q "(abort|fail)"; then + echo "Failed to install before the post-installation script was run." >&2 + exit 1 +fi diff --git a/scripts/postrm b/scripts/postrm new file mode 100755 index 0000000..eab36b4 --- /dev/null +++ b/scripts/postrm @@ -0,0 +1,41 @@ +#!/bin/sh + +after_remove() { + : + + rm -f /etc/subscription + rm -f /etc/pmg/subscription + rm -f /etc/proxmox-backup/subscription +} + +after_purge() { + : +} + +dummy() { + : +} + +if [ "${1}" = "remove" ] || [ "${1}" = "abort-install" ]; then + # "after remove" goes here + # "abort-install" happens when the pre-installation script failed. + # In that case, this script, which should be idemptoent, is run + # to ensure a clean roll-back of the installation. + after_remove +elif [ "${1}" = "purge" ] && [ -z "${2}" ]; then + # like "on remove", but executes after dpkg deletes config files + # 'apt-get purge' runs 'on remove' section, then this section. + # There is no equivalent in RPM or ARCH. + after_purge +elif [ "${1}" = "upgrade" ]; then + # This represents the case where the old package's postrm is called after + # the 'preinst' script is called. + # We should ignore this and just use 'preinst upgrade' and + # 'postinst configure'. The newly installed package should do the + # upgrade, not the uninstalled one, since it can't anticipate what new + # things it will have to do to upgrade for the new version. + dummy +elif echo "${1}" | grep -E -q '(fail|abort)'; then + echo "Failed to install before the post-removal script was run." >&2 + exit 1 +fi diff --git a/scripts/prerm b/scripts/prerm new file mode 100755 index 0000000..fdb3552 --- /dev/null +++ b/scripts/prerm @@ -0,0 +1,29 @@ +#!/bin/sh + +before_remove() { + : + + debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) + $debsystemctl stop pve-fake-subscription.timer >/dev/null || true + systemctl disable pve-fake-subscription.timer >/dev/null || true + systemctl --system daemon-reload >/dev/null || true +} + +dummy() { + : +} + +if [ "${1}" = "remove" ] && [ -z "${2}" ]; then + # "before remove" goes here + before_remove +elif [ "${1}" = "upgrade" ]; then + # Executed before the old version is removed + # upon upgrade. + # We should generally not do anything here. The newly installed package + # should do the upgrade, not the uninstalled one, since it can't anticipate + # what new things it will have to do to upgrade for the new version. + dummy +elif echo "${1}" | grep -E -q "(fail|abort)"; then + echo "Failed to install before the pre-removal script was run." >&2 + exit 1 +fi diff --git a/scripts/purge b/scripts/purge deleted file mode 100755 index 9b7d69b..0000000 --- a/scripts/purge +++ /dev/null @@ -1,3 +0,0 @@ -rm -f /etc/subscription -rm -f /etc/pmg/subscription -rm -f /etc/proxmox-backup/subscription \ No newline at end of file diff --git a/usr/lib/systemd/system-preset/pve-fake-subscription.preset b/usr/lib/systemd/system-preset/pve-fake-subscription.preset new file mode 100644 index 0000000..b9e8888 --- /dev/null +++ b/usr/lib/systemd/system-preset/pve-fake-subscription.preset @@ -0,0 +1 @@ +enable pve-fake-subscription.timer diff --git a/usr/lib/systemd/system/pve-fake-subscription.service b/usr/lib/systemd/system/pve-fake-subscription.service index 2b77ffc..46eb64d 100644 --- a/usr/lib/systemd/system/pve-fake-subscription.service +++ b/usr/lib/systemd/system/pve-fake-subscription.service @@ -4,4 +4,3 @@ Description=Fake a Proxmox VE subscription [Service] Type=oneshot ExecStart=/usr/bin/pve-fake-subscription - diff --git a/usr/share/doc/pve-fake-subscription/copyright b/usr/share/doc/pve-fake-subscription/copyright new file mode 100644 index 0000000..2f77829 --- /dev/null +++ b/usr/share/doc/pve-fake-subscription/copyright @@ -0,0 +1,7 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: pve-fake-subscription +Source: https://github.com/Jamesits/pve-fake-subscription + +Files: * +Copyright: 2019 Nobody +License: GLWTS(Good Luck With That Shit) Public License