Skip to content

Commit 1020efd

Browse files
committed
fix: Improve GitHub API zipball extraction and fix permissions
- Replace mv with find/cp for more reliable subdirectory extraction - Add cleanup of leftover temp_extract directories - Fix ownership (www-data:www-data) and permissions (755) for plugins/themes - Add detailed logging of ownership and permissions verification - Apply fixes to both runtime and build-time extraction methods - This should fix the temp_extract directory issue and permission problems
1 parent aee4420 commit 1020efd

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

β€Žscripts/mautic-deployer.tsβ€Ž

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
Β (0)