Compare commits

..

7 Commits
0.22 ... 0.26

Author SHA1 Message Date
fde4edc05f use version from package, stricter compiler 2020-11-29 15:37:39 +01:00
7e6cc7bb32 lock only if config required 2020-11-29 15:27:32 +01:00
878a7bd752 disable colors in ci mode 2020-11-16 17:30:32 +01:00
f6860115a3 remove ununsed log 2020-11-14 00:40:16 +01:00
f43e73ce41 process end in exit 2020-11-14 00:33:52 +01:00
6b4277b57b changelog 2020-11-13 21:47:33 +01:00
d4b8a7223f don't require config for update 2020-11-13 16:27:19 +01:00
7 changed files with 77 additions and 47 deletions

1
.gitignore vendored
View File

@@ -13,6 +13,7 @@ restore
docker docker
Dockerfile Dockerfile
build build
dist
# Config # Config
.autorestic.yml .autorestic.yml

View File

@@ -1,3 +1,3 @@
## 0.22 ## 0.25
- New CI Flag for clean ci output - disable color in CI mode

View File

@@ -1,10 +1,11 @@
{ {
"private": true, "private": true,
"version": "0.26",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"dev": "tsc -w", "dev": "tsc -w",
"move": "mv bin/index-linux bin/autorestic_linux_x64 && mv bin/index-macos bin/autorestic_macos_x64", "move": "mv bin/index-linux bin/autorestic_linux_x64 && mv bin/index-macos bin/autorestic_macos_x64",
"bin": "yarn run build && pkg lib/index.js --targets latest-macos-x64,latest-linux-x64 --out-path bin && yarn run move", "bin": "yarn run build && pkg dist/src/index.js --targets latest-macos-x64,latest-linux-x64 --out-path bin && yarn run move",
"docs:build": "codedoc install && codedoc build", "docs:build": "codedoc install && codedoc build",
"docs:dev": "codedoc serve" "docs:dev": "codedoc serve"
}, },

View File

@@ -1,7 +1,7 @@
import { Writer } from 'clitastic' import { Writer } from 'clitastic'
import { mkdirSync } from 'fs' import { mkdirSync } from 'fs'
import { config, VERBOSE } from './' import { config, hasError, VERBOSE } from './'
import { getEnvFromBackend } from './backend' import { getEnvFromBackend } from './backend'
import { LocationFromPrefixes } from './config' import { LocationFromPrefixes } from './config'
import { Locations, Location, Backend } from './types' import { Locations, Location, Backend } from './types'
@@ -68,6 +68,7 @@ export const backupSingle = (name: string, to: string, location: Location) => {
writer.done(`${name}${to.blue} : ${'Done ✓'.green} (${delta.finished(true)})`) writer.done(`${name}${to.blue} : ${'Done ✓'.green} (${delta.finished(true)})`)
} catch (e) { } catch (e) {
hasError()
writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`) writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`)
} }
} }

View File

@@ -1,10 +1,11 @@
import 'colors' import colors from 'colors'
import { program } from 'commander' import { program } from 'commander'
import { setCIMode } from 'clitastic' import { setCIMode } from 'clitastic'
import { unlock, readLock, writeLock } from './lock' import { unlock, readLock, writeLock } from './lock'
import { Config } from './types' import { Config } from './types'
import { init } from './config' import { init } from './config'
import { version } from '../package.json'
import info from './handlers/info' import info from './handlers/info'
import check from './handlers/check' import check from './handlers/check'
@@ -17,18 +18,25 @@ import install from './handlers/install'
import { uninstall } from './handlers/uninstall' import { uninstall } from './handlers/uninstall'
import { upgrade } from './handlers/upgrade' import { upgrade } from './handlers/upgrade'
export const VERSION = '0.22' export const VERSION = version
export const INSTALL_DIR = '/usr/local/bin' export const INSTALL_DIR = '/usr/local/bin'
let requireConfig: boolean = true
let error: boolean = false
export function hasError() {
error = true
}
process.on('uncaughtException', (err) => { process.on('uncaughtException', (err) => {
console.log(err.message) console.log(err.message)
unlock() unlock()
process.exit(1) process.exit(1)
}) })
let queue: Function = () => {} let queue: () => Promise<void> = async () => {}
const enqueue = (fn: Function) => (cmd: any) => { const enqueue = (fn: Function) => (cmd: any) => {
queue = () => fn(cmd.opts()) queue = async () => fn(cmd.opts())
} }
program.storeOptionsAsProperties() program.storeOptionsAsProperties()
@@ -53,7 +61,7 @@ program
.option('-a, --all') .option('-a, --all')
.action(enqueue(check)) .action(enqueue(check))
program.command('backup').description('Performs a backup').option('-b, --backend <backends...>').option('-a, --all').action(enqueue(backup)) program.command('backup').description('Performs a backup').option('-l, --location <locations...>').option('-a, --all').action(enqueue(backup))
program program
.command('restore') .command('restore')
@@ -83,22 +91,33 @@ program
.option('-b, --backend <backends...>') .option('-b, --backend <backends...>')
.option('-a, --all') .option('-a, --all')
.action(({ args, all, backend }) => { .action(({ args, all, backend }) => {
queue = () => exec({ all, backend }, args) queue = async () => exec({ all, backend }, args)
}) })
program.command('install').description('Installs both restic and autorestic to /usr/local/bin').action(enqueue(install)) program.command('install').description('Installs both restic and autorestic to /usr/local/bin').action(enqueue(install))
program.command('uninstall').description('Uninstalls autorestic from the system').action(enqueue(uninstall)) program.command('uninstall').description('Uninstalls autorestic from the system').action(enqueue(uninstall))
program.command('upgrade').alias('update').description('Checks and installs new autorestic versions').action(enqueue(upgrade)) program
.command('upgrade')
.alias('update')
.description('Checks and installs new autorestic versions')
.action(() => {
requireConfig = false
queue = upgrade
})
const { verbose, config: configFile, ci } = program.parse(process.argv) const { verbose, config: configFile, ci } = program.parse(process.argv)
export const VERBOSE = verbose export const VERBOSE = verbose
export let config: Config = init(configFile) export let config: Config
setCIMode(ci) setCIMode(ci)
if (ci) colors.disable()
try { async function main() {
try {
if (requireConfig) {
config = init(configFile)
const lock = readLock() const lock = readLock()
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red) if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
@@ -106,9 +125,14 @@ try {
...lock, ...lock,
running: true, running: true,
}) })
queue() }
} catch (e) {
await queue()
if (error) process.exit(1)
} catch (e) {
console.error(e.message) console.error(e.message)
} finally { } finally {
unlock() if (requireConfig) unlock()
}
} }
main()

View File

@@ -1,10 +1,13 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "es2019",
"module": "commonjs", "module": "commonjs",
"outDir": "./lib", "outDir": "./dist",
"rootDir": "./src",
"strict": true, "strict": true,
"esModuleInterop": true "esModuleInterop": true,
} "resolveJsonModule": true,
"alwaysStrict": true,
"strictNullChecks": true
},
"include": ["./src", "./package.json"]
} }

View File

@@ -3,9 +3,9 @@
"@babel/parser@^7.9.4": "@babel/parser@^7.9.4":
version "7.12.5" version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.5.tgz#b4af32ddd473c0bfa643bd7ff0728b8e71b81ea0" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.7.tgz#fee7b39fe809d0e73e5b25eecaf5780ef3d73056"
integrity sha512-FVM6RZQ0mn2KCf1VUED7KepYeUWoVShczewOCfm3nzoBybaih51h+sYVVGthW9M6lPByEPTQf+xm27PBdlpwmQ== integrity sha512-oWR02Ubp4xTLCAqPRiNIuMVgNO5Aif/xpXtabhzW2HWUD47XJsAB4Zd/Rg30+XeQA3juXigV7hlquOTmwqLiwg==
"@babel/runtime@^7.9.2": "@babel/runtime@^7.9.2":
version "7.12.5" version "7.12.5"
@@ -52,9 +52,9 @@
integrity sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww== integrity sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==
"@types/node@^14": "@types/node@^14":
version "14.14.7" version "14.14.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.7.tgz#8ea1e8f8eae2430cf440564b98c6dfce1ec5945d" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.10.tgz#5958a82e41863cfc71f2307b3748e3491ba03785"
integrity sha512-Zw1vhUSQZYw+7u5dAwNbIA9TuTotpzY/OF7sJM9FqPOF3SPjKnxrjoTktXDZgUjybf4cWVBP7O8wvKdSaGHweg== integrity sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==
"@types/strip-bom@^3.0.0": "@types/strip-bom@^3.0.0":
version "3.0.0" version "3.0.0"
@@ -283,9 +283,9 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
cron-parser@2.x.x: cron-parser@2.x.x:
version "2.17.0" version "2.18.0"
resolved "https://registry.yarnpkg.com/cron-parser/-/cron-parser-2.17.0.tgz#5707421a7e0a73ee74675d1c032a2f14123f2cf8" resolved "https://registry.yarnpkg.com/cron-parser/-/cron-parser-2.18.0.tgz#de1bb0ad528c815548371993f81a54e5a089edcf"
integrity sha512-oTmzVEwlurRe51HqTm4afshVr8Rkxy9kFiWxh5e6SmrY2o9NDYU4S6SduanBZYXLgkLy0skA98y7/tztW/DmjQ== integrity sha512-s4odpheTyydAbTBQepsqd2rNWGa2iV3cyo8g7zbI2QQYGLVsfbhmwukayS1XHppe02Oy1fg7mg6xoaraVJeEcg==
dependencies: dependencies:
is-nan "^1.3.0" is-nan "^1.3.0"
moment-timezone "^0.5.31" moment-timezone "^0.5.31"
@@ -662,9 +662,9 @@ is-binary-path@~2.1.0:
binary-extensions "^2.0.0" binary-extensions "^2.0.0"
is-core-module@^2.1.0: is-core-module@^2.1.0:
version "2.1.0" version "2.2.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.1.0.tgz#a4cc031d9b1aca63eecbd18a650e13cb4eeab946" resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
integrity sha512-YcV7BgVMRFRua2FqQzKtTDMz8iCuLEyGKjr70q8Zm1yy2qKcurbFEd79PAdHV77oL3NrAaOVQIbMmiHQCHB7ZA== integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
dependencies: dependencies:
has "^1.0.3" has "^1.0.3"
@@ -865,9 +865,9 @@ mkdirp@^1.0.4:
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
moment-timezone@^0.5.31: moment-timezone@^0.5.31:
version "0.5.31" version "0.5.32"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.31.tgz#9c40d8c5026f0c7ab46eda3d63e49c155148de05" resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.32.tgz#db7677cc3cc680fd30303ebd90b0da1ca0dfecc2"
integrity sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA== integrity sha512-Z8QNyuQHQAmWucp8Knmgei8YNo28aLjJq6Ma+jy1ZSpSk5nyfRT8xgUbSQvD2+2UajISfenndwvFuH3NGS+nvA==
dependencies: dependencies:
moment ">= 2.9.0" moment ">= 2.9.0"
@@ -1280,9 +1280,9 @@ spdx-expression-parse@^3.0.0:
spdx-license-ids "^3.0.0" spdx-license-ids "^3.0.0"
spdx-license-ids@^3.0.0: spdx-license-ids@^3.0.0:
version "3.0.6" version "3.0.7"
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.6.tgz#c80757383c28abf7296744998cbc106ae8b854ce" resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.7.tgz#e9c18a410e5ed7e12442a549fbd8afa767038d65"
integrity sha512-+orQK83kyMva3WyPf59k1+Y525csj5JejicWut55zeTWANuN17qSiSLUXWtzHeNWORSvT7GLDJ/E/XiIWoXBTw== integrity sha512-U+MTEOO0AiDzxwFvoa4JVnMV6mZlJKk2sBLt90s7G0Gd0Mlknc7kxEn3nuDPNZRta7O2uy8oLcZLVT+4sqNZHQ==
sprintf-js@~1.0.2: sprintf-js@~1.0.2:
version "1.0.3" version "1.0.3"