@@ -514,7 +514,7 @@ PORT=${this.config.port}
514514 // For GitHub API zipballs, we need to handle the nested directory structure
515515 if ( cleanUrl . includes ( 'api.github.com' ) ) {
516516 // GitHub API creates a zip with a subdirectory named after the commit
517- extractCommand = `cd build/plugins && mkdir -p temp_extract && unzip -o "${ fileName } " -d temp_extract && rm "${ fileName } " && mv temp_extract/*/* "${ directory } /" && rm -rf temp_extract` ;
517+ extractCommand = `cd build/plugins && mkdir -p temp_extract " ${ directory } " && unzip -o "${ fileName } " -d temp_extract && rm "${ fileName } " && find temp_extract -mindepth 1 -maxdepth 1 -type d -exec cp -r {}/* "${ directory } /" \\; && rm -rf temp_extract` ;
518518 } else {
519519 extractCommand = `cd build/plugins && mkdir -p "${ directory } " && unzip -o "${ fileName } " -d "${ directory } " && rm "${ fileName } "` ;
520520 }
@@ -676,7 +676,7 @@ PORT=${this.config.port}
676676 // For GitHub API zipballs, we need to handle the nested directory structure
677677 if ( cleanUrl . includes ( 'api.github.com' ) ) {
678678 // GitHub API creates a zip with a subdirectory named after the commit
679- extractCommand = `mkdir -p temp_extract && unzip -o theme.zip -d temp_extract && rm theme.zip && mv temp_extract/*/* "${ directory } /" && rm -rf temp_extract` ;
679+ extractCommand = `mkdir -p temp_extract " ${ directory } " && unzip -o theme.zip -d temp_extract && rm theme.zip && find temp_extract -mindepth 1 -maxdepth 1 -type d -exec cp -r {}/* "${ directory } /" \\; && rm -rf temp_extract` ;
680680 } else {
681681 extractCommand = `mkdir -p "${ directory } " && unzip -o theme.zip -d "${ directory } " && rm theme.zip` ;
682682 }
@@ -688,6 +688,18 @@ PORT=${this.config.port}
688688 docker exec mautic_web bash -c "cd /var/www/html/docroot/themes && ${ curlCommand } && ${ extractCommand } "
689689 ` , { ignoreError : true } ) ;
690690
691+ // Fix ownership and permissions for the theme directory if specified
692+ if ( directory ) {
693+ Logger . log ( `π Setting correct ownership and permissions for theme ${ directory } ...` , 'π' ) ;
694+ const chownResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'chown -R www-data:www-data /var/www/html/docroot/themes/${ directory } && chmod -R 755 /var/www/html/docroot/themes/${ directory } '` , { ignoreError : true } ) ;
695+
696+ if ( chownResult . success ) {
697+ Logger . log ( `β
Theme ownership and permissions set correctly` , 'β
' ) ;
698+ } else {
699+ Logger . log ( `β οΈ Warning: Could not set theme ownership/permissions: ${ chownResult . output } ` , 'β οΈ' ) ;
700+ }
701+ }
702+
691703 // Clear cache after theme installation
692704 Logger . log ( `π§Ή Clearing cache after theme installation...` , 'π§Ή' ) ;
693705 const cacheResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && rm -rf var/cache/prod/*'` , { ignoreError : true } ) ;
@@ -743,6 +755,9 @@ PORT=${this.config.port}
743755 // Use URL-specific token if provided, otherwise fall back to global token
744756 const authToken = token || this . config . githubToken ;
745757
758+ // Clean up any leftover temp directories from previous failed extractions
759+ await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html/docroot/plugins && rm -rf temp_extract'` , { ignoreError : true } ) ;
760+
746761 // Handle upgrades: remove existing plugin directory if it exists
747762 if ( directory ) {
748763 Logger . log ( `π Checking for existing plugin: ${ directory } ` , 'π' ) ;
@@ -810,8 +825,8 @@ PORT=${this.config.port}
810825 // For GitHub API zipballs, we need to handle the nested directory structure
811826 if ( cleanUrl . includes ( 'api.github.com' ) ) {
812827 // GitHub API creates a zip with a subdirectory named after the commit
813- // Extract to temp, then move contents to target directory
814- extractResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html/docroot/plugins && mkdir -p temp_extract && unzip -o plugin.zip -d temp_extract && rm plugin.zip && mv temp_extract/*/* "${ directory } /" && rm -rf temp_extract'` , { ignoreError : true } ) ;
828+ // Extract to temp, find the subdirectory, then move contents to target directory
829+ extractResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html/docroot/plugins && mkdir -p temp_extract " ${ directory } " && unzip -o plugin.zip -d temp_extract && rm plugin.zip && find temp_extract -mindepth 1 -maxdepth 1 -type d -exec cp -r {}/* "${ directory } /" \\; && rm -rf temp_extract'` , { ignoreError : true } ) ;
815830 } else {
816831 extractResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html/docroot/plugins && mkdir -p "${ directory } " && unzip -o plugin.zip -d "${ directory } " && rm plugin.zip'` , { ignoreError : true } ) ;
817832 }
@@ -846,6 +861,23 @@ PORT=${this.config.port}
846861 Logger . log ( dirContents . output , 'π' ) ;
847862 }
848863 }
864+
865+ // Fix ownership and permissions for the plugin directory
866+ Logger . log ( `π Setting correct ownership and permissions for ${ directory } ...` , 'π' ) ;
867+ const chownResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'chown -R www-data:www-data /var/www/html/docroot/plugins/${ directory } && chmod -R 755 /var/www/html/docroot/plugins/${ directory } '` , { ignoreError : true } ) ;
868+
869+ if ( chownResult . success ) {
870+ Logger . log ( `β
Ownership and permissions set correctly` , 'β
' ) ;
871+ } else {
872+ Logger . log ( `β οΈ Warning: Could not set ownership/permissions: ${ chownResult . output } ` , 'β οΈ' ) ;
873+ }
874+
875+ // Verify final ownership and permissions
876+ const permCheck = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'ls -la /var/www/html/docroot/plugins/${ directory } /'` , { ignoreError : true } ) ;
877+ if ( permCheck . success ) {
878+ Logger . log ( `π Final ownership and permissions for ${ directory } :` , 'π' ) ;
879+ Logger . log ( permCheck . output , 'π' ) ;
880+ }
849881 }
850882
851883 // Run Mautic plugin installation command
0 commit comments