Skip to content

Commit

Permalink
testing ways to extract macos *.pkg files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Jan 25, 2018
1 parent 163bcaa commit e1a8564
Showing 1 changed file with 29 additions and 35 deletions.
64 changes: 29 additions & 35 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,62 @@ var decompress = require('inly');
if (process.platform == "darwin") var macunpack = require('xar');
// will use zip binary 7za.exe on windows to extract 7z
var winfilezip = '7za920.zip';

var macunpack = require('xar');
var xar = require( 'xarchive' );
const _7zipData = getDataForPlatform();
const whattocopy = _7zipData.binaryfiles;
const cwd = process.cwd();
const destination = path.join(cwd, process.platform);
const source = path.join(cwd, _7zipData.filename);

fs.mkdir(destination, (err) => { if (err) {}});

wget({ url: _7zipData.url + _7zipData.filename, dest: source })
.then(function () {
console.log('Decompressing ' + _7zipData.filename);
var buffer = fs.createWriteStream(source);
macunpack.unpack(fs.readFileSync(source), function (err, file, content) {
if (err) return console.error(err)
if (file.type[0] === 'directory') {
fs.mkdirSync(file.path)
} else {
fs.writeFileSync(file.path, content)
}
});
});
/*
wget({ url: _7zipData.url + _7zipData.filename, dest: source })
.then(function () {
console.log('Decompressing ' + _7zipData.filename);
const extract = decompress(source, destination);
extract.on('file', (name) => {
console.log(name);
//////////////////
if (whattocopy.indexOf(path.basename(name)) == 1){
fs.renameSync(path.join(destination, _7zipData.extractfolder, _7zipData.applocation,path.basename(name)), path.join(__dirname,'binaries',process.platform,path.basename(name)));
console.log('--->File copied!');
}
//////////////////
if (whattocopy.indexOf(path.basename(name)) > 0) console.log(name);
});
extract.on('error', (error) => {
console.error(error);
});
extract.on('end', () => {
console.log('done');
fs.unlinkSync(source);
rmdir(destination);
fs.move(path.join(destination, _7zipData.extractfolder, _7zipData.applocation), path.join(__dirname,'binaries',process.platform), { overwrite: true }, (err) => { if (err) return console.error(err);
console.log('Binaries copied successfully!');
// fs.unlink(source, (err) => { if (err) console.error(err); });
// fs.remove(destination, (err) => { if (err) console.error(err); });
});
});
});

*/
function getDataForPlatform(){
if (process.platform == "darwin") var macos = require('macos-release').version;
if (process.platform == "win32") var macos = '10.6';//require('macos-release').version;
switch (process.platform) {
// Windows version
case "linux": return { url: 'http://d.7-zip.org/a/',
case "darwin": return { url: 'http://d.7-zip.org/a/',
filename: '7z1800-extra.7z',
extraname: 'lzma1800.7z',
extractfolder: '',
applocation: '',
binaryfiles: [ '7za.dll', '7za.exe', '7zxa.dll', 'x64', '7zr.exe' ],
binaryfiles: ['7za.dll','7za.exe','7zxa.dll','7zr.exe'],
sfxmodules: ['7zS2.sfx','7zS2con.sfx','7zSD.sfx'] };
// Linux version
case "win32": return {
case "linux": return {
url: 'http://cfhcable.dl.sourceforge.net/project/p7zip/p7zip/16.02/',
filename: 'p7zip_16.02_x86_linux_bin.tar.bz2',
extraname: 'lzma1604.7z',
Expand All @@ -56,7 +68,7 @@ function getDataForPlatform(){
binaryfiles: ['7z','7z.so','7za','7zCon.sfx','7zr','Codecs','Rar.so'],
sfxmodules: ['7zS2.sfx','7zS2con.sfx','7zSD.sfx'] };
// Mac version
case "darwin": return { url: 'https://raw.githubusercontent.com/rudix-mac/packages/master/' + macos + '/',
case "win32": return { url: 'https://raw.githubusercontent.com/rudix-mac/packages/master/' + macos + '/',
filename: 'p7zip-9.20.1-1.pkg',
extraname: '7z920_extra.7z',
extractfolder: '',
Expand All @@ -79,21 +91,3 @@ function wget(path) {
});
});
}

function rmdir(dir) {
var filename, i, item, len, list, stat;
list = fs.readdirSync(dir);
for (i = 0, len = list.length; i < len; i++) {
item = list[i];
filename = path.join(dir, item);
stat = fs.statSync(filename);
if (filename === "." || filename === "..") {

} else if (stat.isDirectory()) {
rmdir(filename);
} else {
fs.unlinkSync(filename);
}
}
return fs.rmdirSync(dir);
}

0 comments on commit e1a8564

Please sign in to comment.