]> git.proxmox.com Git - pmg-api.git/commitdiff
postinst: migrate/update APT auth config
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 14 Sep 2022 08:05:39 +0000 (10:05 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Sep 2022 08:46:59 +0000 (10:46 +0200)
missed when switching over to Proxmox::RS::Subscription, which stores
the same info in the product-specific /etc/apt/auth.conf.d/pmg.conf .

the top-level file might contain non-PMG-managed entries, so only remove
entries matching "our" machine/

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
debian/postinst

index fdcecbf2ec3b84aba9c3dfdeddb1cbfddadd4c7e..8ea71583526a1fe054a03c66b72b2362839df21a 100644 (file)
@@ -19,6 +19,36 @@ ucf_register_templates() {
     done
 }
 
+migrate_apt_auth_conf() {
+    output=""
+    removed=""
+    match=0
+
+    while read -r l; do
+       if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pmg"; then
+           match=1
+       elif echo "$l" | grep -q "machine"; then
+           match=0
+       fi
+
+       if test "$match" = "1"; then
+           removed="$removed\n$l"
+       else
+           output="$output\n$l"
+       fi
+    done < /etc/apt/auth.conf
+
+    if test -n "$removed"; then
+       if test ! -e /etc/apt/auth.conf.d/pmg.conf; then
+           echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pmg.conf .."
+           echo "$removed" > /etc/apt/auth.conf.d/pmg.conf
+       else
+           echo "Removing stale APT auth config from /etc/apt/auth.conf"
+       fi
+       echo "$output" > /etc/apt/auth.conf
+    fi
+}
+
 case "$1" in
     triggered)
 
@@ -81,6 +111,12 @@ case "$1" in
            # rewrite banner
            pmgbanner || true
        fi
+
+       if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.1-7~'; then
+           if test -e /etc/apt/auth.conf ; then
+               migrate_apt_auth_conf
+           fi
+       fi
     ;;
 
     abort-upgrade)