Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macOS Chromium Marmaduke build updater
// To use this simply install NodeJS (https://nodejs.org/)
// Then run node chromiumUpdater.js.
// You might want to put it in your crontab.
// Set to true for ASi builds
// Set to false for Intel builds
const APPLE_SILLICON = false
// Ignore No-Sync builds?
const SYNC_ONLY = true
// Show notifications
// brew install terminal-notifier
const NOTIFICATIONS = true
const https = require("https")
const fs = require("fs")
// easier to do this with a node_module such as the excellent node-fetch
// but i want this to be one file
function makeRequest(options,cb) {
var req = https.request(options, (res) => {
var data = ""
res.on('data', (d) => {
data += d.toString()
});
res.on('end', () => {
res.data = data
cb(undefined,res)
});
});
req.on('error', (e) => {
cb(e)
});
req.end();
}
function showNotif(description,subtitle,group) {
subtitle = subtitle || ""
console.error(subtitle,description)
if (fs.existsSync("/usr/local/bin/terminal-notifier") && NOTIFICATIONS) {
require("child_process").spawn("/usr/local/bin/terminal-notifier",["-title","Chromium Updater","-appIcon","/Applications/Chromium.app/Contents/Resources/app.icns","-subtitle",JSON.stringify(subtitle),"-message",JSON.stringify(description),"-sender","'org.chromium.Chromium'","-activate","'org.chromium.Chromium'","-ignoreDnD","-group",JSON.stringify(group || 'chromiumUpdate')])
}
}
showNotif("Checking for updates")
makeRequest({
//https://api.github.com/repos/macchrome/chromium/releases
hostname: "api.github.com", port: 443,
method: "GET", path: "/repos/macchrome/macstable/releases",
headers: {'User-Agent': "chromiumUpdater/1.0 pure-node-js-http-library/" + process.version}
}, (err,res) => {
if (res.statusCode > 299 || res.statusCode < 200) return showNotif("Server returned a status of " + res.statusCode,"Error")
var j = JSON.parse(res.data)
var files = []
for (var release of j) files.push(...release.assets)
console.log("\nFound files",files.map((f) => f.name).join(", "))
// Mac builds only
files = files.filter((f) => f.name.endsWith(".app.zip"))
// ASi builds
files = files.filter((f) => (f.name.includes("_arm64") && APPLE_SILLICON) || (!f.name.includes("_arm64") && !APPLE_SILLICON))
// Sync only
if (SYNC_ONLY) files = files.filter((f) => f.name.includes(".sync"))
if (!files[0]) return showNotif("No eligible builds found","Error")
console.log("\nEligible builds are",files.map((f) => f.name).join(", "), ".\nSince",files[0].name,"is the latest, we'll use that.\n")
var latestSplit = files[0].name.split(".")
var latestMajor = parseInt(latestSplit[1])
var latestMinor = parseInt(latestSplit[3])
if (fs.existsSync("/Applications/Chromium.app/Contents/Info.plist")) {
var localplist = fs.readFileSync("/Applications/Chromium.app/Contents/Info.plist").toString()
var localVersion = localplist.split(`<key>CFBundleShortVersionString</key>\n\t<string>`)[1].split("</string>")[0]
var localSplit = localVersion.split(".")
var localMajor = parseInt(localSplit[0])
var localMinor = parseInt(localSplit[2])
console.log("The currently installed version is",localVersion)
if (
// major downgrade protection
localMajor > latestMajor ||
(localMajor == latestMajor && localMinor >= latestMinor)
) {
return showNotif(localMajor+"." + localMinor + " >= " + latestMajor + "." + latestMinor,"Already up to date! 😃👍")
}
}
showNotif(localMajor+"." + localMinor + " -> " + latestMajor + "." + latestMinor,"Updating!")
fs.rmSync("/Applications/Chromium.app",{recursive:true,force:true})
require("child_process").execSync("curl -L " + JSON.stringify(files[0].browser_download_url) + " > /tmp/chromUpdate.zip && unzip /tmp/chromUpdate.zip -d /Applications")
return showNotif(localMajor+"." + localMinor + " -> " + latestMajor + "." + latestMinor,"Succesfully updated 😃👍!","chromium_update_"+latestMajor+latestMinor)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment