check for mahor version for updates

This commit is contained in:
cupcakearmy 2021-04-15 00:57:15 +02:00
parent 805bed7db1
commit 190eca6f6e
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 22 additions and 13 deletions

View File

@ -17,12 +17,14 @@
"typescript": "^3.9"
},
"dependencies": {
"@types/semver": "^7.3.4",
"axios": "^0.19",
"clitastic": "^0.1.2",
"colors": "^1",
"commander": "^6.2",
"cron-parser": "2.x.x",
"js-yaml": "3.x.x",
"semver": "^7.3.5",
"uhrwerk": "1.x.x"
}
}

View File

@ -2,6 +2,7 @@ import { chmodSync } from 'fs'
import axios from 'axios'
import { Writer } from 'clitastic'
import semver from 'semver'
import { INSTALL_DIR, VERSION } from '..'
import { checkIfResticIsAvailable, downloadFile, exec } from '../utils'
@ -18,19 +19,25 @@ export async function upgrade() {
responseType: 'json',
})
if (json.tag_name != VERSION) {
const platformMap: { [key: string]: string } = {
darwin: 'macos',
const latest = semver.coerce(json.tag_name)
const current = semver.coerce(VERSION)
if (!latest || !current) throw new Error('Could not parse versions numbers.')
if (semver.gt(latest, current) && semver.major(latest) === semver.major(current)) {
// Update to compatible
if (json.tag_name != VERSION) {
const platformMap: { [key: string]: string } = {
darwin: 'macos',
}
const name = `autorestic_${platformMap[process.platform] || process.platform}_${process.arch}`
const dl = json.assets.find((asset: any) => asset.name === name)
const to = INSTALL_DIR + '/autorestic'
w.replaceLn('Downloading binary... 🌎')
await downloadFile(dl.browser_download_url, to)
chmodSync(to, 0o755)
}
const name = `autorestic_${platformMap[process.platform] || process.platform}_${process.arch}`
const dl = json.assets.find((asset: any) => asset.name === name)
const to = INSTALL_DIR + '/autorestic'
w.replaceLn('Downloading binary... 🌎')
await downloadFile(dl.browser_download_url, to)
chmodSync(to, 0o755)
}
w.done('All up to date! 🚀')

View File

@ -17,7 +17,7 @@ import install from './handlers/install'
import { uninstall } from './handlers/uninstall'
import { upgrade } from './handlers/upgrade'
export const VERSION = '0.27'
export const VERSION = '0.28'
export const INSTALL_DIR = '/usr/local/bin'
let requireConfig: boolean = true