Compare commits

..

5 Commits
0.22 ... 0.25

Author SHA1 Message Date
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
3 changed files with 45 additions and 23 deletions

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,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,4 +1,4 @@
import 'colors' import colors from 'colors'
import { program } from 'commander' import { program } from 'commander'
import { setCIMode } from 'clitastic' import { setCIMode } from 'clitastic'
@@ -17,18 +17,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 = '0.25'
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 +60,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,32 +90,46 @@ 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() {
const lock = readLock() try {
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red) const lock = readLock()
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
writeLock({ writeLock({
...lock, ...lock,
running: true, running: true,
}) })
queue()
} catch (e) { if (requireConfig) config = init(configFile)
console.error(e.message) await queue()
} finally { if (error) process.exit(1)
unlock() } catch (e) {
console.error(e.message)
} finally {
unlock()
}
} }
main()