@@ -41,6 +41,7 @@ exports[`arm 2`] = `
4141 "/usr/share/",
4242 "/opt/Test App ßW/resources/",
4343 "/opt/Test App ßW/resources/app.asar",
44+ "/opt/Test App ßW/resources/apparmor-profile",
4445 "/usr/share/applications/",
4546 "/usr/share/applications/testapp.desktop",
4647 "/usr/share/doc/",
@@ -115,6 +116,7 @@ exports[`arm 5`] = `
115116 "/usr/share/",
116117 "/opt/Test App ßW/resources/",
117118 "/opt/Test App ßW/resources/app.asar",
119+ "/opt/Test App ßW/resources/apparmor-profile",
118120 "/usr/share/applications/",
119121 "/usr/share/applications/testapp.desktop",
120122 "/usr/share/doc/",
@@ -200,6 +202,7 @@ exports[`custom depends 2`] = `
200202 "/usr/share/",
201203 "/opt/Test App ßW/resources/",
202204 "/opt/Test App ßW/resources/app.asar",
205+ "/opt/Test App ßW/resources/apparmor-profile",
203206 "/usr/share/applications/",
204207 "/usr/share/applications/Boo.desktop",
205208 "/usr/share/doc/",
@@ -285,6 +288,7 @@ exports[`deb 2`] = `
285288 "/usr/share/",
286289 "/opt/Test App ßW/resources/",
287290 "/opt/Test App ßW/resources/app.asar",
291+ "/opt/Test App ßW/resources/apparmor-profile",
288292 "/usr/share/applications/",
289293 "/usr/share/applications/testapp.desktop",
290294 "/usr/share/doc/",
@@ -370,6 +374,7 @@ exports[`deb file associations 2`] = `
370374 "/usr/share/",
371375 "/opt/Test App ßW/resources/",
372376 "/opt/Test App ßW/resources/app.asar",
377+ "/opt/Test App ßW/resources/apparmor-profile",
373378 "/usr/share/applications/",
374379 "/usr/share/applications/testapp.desktop",
375380 "/usr/share/doc/",
@@ -469,6 +474,7 @@ exports[`executable path in postinst script 2`] = `
469474 "/usr/share/",
470475 "/opt/foo/resources/",
471476 "/opt/foo/resources/app.asar",
477+ "/opt/foo/resources/apparmor-profile",
472478 "/usr/share/applications/",
473479 "/usr/share/applications/Boo.desktop",
474480 "/usr/share/doc/",
544550
545551if hash update-desktop-database 2>/dev/null; then
546552 update-desktop-database /usr/share/applications || true
553+ fi
554+
555+ # Install apparmor profile. (Ubuntu 24+)
556+ # First check if the version of AppArmor running on the device supports our profile.
557+ # This is in order to keep backwards compatibility with Ubuntu 22.04 which does not support abi/4.0.
558+ # In that case, we just skip installing the profile since the app runs fine without it on 22.04.
559+ #
560+ # Those apparmor_parser flags are akin to performing a dry run of loading a profile.
561+ # https://wiki.debian.org/AppArmor/HowToUse#Dumping_profiles
562+ #
563+ # Unfortunately, at the moment AppArmor doesn't have a good story for backwards compatibility.
564+ # https://askubuntu.com/questions/1517272/writing-a-backwards-compatible-apparmor-profile
565+ APPARMOR_PROFILE_SOURCE='/opt/foo/resources/apparmor-profile'
566+ APPARMOR_PROFILE_TARGET='/etc/apparmor.d/Boo'
567+ if test -d "/etc/apparmor.d"; then
568+ if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then
569+ cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET"
570+
571+ if hash apparmor_parser 2>/dev/null; then
572+ # Extra flags taken from dh_apparmor:
573+ # > By using '-W -T' we ensure that any abstraction updates are also pulled in.
574+ # https://wiki.debian.org/AppArmor/Contribute/FirstTimeProfileImport
575+ apparmor_parser --replace --write-cache --skip-read-cache "$APPARMOR_PROFILE_TARGET"
576+ fi
577+ else
578+ echo "Skipping the installation of the AppArmor profile as this version of AppArmor does not seem to support the bundled profile"
579+ fi
547580fi"
548581` ;
549582
@@ -597,6 +630,7 @@ exports[`no quotes for safe exec name 3`] = `
597630 "/usr/share/",
598631 "/opt/foo/resources/",
599632 "/opt/foo/resources/app.asar",
633+ "/opt/foo/resources/apparmor-profile",
600634 "/usr/share/applications/",
601635 "/usr/share/applications/Boo.desktop",
602636 "/usr/share/doc/",
@@ -682,6 +716,7 @@ exports[`top-level exec name 2`] = `
682716 "/usr/share/",
683717 "/opt/foo/resources/",
684718 "/opt/foo/resources/app.asar",
719+ "/opt/foo/resources/apparmor-profile",
685720 "/usr/share/applications/",
686721 "/usr/share/applications/Boo.desktop",
687722 "/usr/share/doc/",
0 commit comments