This skript downloads and installs the most recent version of Hyper using last DEP package for linux.
git clone https://gist.github.com/mojoaxel/4fa8947905472818a72a97c113b535ae update-hyper
cd update-hyper
npm install
npm run update
This skript downloads and installs the most recent version of Hyper using last DEP package for linux.
git clone https://gist.github.com/mojoaxel/4fa8947905472818a72a97c113b535ae update-hyper
cd update-hyper
npm install
npm run update
{ | |
"name": "hyper-updater", | |
"version": "1.0.1", | |
"description": "node.js script to install the latest version of zeit/hyper using the debian package", | |
"main": "update.js", | |
"scripts": { | |
"update": "node update.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Alexander Wunschik <[email protected]>", | |
"license": "GPL-3.0", | |
"dependencies": { | |
"download": "^6.2.5", | |
"github": "^11.0.0", | |
"prettyjson": "^1.2.1", | |
"progress": "^2.0.0", | |
"rimraf": "^2.6.2", | |
"sudo": "^1.0.3", | |
"temp-dir": "^1.0.0", | |
"underscore": "^1.8.3" | |
} | |
} |
const GitHubApi = require("github"); | |
const prettyjson = require('prettyjson'); | |
const _ = require('underscore'); | |
const download = require('download'); | |
const ProgressBar = require('progress'); | |
const tempDir = require('temp-dir'); | |
const path = require('path'); | |
var sudo = require('sudo'); | |
var rimfaf = require('rimraf'); | |
var github = new GitHubApi(); | |
const MAX_VERSION_INDEX = 10; | |
github.repos.getReleases({ | |
owner: 'zeit', | |
repo: 'hyper', | |
page: 1, | |
per_page: MAX_VERSION_INDEX | |
}, function(err, res) { | |
let packageIndex = 0; | |
let packageFound = false; | |
while (!packageFound && packageIndex <= res.data.length && packageIndex <= MAX_VERSION_INDEX) { | |
var debianAsset = _.find(res.data[packageIndex].assets, (asset) => { | |
return asset && asset.browser_download_url && asset.browser_download_url.endsWith('.deb'); | |
}); | |
packageFound = !!debianAsset; | |
packageIndex++; | |
} | |
if (!packageFound) { | |
console.error(`No debian package found for the last ${MAX_VERSION_INDEX} versions.`); | |
process.exit() | |
} | |
var filePath = path.join(tempDir, debianAsset.name); | |
console.log(`Downloading ${filePath}`); | |
const bar = new ProgressBar('[:bar] :percent :etas', { | |
complete: '=', | |
incomplete: ' ', | |
width: 40, | |
total: 0 | |
}); | |
download(debianAsset.browser_download_url, tempDir) | |
.on('response', res => { | |
bar.total = res.headers['content-length']; | |
res.on('data', data => bar.tick(data.length)); | |
}) | |
.then(() => { | |
console.log('Downloaded finished!'); | |
var options = { | |
cachePassword: true, | |
prompt: '*** sudo Password: ' | |
}; | |
console.log("Starting installation..."); | |
var child = sudo([ 'dpkg', '-i', filePath ], options); | |
child.stdout.on('end', function (data) { | |
console.log("Installed finished"); | |
rimfaf(filePath, () => { | |
console.log("removed tmp file"); | |
}); | |
}); | |
}) | |
.catch((e) => { | |
console.error("Error downloading file: ", e); | |
}); | |
}); |