greenlock-cli.js/bin/greenlock.js

138 lines
4.5 KiB
JavaScript
Raw Permalink Normal View History

2015-12-16 11:01:10 +00:00
#!/usr/bin/env node
'use strict';
var cli = require('cli');
2015-12-16 12:27:23 +00:00
var mkdirp = require('mkdirp');
2015-12-16 11:01:10 +00:00
cli.parse({
2018-05-13 04:55:05 +00:00
'acme-version':
2018-05-13 07:31:44 +00:00
[ false, " v01 (Let's Encrypt v01) or draft-11 (Let's Encrypt v02) (default: draft-11)", 'string'
, 'draft-11' ]
2018-05-13 04:55:05 +00:00
, 'acme-url':
2018-05-13 07:31:44 +00:00
[ false, " ACME API Directory URL (default: https://acme-v02.api.letsencrypt.org/directory", 'string'
, 'https://acme-staging-v02.api.letsencrypt.org/directory' ]
, 'aol-keyword-www':
[ false, " Travel back in time to 1995 where we redirect bare domains as to have a triple-w prefix", 'string'
, false ]
2018-05-13 04:55:05 +00:00
, config:
[ 'c', " Path to configuration file --config /etc/greenlock/greenlock.yml (default: '')", 'string' ]
, serve:
2018-05-13 07:31:44 +00:00
[ false, " Run as webserver (default: false)", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, email:
2018-05-13 07:31:44 +00:00
[ false, " Email used for registration and recovery contact (default: '')", 'email' ]
2018-05-13 04:55:05 +00:00
, analytics:
2018-05-13 07:31:44 +00:00
[ false, " Share analytics with greenlock (default: false)", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, community:
2018-05-13 07:31:44 +00:00
[ false, " Join the greenlock community to get important updates (default: false)", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, 'agree-tos':
2018-05-13 07:31:44 +00:00
[ false, " Agree to the Let's Encrypt Subscriber Agreement", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, domains:
[ false, " Comma-separated list of domains to secure (default: [])", 'string' ]
, 'config-dir':
2018-05-13 07:31:44 +00:00
[ false, " Configuration directory.", 'string'
, '~/acme/etc/' ]
2018-05-13 04:55:05 +00:00
, 'cert-path':
2018-05-13 07:31:44 +00:00
[ false, " Path where new cert.pem is saved", 'string'
, ':configDir/live/:hostname/cert.pem' ]
2018-05-13 04:55:05 +00:00
, 'fullchain-path':
2018-05-13 07:31:44 +00:00
[ false, " Path where new fullchain.pem (cert + chain) is saved", 'string'
, ':configDir/live/:hostname/fullchain.pem' ]
2018-05-13 04:55:05 +00:00
, 'chain-path':
2018-05-13 07:31:44 +00:00
[ false, " Path where new chain.pem is saved", 'string'
, ':configDir/live/:hostname/chain.pem' ]
2018-05-13 04:55:05 +00:00
, 'bundle-path':
2018-05-13 07:31:44 +00:00
[ false, " Path where new bundle.pem (fullchain + privkey) is saved", 'string'
, ':configDir/live/:hostname/bundle.pem' ]
2018-05-13 04:55:05 +00:00
, 'privkey-path':
2018-05-13 07:31:44 +00:00
[ false, " Path where (new or existing) domain privkey.pem is saved", 'string'
, ':configDir/live/:hostname/privkey.pem' ]
, 'webroot':
[ false, " public_html / webroot path such as /srv/www/:hostname", 'string' ]
2018-05-13 04:55:05 +00:00
, 'renew-within':
2018-05-13 07:31:44 +00:00
[ false, " Renew certificates this many days before expiry", 'int'
, 11 ]
, staging:
[ false, " Use Let's Encrypt v02 staging API", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, standalone:
2018-05-13 07:31:44 +00:00
[ false, " Obtain certs using a \"standalone\" webserver", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, manual:
2018-05-13 07:31:44 +00:00
[ false, " Print the token and key to the screen and wait for you to hit enter, giving you time to copy it somewhere before continuing (default: false)", 'boolean'
, false ]
2018-05-13 04:55:05 +00:00
, debug:
2018-05-13 07:31:44 +00:00
[ false, " show traces and logs", 'boolean'
, false ]
2015-12-16 11:01:10 +00:00
});
2015-12-16 11:43:30 +00:00
// ignore certonly and extraneous arguments
cli.main(function(_, options) {
2015-12-17 09:16:43 +00:00
console.log('');
2015-12-16 11:43:30 +00:00
var args = {};
2018-05-13 07:31:44 +00:00
var homedir = require('os').homedir();
2015-12-16 11:43:30 +00:00
Object.keys(options).forEach(function (key) {
var val = options[key];
if ('string' === typeof val) {
val = val.replace(/^~/, homedir);
}
key = key.replace(/\-([a-z0-9A-Z])/g, function (c) { return c[1].toUpperCase(); });
args[key] = val;
});
Object.keys(args).forEach(function (key) {
var val = args[key];
if ('string' === typeof val) {
2016-08-10 02:39:39 +00:00
val = val.replace(/(\:configDir)|(\:config)/, args.configDir);
2015-12-16 11:43:30 +00:00
}
args[key] = val;
});
2015-12-16 12:27:23 +00:00
if (args.domains) {
args.domains = args.domains.split(',');
2015-12-16 11:43:30 +00:00
}
2015-12-16 12:27:23 +00:00
2015-12-17 09:14:33 +00:00
if (!(Array.isArray(args.domains) && args.domains.length) || !args.email || !args.agreeTos) {
2017-01-25 21:42:01 +00:00
console.error("\nUsage: greenlock certonly --standalone --domains example.com --email user@example.com --agree-tos");
console.error("\nSee greenlock --help for more details\n");
2015-12-17 09:14:33 +00:00
return;
}
2015-12-16 12:27:23 +00:00
if (args.tlsSni01Port) {
// [@agnat]: Coerce to string. cli returns a number although we request a string.
args.tlsSni01Port = "" + args.tlsSni01Port;
2015-12-16 12:27:23 +00:00
args.tlsSni01Port = args.tlsSni01Port.split(',').map(function (port) {
return parseInt(port, 10);
});
}
if (args.http01Port) {
// [@agnat]: Coerce to string. cli returns a number although we request a string.
args.http01Port = "" + args.http01Port;
2015-12-16 12:27:23 +00:00
args.http01Port = args.http01Port.split(',').map(function (port) {
return parseInt(port, 10);
});
2015-12-16 11:43:30 +00:00
}
2015-12-16 12:27:23 +00:00
mkdirp(args.configDir, function (err) {
2015-12-16 11:43:30 +00:00
if (err) {
2015-12-16 12:27:23 +00:00
console.error("Could not create --config-dir '" + args.configDir + "':", err.code);
console.error("Try setting --config-dir '/tmp'");
2015-12-16 11:43:30 +00:00
return;
}
require('../').run(args).then(function (status) {
process.exit(status);
});
2015-12-16 11:43:30 +00:00
});
2015-12-16 11:01:10 +00:00
});