config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. // Generated by IcedCoffeeScript 1.7.1-g
  2. (function() {
  3. var AltKeyRing, Config, a_json_parse, base64u, chain, constants, fs, fullname, home, iced, iutils, keyring, kpath, log, make_esc, mkdir_p, path, prng, request, set_gpg_cmd, tmpdir, url_join, __iced_k, __iced_k_noop, _ref, _ref1, _ref2,
  4. __slice = [].slice;
  5. iced = require('iced-runtime');
  6. __iced_k = __iced_k_noop = function() {};
  7. constants = require('./constants').constants;
  8. fullname = require('./package').fullname;
  9. request = require('./request').request;
  10. log = require('./log');
  11. tmpdir = require('os').tmpdir;
  12. fs = require('fs');
  13. _ref = require('iced-error'), chain = _ref.chain, make_esc = _ref.make_esc;
  14. iutils = require('iced-utils');
  15. _ref1 = iutils.util, a_json_parse = _ref1.a_json_parse, base64u = _ref1.base64u;
  16. mkdir_p = iutils.fs.mkdir_p;
  17. prng = require('crypto').prng;
  18. path = require('path');
  19. _ref2 = require('gpg-wrapper'), set_gpg_cmd = _ref2.set_gpg_cmd, keyring = _ref2.keyring;
  20. AltKeyRing = keyring.AltKeyRing;
  21. kpath = require('keybase-path');
  22. url_join = function() {
  23. var a, args, parts, rxx, trim;
  24. args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  25. rxx = /^(\/*)(.*?)(\/*)$/;
  26. trim = function(s) {
  27. var m;
  28. if ((m = s.match(rxx)) != null) {
  29. return m[2];
  30. } else {
  31. return s;
  32. }
  33. };
  34. parts = (function() {
  35. var _i, _len, _results;
  36. _results = [];
  37. for (_i = 0, _len = args.length; _i < _len; _i++) {
  38. a = args[_i];
  39. _results.push(trim(a));
  40. }
  41. return _results;
  42. })();
  43. return parts.join('/');
  44. };
  45. home = function(opts) {
  46. var x;
  47. x = kpath.home(opts);
  48. return x;
  49. };
  50. exports.Config = Config = (function() {
  51. function Config(argv) {
  52. this.argv = argv;
  53. this._tmpdir = null;
  54. this._alt_cmds = {};
  55. this._keyring_dir = null;
  56. this._actual_prefix = null;
  57. }
  58. Config.prototype.set_actual_prefix = function(p) {
  59. return this._actual_prefix = p;
  60. };
  61. Config.prototype.get_keyring_dir = function() {
  62. var d, v;
  63. if (this._keyring_dir == null) {
  64. if (!((d = this.argv.get("k", "keyring-dir")) != null)) {
  65. v = (home({
  66. array: true
  67. })).concat([".keybase-installer", "keyring"]);
  68. d = kpath.unsplit(v);
  69. }
  70. this._keyring_dir = d;
  71. }
  72. return this._keyring_dir;
  73. };
  74. Config.prototype.init_keyring = function(cb) {
  75. var dir, esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  76. __iced_k = __iced_k_noop;
  77. ___iced_passed_deferral = iced.findDeferral(arguments);
  78. keyring.init({
  79. log: log,
  80. get_tmp_keyring_dir: (function(_this) {
  81. return function() {
  82. return _this.get_tmpdir();
  83. };
  84. })(this),
  85. get_no_options: (function(_this) {
  86. return function() {
  87. return _this.get_no_gpg_options();
  88. };
  89. })(this)
  90. });
  91. dir = this.get_keyring_dir();
  92. esc = make_esc(cb, "Config::init_keyring");
  93. (function(_this) {
  94. return (function(__iced_k) {
  95. __iced_deferrals = new iced.Deferrals(__iced_k, {
  96. parent: ___iced_passed_deferral,
  97. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  98. funcname: "Config.init_keyring"
  99. });
  100. AltKeyRing.make(dir, esc(__iced_deferrals.defer({
  101. assign_fn: (function(__slot_1) {
  102. return function() {
  103. return __slot_1._master_ring = arguments[0];
  104. };
  105. })(_this),
  106. lineno: 66
  107. })));
  108. __iced_deferrals._fulfill();
  109. });
  110. })(this)((function(_this) {
  111. return function() {
  112. (function(__iced_k) {
  113. __iced_deferrals = new iced.Deferrals(__iced_k, {
  114. parent: ___iced_passed_deferral,
  115. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  116. funcname: "Config.init_keyring"
  117. });
  118. _this._master_ring.index(esc(__iced_deferrals.defer({
  119. assign_fn: (function(__slot_1) {
  120. return function() {
  121. return __slot_1._keyring_index = arguments[0];
  122. };
  123. })(_this),
  124. lineno: 67
  125. })));
  126. __iced_deferrals._fulfill();
  127. })(function() {
  128. return cb(null);
  129. });
  130. };
  131. })(this));
  132. };
  133. Config.prototype.keyring_index = function() {
  134. return this._keyring_index;
  135. };
  136. Config.prototype.master_ring = function() {
  137. return this._master_ring;
  138. };
  139. Config.prototype.set_master_ring = function(r, cb) {
  140. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  141. __iced_k = __iced_k_noop;
  142. ___iced_passed_deferral = iced.findDeferral(arguments);
  143. this._master_ring = r;
  144. (function(_this) {
  145. return (function(__iced_k) {
  146. __iced_deferrals = new iced.Deferrals(__iced_k, {
  147. parent: ___iced_passed_deferral,
  148. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  149. funcname: "Config.set_master_ring"
  150. });
  151. _this._master_ring.index(__iced_deferrals.defer({
  152. assign_fn: (function(__slot_1) {
  153. return function() {
  154. err = arguments[0];
  155. return __slot_1._keyring_index = arguments[1];
  156. };
  157. })(_this),
  158. lineno: 79
  159. }));
  160. __iced_deferrals._fulfill();
  161. });
  162. })(this)((function(_this) {
  163. return function() {
  164. return cb(err);
  165. };
  166. })(this));
  167. };
  168. Config.prototype.url_prefix = function() {
  169. var prot, u;
  170. if ((u = this.argv.get("u", "url-prefix"))) {
  171. return u;
  172. } else {
  173. prot = this.argv.get("S", "no-https") ? 'http' : 'https';
  174. return constants.url_prefix[prot];
  175. }
  176. };
  177. Config.prototype.install_prefix = function() {
  178. return process.env.PREFIX || this.argv.get("p", "prefix");
  179. };
  180. Config.prototype.make_url = function(u) {
  181. return url_join(this.url_prefix(), u);
  182. };
  183. Config.prototype.get_tmpdir = function() {
  184. return this._tmpdir;
  185. };
  186. Config.prototype.get_no_gpg_options = function() {
  187. return this.argv.get("O", "no-gpg-options");
  188. };
  189. Config.prototype.make_tmpdir = function(cb) {
  190. var err, p, r, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  191. __iced_k = __iced_k_noop;
  192. ___iced_passed_deferral = iced.findDeferral(arguments);
  193. err = null;
  194. (function(_this) {
  195. return (function(__iced_k) {
  196. if (_this._tmpdir == null) {
  197. r = base64u.encode(prng(16));
  198. p = kpath.split(tmpdir()).concat(["keybase_install_" + r]);
  199. _this._tmpdir = kpath.unsplit(p);
  200. (function(__iced_k) {
  201. __iced_deferrals = new iced.Deferrals(__iced_k, {
  202. parent: ___iced_passed_deferral,
  203. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  204. funcname: "Config.make_tmpdir"
  205. });
  206. fs.mkdir(_this._tmpdir, 0x1c0, __iced_deferrals.defer({
  207. assign_fn: (function() {
  208. return function() {
  209. return err = arguments[0];
  210. };
  211. })(),
  212. lineno: 111
  213. }));
  214. __iced_deferrals._fulfill();
  215. })(function() {
  216. return __iced_k(log.info("Made temporary directory: " + _this._tmpdir));
  217. });
  218. } else {
  219. return __iced_k();
  220. }
  221. });
  222. })(this)((function(_this) {
  223. return function() {
  224. return cb(err);
  225. };
  226. })(this));
  227. };
  228. Config.prototype.cleanup = function(cb) {
  229. var esc, f, files, p, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  230. __iced_k = __iced_k_noop;
  231. ___iced_passed_deferral = iced.findDeferral(arguments);
  232. esc = make_esc(cb, "Installer::cleanup");
  233. log.debug("+ cleanup " + this._tmpdir);
  234. (function(_this) {
  235. return (function(__iced_k) {
  236. if (_this._tmpdir == null) {
  237. return __iced_k();
  238. } else {
  239. (function(__iced_k) {
  240. if (_this.argv.get("C", "skip-cleanup")) {
  241. return __iced_k(log.info("Preserving tmpdir " + _this._tmpdir + " as per command-line switch"));
  242. } else {
  243. log.info("cleaning up tmpdir " + _this._tmpdir);
  244. (function(__iced_k) {
  245. __iced_deferrals = new iced.Deferrals(__iced_k, {
  246. parent: ___iced_passed_deferral,
  247. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  248. funcname: "Config.cleanup"
  249. });
  250. fs.readdir(_this._tmpdir, esc(__iced_deferrals.defer({
  251. assign_fn: (function() {
  252. return function() {
  253. return files = arguments[0];
  254. };
  255. })(),
  256. lineno: 125
  257. })));
  258. __iced_deferrals._fulfill();
  259. })(function() {
  260. (function(__iced_k) {
  261. var _i, _len, _ref3, _results, _while;
  262. _ref3 = files;
  263. _len = _ref3.length;
  264. _i = 0;
  265. _results = [];
  266. _while = function(__iced_k) {
  267. var _break, _continue, _next;
  268. _break = function() {
  269. return __iced_k(_results);
  270. };
  271. _continue = function() {
  272. return iced.trampoline(function() {
  273. ++_i;
  274. return _while(__iced_k);
  275. });
  276. };
  277. _next = function(__iced_next_arg) {
  278. _results.push(__iced_next_arg);
  279. return _continue();
  280. };
  281. if (!(_i < _len)) {
  282. return _break();
  283. } else {
  284. f = _ref3[_i];
  285. p = kpath.join(_this._tmpdir, f);
  286. log.debug("| Unlink " + p);
  287. (function(__iced_k) {
  288. __iced_deferrals = new iced.Deferrals(__iced_k, {
  289. parent: ___iced_passed_deferral,
  290. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  291. funcname: "Config.cleanup"
  292. });
  293. fs.unlink(p, esc(__iced_deferrals.defer({
  294. lineno: 129
  295. })));
  296. __iced_deferrals._fulfill();
  297. })(_next);
  298. }
  299. };
  300. _while(__iced_k);
  301. })(function() {
  302. (function(__iced_k) {
  303. __iced_deferrals = new iced.Deferrals(__iced_k, {
  304. parent: ___iced_passed_deferral,
  305. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  306. funcname: "Config.cleanup"
  307. });
  308. fs.rmdir(_this._tmpdir, esc(__iced_deferrals.defer({
  309. lineno: 130
  310. })));
  311. __iced_deferrals._fulfill();
  312. })(__iced_k);
  313. });
  314. });
  315. }
  316. })(__iced_k);
  317. }
  318. });
  319. })(this)((function(_this) {
  320. return function() {
  321. log.debug("- cleanup " + _this._tmpdir + " -> OK");
  322. return cb(null);
  323. };
  324. })(this));
  325. };
  326. Config.prototype.get_proxy = function() {
  327. return this.argv.get("x", "proxy") || process.env.https_proxy || process.env.http_proxy;
  328. };
  329. Config.prototype.request = function(u, cb) {
  330. var body, err, opts, res, url, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  331. __iced_k = __iced_k_noop;
  332. ___iced_passed_deferral = iced.findDeferral(arguments);
  333. url = u.match("^https?://") ? u : this.make_url(u);
  334. opts = {
  335. url: url,
  336. headers: {
  337. "X-Keybase-Installer": fullname()
  338. },
  339. maxRedirects: 10,
  340. progress: 50000,
  341. proxy: this.get_proxy()
  342. };
  343. log.info("Fetching URL " + url);
  344. (function(_this) {
  345. return (function(__iced_k) {
  346. __iced_deferrals = new iced.Deferrals(__iced_k, {
  347. parent: ___iced_passed_deferral,
  348. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  349. funcname: "Config.request"
  350. });
  351. request(opts, __iced_deferrals.defer({
  352. assign_fn: (function() {
  353. return function() {
  354. err = arguments[0];
  355. res = arguments[1];
  356. return body = arguments[2];
  357. };
  358. })(),
  359. lineno: 150
  360. }));
  361. __iced_deferrals._fulfill();
  362. });
  363. })(this)((function(_this) {
  364. return function() {
  365. log.debug(" * fetched -> " + (typeof res !== "undefined" && res !== null ? res.statusCode : void 0));
  366. return cb(err, res, body);
  367. };
  368. })(this));
  369. };
  370. Config.prototype.set_keys = function(keys) {
  371. if ((this._keys == null) || this._keys.version !== keys.version) {
  372. log.info("Using keyset version v" + keys.version);
  373. return this._keys = keys;
  374. }
  375. };
  376. Config.prototype.set_alt_cmds = function() {
  377. this.set_alt_gpg();
  378. return this.set_alt_npm();
  379. };
  380. Config.prototype.set_alt_gpg = function() {
  381. var c;
  382. if ((c = this.argv.get("g", "gpg")) != null) {
  383. return this._alt_cmds.gpg = c;
  384. } else {
  385. return null;
  386. }
  387. };
  388. Config.prototype.set_alt_npm = function() {
  389. var n;
  390. if ((n = this.argv.get("n", "npm")) != null) {
  391. return this._alt_cmds.npm = n;
  392. }
  393. };
  394. Config.prototype.get_alt_cmd = function(k) {
  395. return this._alt_cmds[k];
  396. };
  397. Config.prototype.get_cmd = function(k) {
  398. return this.get_alt_cmd(k) || k;
  399. };
  400. Config.prototype.key_version = function() {
  401. return this._keys.version;
  402. };
  403. Config.prototype.set_index = function(i) {
  404. return this._index = i;
  405. };
  406. Config.prototype.index = function() {
  407. return this._index;
  408. };
  409. Config.prototype.index_lookup_hash = function(v) {
  410. var _ref3, _ref4;
  411. return (_ref3 = this._index["package"]) != null ? (_ref4 = _ref3.all) != null ? _ref4[v] : void 0 : void 0;
  412. };
  413. Config.prototype.oneshot_verify = function(_arg, cb) {
  414. var err, file, json, query, sig, which, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  415. __iced_k = __iced_k_noop;
  416. ___iced_passed_deferral = iced.findDeferral(arguments);
  417. which = _arg.which, sig = _arg.sig, file = _arg.file;
  418. query = this._keys[which].fingerprint();
  419. (function(_this) {
  420. return (function(__iced_k) {
  421. __iced_deferrals = new iced.Deferrals(__iced_k, {
  422. parent: ___iced_passed_deferral,
  423. filename: "/Users/max/src/keybase/node-installer/src/config.iced",
  424. funcname: "Config.oneshot_verify"
  425. });
  426. _this.master_ring().oneshot_verify({
  427. query: query,
  428. file: file,
  429. sig: sig,
  430. single: true
  431. }, __iced_deferrals.defer({
  432. assign_fn: (function() {
  433. return function() {
  434. err = arguments[0];
  435. return json = arguments[1];
  436. };
  437. })(),
  438. lineno: 203
  439. }));
  440. __iced_deferrals._fulfill();
  441. });
  442. })(this)((function(_this) {
  443. return function() {
  444. return cb(err, json);
  445. };
  446. })(this));
  447. };
  448. return Config;
  449. })();
  450. }).call(this);