update.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ArgumentParser, Base, Command, add_option_dict, env, iced, log, make_esc, path, path_eq, path_join, rewrite, run, strip, version_info, __iced_k, __iced_k_noop,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. ArgumentParser = require('argparse').ArgumentParser;
  11. add_option_dict = require('./argparse').add_option_dict;
  12. version_info = require('../version').version_info;
  13. run = require('iced-spawn').run;
  14. path = require('path');
  15. env = require('../env').env;
  16. make_esc = require('iced-error').make_esc;
  17. rewrite = function(s) {
  18. return s.replace(/-/g, "_");
  19. };
  20. path_eq = function(a, b) {
  21. var e, i, _i, _len;
  22. if (a.length !== b.length) {
  23. return false;
  24. }
  25. for (i = _i = 0, _len = a.length; _i < _len; i = ++_i) {
  26. e = a[i];
  27. if (e !== b[i]) {
  28. return false;
  29. }
  30. }
  31. return true;
  32. };
  33. path_join = function(arr) {
  34. var res, _ref;
  35. res = path.join.apply(path, arr);
  36. if (((_ref = arr[0]) != null ? _ref.length : void 0) === 0) {
  37. res = path.sep + res;
  38. }
  39. return res;
  40. };
  41. strip = function(s) {
  42. var m;
  43. if ((m = s.match(/(\S+)/))) {
  44. return m[1];
  45. } else {
  46. return s;
  47. }
  48. };
  49. exports.Command = Command = (function(_super) {
  50. __extends(Command, _super);
  51. function Command() {
  52. return Command.__super__.constructor.apply(this, arguments);
  53. }
  54. Command.prototype.OPTS = {
  55. n: {
  56. alias: "npm",
  57. help: "an alternate path for NPM"
  58. },
  59. u: {
  60. alias: "url",
  61. help: "specify a URL prefix for fetching"
  62. },
  63. C: {
  64. alias: "skip-cleanup",
  65. action: "storeTrue",
  66. help: "Don't cleanup temporary stuff after install"
  67. },
  68. c: {
  69. alias: "cmd",
  70. help: "the command to run"
  71. },
  72. p: {
  73. alias: "prefix",
  74. help: "the prefix to install to"
  75. },
  76. g: {
  77. alias: 'global',
  78. help: "install globally; don't try to guess prefix",
  79. action: "storeTrue"
  80. }
  81. };
  82. Command.prototype.add_subcommand_parser = function(scp) {
  83. var name, opts, sub;
  84. opts = {
  85. aliases: [],
  86. help: "update the keybase client software"
  87. };
  88. name = "update";
  89. sub = scp.addParser(name, opts);
  90. add_option_dict(sub, this.OPTS);
  91. return opts.aliases.concat([name]);
  92. };
  93. Command.prototype.run = function(cb) {
  94. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  95. __iced_k = __iced_k_noop;
  96. ___iced_passed_deferral = iced.findDeferral(arguments);
  97. esc = make_esc(cb, "Command::run");
  98. log.debug("+ Command::run");
  99. (function(_this) {
  100. return (function(__iced_k) {
  101. __iced_deferrals = new iced.Deferrals(__iced_k, {
  102. parent: ___iced_passed_deferral,
  103. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  104. funcname: "Command.run"
  105. });
  106. _this.tweak_path(esc(__iced_deferrals.defer({
  107. lineno: 76
  108. })));
  109. __iced_deferrals._fulfill();
  110. });
  111. })(this)((function(_this) {
  112. return function() {
  113. (function(__iced_k) {
  114. __iced_deferrals = new iced.Deferrals(__iced_k, {
  115. parent: ___iced_passed_deferral,
  116. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  117. funcname: "Command.run"
  118. });
  119. _this.probe_npm(esc(__iced_deferrals.defer({
  120. lineno: 77
  121. })));
  122. __iced_deferrals._fulfill();
  123. })(function() {
  124. (function(__iced_k) {
  125. __iced_deferrals = new iced.Deferrals(__iced_k, {
  126. parent: ___iced_passed_deferral,
  127. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  128. funcname: "Command.run"
  129. });
  130. _this.probe_installer(esc(__iced_deferrals.defer({
  131. lineno: 78
  132. })));
  133. __iced_deferrals._fulfill();
  134. })(function() {
  135. (function(__iced_k) {
  136. __iced_deferrals = new iced.Deferrals(__iced_k, {
  137. parent: ___iced_passed_deferral,
  138. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  139. funcname: "Command.run"
  140. });
  141. _this.compute_prefix(esc(__iced_deferrals.defer({
  142. lineno: 79
  143. })));
  144. __iced_deferrals._fulfill();
  145. })(function() {
  146. (function(__iced_k) {
  147. __iced_deferrals = new iced.Deferrals(__iced_k, {
  148. parent: ___iced_passed_deferral,
  149. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  150. funcname: "Command.run"
  151. });
  152. _this.run_install(esc(__iced_deferrals.defer({
  153. lineno: 80
  154. })));
  155. __iced_deferrals._fulfill();
  156. })(function() {
  157. log.debug("- Command::run");
  158. return cb(null);
  159. });
  160. });
  161. });
  162. });
  163. };
  164. })(this));
  165. };
  166. Command.prototype.npm = function(args, cb) {
  167. var err, name, out, p, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  168. __iced_k = __iced_k_noop;
  169. ___iced_passed_deferral = iced.findDeferral(arguments);
  170. name = this.argv.npm || "npm";
  171. if ((p = this.argv.prefix) != null) {
  172. args = ["--prefix", p].concat(args);
  173. }
  174. (function(_this) {
  175. return (function(__iced_k) {
  176. __iced_deferrals = new iced.Deferrals(__iced_k, {
  177. parent: ___iced_passed_deferral,
  178. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  179. funcname: "Command.npm"
  180. });
  181. run({
  182. name: name,
  183. args: args
  184. }, __iced_deferrals.defer({
  185. assign_fn: (function() {
  186. return function() {
  187. err = arguments[0];
  188. return out = arguments[1];
  189. };
  190. })(),
  191. lineno: 90
  192. }));
  193. __iced_deferrals._fulfill();
  194. });
  195. })(this)((function(_this) {
  196. return function() {
  197. return cb(err, out);
  198. };
  199. })(this));
  200. };
  201. Command.prototype.kbi = function(_arg, cb) {
  202. var args, err, name, out, verbose, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  203. __iced_k = __iced_k_noop;
  204. ___iced_passed_deferral = iced.findDeferral(arguments);
  205. args = _arg.args, verbose = _arg.verbose;
  206. name = this.argv.cmd || "keybase-installer";
  207. if (verbose) {
  208. log.info("Running `" + name + " " + (args.join(' ')) + "`");
  209. }
  210. (function(_this) {
  211. return (function(__iced_k) {
  212. __iced_deferrals = new iced.Deferrals(__iced_k, {
  213. parent: ___iced_passed_deferral,
  214. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  215. funcname: "Command.kbi"
  216. });
  217. run({
  218. name: name,
  219. args: args
  220. }, __iced_deferrals.defer({
  221. assign_fn: (function() {
  222. return function() {
  223. err = arguments[0];
  224. return out = arguments[1];
  225. };
  226. })(),
  227. lineno: 98
  228. }));
  229. __iced_deferrals._fulfill();
  230. });
  231. })(this)((function(_this) {
  232. return function() {
  233. return cb(err, out, name);
  234. };
  235. })(this));
  236. };
  237. Command.prototype.probe_installer = function(cb) {
  238. var err, name, vers, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  239. __iced_k = __iced_k_noop;
  240. ___iced_passed_deferral = iced.findDeferral(arguments);
  241. (function(_this) {
  242. return (function(__iced_k) {
  243. __iced_deferrals = new iced.Deferrals(__iced_k, {
  244. parent: ___iced_passed_deferral,
  245. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  246. funcname: "Command.probe_installer"
  247. });
  248. _this.kbi({
  249. args: ["--version"]
  250. }, __iced_deferrals.defer({
  251. assign_fn: (function() {
  252. return function() {
  253. err = arguments[0];
  254. vers = arguments[1];
  255. return name = arguments[2];
  256. };
  257. })(),
  258. lineno: 104
  259. }));
  260. __iced_deferrals._fulfill();
  261. });
  262. })(this)((function(_this) {
  263. return function() {
  264. if (typeof err !== "undefined" && err !== null) {
  265. err = new Error("Can't find `" + name + "` in your path: " + err.message);
  266. } else {
  267. log.info("Found keybase-installer: " + vers);
  268. }
  269. return cb(err);
  270. };
  271. })(this));
  272. };
  273. Command.prototype.probe_npm = function(cb) {
  274. var err, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  275. __iced_k = __iced_k_noop;
  276. ___iced_passed_deferral = iced.findDeferral(arguments);
  277. (function(_this) {
  278. return (function(__iced_k) {
  279. __iced_deferrals = new iced.Deferrals(__iced_k, {
  280. parent: ___iced_passed_deferral,
  281. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  282. funcname: "Command.probe_npm"
  283. });
  284. _this.npm(["config", "get", "prefix"], __iced_deferrals.defer({
  285. assign_fn: (function() {
  286. return function() {
  287. err = arguments[0];
  288. return ret = arguments[1];
  289. };
  290. })(),
  291. lineno: 116
  292. }));
  293. __iced_deferrals._fulfill();
  294. });
  295. })(this)((function(_this) {
  296. return function() {
  297. if (typeof err !== "undefined" && err !== null) {
  298. err = new Error("Can't launch `npm`: " + err.message);
  299. } else {
  300. _this.npm_install_prefix = strip(ret.toString('utf8'));
  301. log.info("Computed npm install prefix: " + _this.npm_install_prefix);
  302. }
  303. return cb(err);
  304. };
  305. })(this));
  306. };
  307. Command.prototype.compute_prefix = function(cb) {
  308. var implicit_path, _ref;
  309. if (this.argv.prefix) {
  310. this.prefix = this.argv.prefix;
  311. } else if (((_ref = process.env.PREFIX) != null ? _ref.length : void 0)) {
  312. } else if ((((implicit_path = this.my_bindir.split(path.sep)).pop() === 'bin') && !(path_eq(this.npm_install_prefix.split(path.sep), implicit_path))) && !this.argv.global) {
  313. this.prefix = path_join(implicit_path);
  314. log.info("Detected custom path '" + this.prefix + "'; preserving it!");
  315. } else {
  316. log.info("Using default npm install prefix");
  317. }
  318. return cb(null);
  319. };
  320. Command.prototype.tweak_path = function(cb) {
  321. this.my_bindir = path.dirname(process.argv[1]);
  322. process.env.path = [this.my_bindir, process.env.path].join(":");
  323. return cb(null);
  324. };
  325. Command.prototype.run_install = function(cb) {
  326. var a, args, err, g, out, v, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref, _ref1;
  327. __iced_k = __iced_k_noop;
  328. ___iced_passed_deferral = iced.findDeferral(arguments);
  329. log.info("Attempting software upgrade.....");
  330. args = [];
  331. if ((g = env().get_gpg_cmd()) != null) {
  332. args.push("-g", g);
  333. }
  334. if (env().get_no_gpg_options()) {
  335. args.push("-O");
  336. }
  337. if (env().get_debug()) {
  338. args.push("-d");
  339. }
  340. if (this.prefix != null) {
  341. args.push("--prefix", this.prefix);
  342. }
  343. _ref = ["npm", "url"];
  344. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  345. a = _ref[_i];
  346. if ((v = this.argv[rewrite(a)]) != null) {
  347. args.push("--" + a, v);
  348. }
  349. }
  350. _ref1 = ["skip-cleanup"];
  351. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  352. a = _ref1[_j];
  353. if ((v = this.argv[rewrite(a)])) {
  354. args.push("--" + a);
  355. }
  356. }
  357. (function(_this) {
  358. return (function(__iced_k) {
  359. __iced_deferrals = new iced.Deferrals(__iced_k, {
  360. parent: ___iced_passed_deferral,
  361. filename: "/Users/max/src/keybase/node-client/src/command/update.iced",
  362. funcname: "Command.run_install"
  363. });
  364. _this.kbi({
  365. args: args,
  366. verbose: true
  367. }, __iced_deferrals.defer({
  368. assign_fn: (function() {
  369. return function() {
  370. err = arguments[0];
  371. return out = arguments[1];
  372. };
  373. })(),
  374. lineno: 169
  375. }));
  376. __iced_deferrals._fulfill();
  377. });
  378. })(this)((function(_this) {
  379. return function() {
  380. return cb(err);
  381. };
  382. })(this));
  383. };
  384. return Command;
  385. })(Base);
  386. }).call(this);