Skip to content

Commit

Permalink
tar archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
bhurlow committed Nov 8, 2015
1 parent cfdc24e commit 44135cb
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
.DS_Store
74 changes: 74 additions & 0 deletions cmd.js
@@ -0,0 +1,74 @@
#! /usr/bin/env node

"use strict";
var fs = require('fs')
var zlib = require('zlib')
var tar = require('tar')
var fstream = require('fstream')
var args = process.argv.slice(2)

function usage() {
console.log('usage:')
console.log('machine-share export <machine-name>')
console.log('machine-share import <machine-name>')
}

if (args.length === 0) {
usage()
process.exit()
}

if (args.length < 2) {
usage()
process.exit()
}

var validCmds = new Set(['export', 'import'])
var cmd = args[0]

if (!validCmds.has(cmd)) {
console.log(args[0] + ' not a command')
}

// TODO:
// should consider the $MACHINE_STORAGE_PATH env var
function doExport() {
let machineName = args[1]
console.log('exporting ' + machineName)
var path = process.env.HOME + '/.docker/machine/machines/' + machineName
console.log('looking in: ' + path)
try {
var dir = fs.readdirSync(path)
}
catch(e) {
console.log('can\'t find that machine :(')
process.exit()
}
createArchive(path)
}

function createArchive(path) {
console.log('creating archive')
var dirDest = fs.createWriteStream('dir.tar')

var packer = tar.Pack({ noProprietary: true })
.on('error', function() { console.log('tar issues') })
.on('end', function() { console.log('archive complete') });

fstream.Reader({ path: path , type: "Directory" })
.on('error', function() { console.log('yoo') })
.pipe(packer)
.pipe(dirDest)

}

function doImport() {

}


switch(cmd) {
case 'export': doExport();
case 'import': doImport();
}

31 changes: 31 additions & 0 deletions package.json
@@ -0,0 +1,31 @@
{
"name": "machine-share",
"version": "0.0.1",
"description": "share docker machines with friendz",
"bin": {
"machine-share": "./cmd.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bhurlow/machine-share.git"
},
"keywords": [
"docker-machine",
"docker",
"export",
"import"
],
"author": "Brian Hurlow",
"license": "MIT",
"bugs": {
"url": "https://github.com/bhurlow/machine-share/issues"
},
"homepage": "https://github.com/bhurlow/machine-share#readme",
"dependencies": {
"fstream": "^1.0.8",
"tar": "^2.2.1"
}
}

0 comments on commit 44135cb

Please sign in to comment.