Created
April 2, 2014 07:48
-
-
Save ksimuk/9929674 to your computer and use it in GitHub Desktop.
dropbox init script for boxparts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var DROPBOX_INIT = '/home/codio/.dropbox-dist/dropboxd' | |
var DROPBOX_EXCLUDE = 'dropbox.py' | |
var cp = require('child_process'); | |
var fs = require('fs'); | |
function dropBoxInit() { | |
var childInit = cp.spawn(DROPBOX_INIT, []); | |
childInit.stdout.on('data', function (data) { | |
data = '' + data; | |
if ((data).indexOf('This computer is now linked to Dropbox') !== -1) { | |
addExlude(function(){ | |
childInit.kill('SIGKILL'); | |
}) | |
} | |
console.log(data); | |
}); | |
childInit.stderr.on('data', function (data) { | |
console.err(data); | |
}); | |
} | |
function addExlude(callback) { | |
console.log('Trying to exclude folders, please wait...') | |
setTimeout( function() { // delay to get list of files | |
var path = '/home/codio/Dropbox/'; | |
var files = fs.readdirSync(path); | |
var params = ['exclude', 'add']; | |
for (var i = 0; i < files.length; ++i) { | |
params.push(path + files[i]); | |
} | |
var childExclude = cp.spawn(DROPBOX_EXCLUDE, params); | |
childExclude.on('close', function(){ | |
callback(); | |
}); | |
}, 5000); | |
} | |
dropBoxInit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment