@@ -667,6 +667,37 @@ tasks.register("setExecutablePermissions") {
667667 }
668668}
669669
670+ tasks.register(" fixDebPermissions" ) {
671+ description = " Rebuilds the .deb so binaries under opt/processing/lib/app/resources keep their executable bit " +
672+ " (jpackage's own deb assembly does not reliably preserve it for arbitrary resource files)"
673+ group = " compose desktop"
674+ onlyIf { OperatingSystem .current().isLinux }
675+
676+ val execOps = objects.newInstance<ExecOps >().execOps
677+
678+ doLast {
679+ val debDir = layout.buildDirectory.dir(" compose/binaries/main/deb" ).get().asFile
680+ val deb = debDir.listFiles { f -> f.name.startsWith(" processing" ) && f.name.endsWith(" .deb" ) }
681+ ?.singleOrNull()
682+ ? : throw GradleException (" Expected exactly one processing*.deb in $debDir " )
683+
684+ val extractDir = debDir.resolve(" ${deb.nameWithoutExtension} -fixperms" )
685+ extractDir.deleteRecursively()
686+
687+ execOps.exec {
688+ commandLine(
689+ " fakeroot" , " bash" , " -c" ,
690+ " dpkg-deb -R '${deb.absolutePath} ' '${extractDir.absolutePath} ' && " +
691+ " find '${extractDir.absolutePath} /opt/processing/lib/app/resources' " +
692+ " -path '*/bin/*' -type f -exec chmod +x {} + && " +
693+ " dpkg-deb -b '${extractDir.absolutePath} ' '${deb.absolutePath} '"
694+ )
695+ }
696+
697+ extractDir.deleteRecursively()
698+ }
699+ }
700+
670701afterEvaluate {
671702 tasks.named(" prepareAppResources" ).configure {
672703 dependsOn(" includeProcessingResources" )
@@ -675,4 +706,15 @@ afterEvaluate {
675706 dependsOn(" includeJdk" )
676707 finalizedBy(" setExecutablePermissions" )
677708 }
709+ // finalizedBy above only guarantees setExecutablePermissions runs after
710+ // createDistributable, not before packageDeb, which merely depends on
711+ // createDistributable transitively - without this, jpackage can read the
712+ // app image before permissions are restored on it.
713+ tasks.named(" packageDeb" ).configure {
714+ dependsOn(" setExecutablePermissions" )
715+ // jpackage's own --type deb assembly doesn't reliably preserve the
716+ // executable bit on arbitrary resource binaries (java, windres, ...);
717+ // rebuild the .deb afterward via dpkg-deb to force it back on.
718+ finalizedBy(" fixDebPermissions" )
719+ }
678720}
0 commit comments