@@ -541,18 +541,30 @@ [Desktop Entry]
541541 if ( OperatingSystem . IsWindows ( ) )
542542 {
543543 var distro = ResolveWslDistroName ( WslDistro ) ;
544- var wslDebRoot = ConvertToWslPath ( distro , debStagingDirectory ) ;
544+ var wslDebRootSource = ConvertToWslPath ( distro , debStagingDirectory ) ;
545545 var wslDebPath = ConvertToWslPath ( distro , debFilePath ) ;
546- var wslAppExecutablePath = ConvertToWslPath ( distro , Path . Combine ( applicationDirectory , executableName ) ) ;
547- var wslPostinstPath = ConvertToWslPath ( distro , Path . Combine ( debStagingDirectory , "DEBIAN" , "postinst" ) ) ;
548- var wslPostrmPath = ConvertToWslPath ( distro , Path . Combine ( debStagingDirectory , "DEBIAN" , "postrm" ) ) ;
549- InvokeWslCommand ( distro , $ "chmod +x { QuoteBashLiteral ( wslAppExecutablePath ) } { QuoteBashLiteral ( wslPostinstPath ) } { QuoteBashLiteral ( wslPostrmPath ) } ") ;
550- InvokeWslCommand ( distro , $ "dpkg-deb --build --root-owner-group { QuoteBashLiteral ( wslDebRoot ) } { QuoteBashLiteral ( wslDebPath ) } ") ;
546+ var wslBuildRoot = $ "/tmp/mcpservermanager-deb-{ Guid . NewGuid ( ) : N} ";
547+ var wslDebRoot = $ "{ wslBuildRoot } /package";
548+ var wslTempDebPath = $ "{ wslBuildRoot } /{ Path . GetFileName ( debFilePath ) } ";
549+ var wslDebRootSourceContents = $ "{ wslDebRootSource } /.";
550+ var wslControlDirectory = $ "{ wslDebRoot } /DEBIAN";
551+ var wslControlPath = $ "{ wslControlDirectory } /control";
552+ var wslAppExecutablePath = $ "{ wslDebRoot } /opt/mcpservermanager/{ executableName } ";
553+ var wslPostinstPath = $ "{ wslControlDirectory } /postinst";
554+ var wslPostrmPath = $ "{ wslControlDirectory } /postrm";
555+
556+ // Build the Debian package inside the Linux filesystem so dpkg-deb sees valid Unix permissions.
557+ InvokeWslCommand ( distro , $ "rm -rf { QuoteBashLiteral ( wslBuildRoot ) } && mkdir -p { QuoteBashLiteral ( wslDebRoot ) } && cp -a { QuoteBashLiteral ( wslDebRootSourceContents ) } { QuoteBashLiteral ( wslDebRoot ) } /") ;
558+ InvokeWslCommand ( distro , $ "chmod 0755 { QuoteBashLiteral ( wslControlDirectory ) } && chmod 0644 { QuoteBashLiteral ( wslControlPath ) } && chmod 0755 { QuoteBashLiteral ( wslPostinstPath ) } { QuoteBashLiteral ( wslPostrmPath ) } { QuoteBashLiteral ( wslAppExecutablePath ) } ") ;
559+ InvokeWslCommand ( distro , $ "dpkg-deb --build --root-owner-group { QuoteBashLiteral ( wslDebRoot ) } { QuoteBashLiteral ( wslTempDebPath ) } ") ;
560+ InvokeWslCommand ( distro , $ "cp { QuoteBashLiteral ( wslTempDebPath ) } { QuoteBashLiteral ( wslDebPath ) } ") ;
551561 if ( installAfterBuild )
552562 {
553563 Info ( $ "Launching interactive WSL sudo in distro '{ distro } '. Enter your password if prompted.") ;
554- InvokeInteractiveWslCommand ( distro , $ "sudo dpkg -i { QuoteBashLiteral ( wslDebPath ) } ") ;
564+ InvokeInteractiveWslCommand ( distro , $ "sudo dpkg -i { QuoteBashLiteral ( wslTempDebPath ) } ") ;
555565 }
566+
567+ InvokeWslCommand ( distro , $ "rm -rf { QuoteBashLiteral ( wslBuildRoot ) } ") ;
556568 }
557569 else
558570 {
0 commit comments