Skip to content

Commit a658cac

Browse files
committed
Added install script to fix chrome file permission issues.
Signed-off-by: Hermann Mayer <[email protected]>
1 parent 85441db commit a658cac

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

exe/fix-local-chrome-permissions

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
// Windows does not need this
4+
if (process.platform === 'win32') {
5+
process.exit(0);
6+
}
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
// Get the installed chromium path
12+
const Downloader = require('puppeteer/utils/ChromiumDownloader');
13+
const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
14+
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
15+
const chromiumPath = revisionInfo.folderPath;
16+
17+
// Some sneaky little helpers to get the job done
18+
const walkSync = (d) => {
19+
return fs.statSync(d).isDirectory()
20+
? fs.readdirSync(d).map(f => walkSync(path.join(d, f))) : d;
21+
}
22+
const flatten = (arr) => {
23+
return arr.reduce(function (flat, toFlatten) {
24+
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
25+
}, []);
26+
};
27+
28+
29+
// Walk over each file, check its executable permission and enable
30+
// ugo+r/ugo+rx accordingly
31+
flatten(walkSync(chromiumPath)).forEach(function(path) {
32+
const stat = fs.statSync(path);
33+
34+
if (!stat.isFile()) {
35+
return;
36+
}
37+
38+
const isExecutable = stat.mode & 0100;
39+
40+
if (isExecutable) {
41+
fs.chmodSync(path, 0755);
42+
} else {
43+
fs.chmodSync(path, 0644);
44+
}
45+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"pdfgen": "./bin/pdfgen"
77
},
88
"scripts": {
9+
"install": "./exe/fix-local-chrome-permissions",
910
"test": "nyc mocha",
1011
"coverage": "nyc report --reporter=lcov"
1112
},

0 commit comments

Comments
 (0)