-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.js
executable file
·54 lines (49 loc) · 1.55 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
var fs = require('fs');
var homedir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
var profile=homedir+"/.bash_profile";
var profile_update='./etc/bash_profile';
var installer='./etc/profile_update';
var markdir = homedir+"/.gotomark";
fs.mkdir(markdir, function(e){
copyFile(installer, markdir+"/profile.sh", function(){
fs.readFile(profile_update, {encoding: 'utf8'}, function(err, data){
fs.createWriteStream(profile, {'flags': 'a'}).write(data, 'utf8', function(err, data){
fs.chownSync(markdir, +(process.env.SUDO_UID), +(process.env.SUDO_GID));
fs.chownSync(markdir+"/profile.sh", +(process.env.SUDO_UID), +(process.env.SUDO_GID));
fs.exists(homedir+"/.marked_destinations", function(exists){
if(exists){
fs.rename(homedir+"/.marked_destinations", markdir+"/marked_destinations");
}
});
if(err) throw(err);
console.log("\n#######################################\n#");
console.log("# Installation Success, I presume\n#");
console.log("# Now Run this command:");
console.log("# \tsource ~/.bash_profile");
console.log("#\n#######################################\n");
});
});
});
});
function copyFile(source, target, cb) {
var cbCalled = false;
var rd = fs.createReadStream(source);
rd.on("error", function(err) {
done(err);
});
var wr = fs.createWriteStream(target);
wr.on("error", function(err) {
done(err);
});
wr.on("close", function(ex) {
done();
});
rd.pipe(wr);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
}