greenlock-cli.js/bin/greenlock.js

138 lines
4.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict';
var cli = require('cli');
var mkdirp = require('mkdirp');
cli.parse({
'acme-version':
[ false, " v01 (Let's Encrypt v01) or draft-11 (Let's Encrypt v02) (default: draft-11)", 'string'
, 'draft-11' ]
, 'acme-url':
[ 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 ]
, config:
[ 'c', " Path to configuration file --config /etc/greenlock/greenlock.yml (default: '')", 'string' ]
, serve:
[ false, " Run as webserver (default: false)", 'boolean'
, false ]
, email:
[ false, " Email used for registration and recovery contact (default: '')", 'email' ]
, analytics:
[ false, " Share analytics with greenlock (default: false)", 'boolean'
, false ]
, community:
[ false, " Join the greenlock community to get important updates (default: false)", 'boolean'
, false ]
, 'agree-tos':
[ false, " Agree to the Let's Encrypt Subscriber Agreement", 'boolean'
, false ]
, domains:
[ false, " Comma-separated list of domains to secure (default: [])", 'string' ]
, 'config-dir':
[ false, " Configuration directory.", 'string'
, '~/acme/etc/' ]
, 'cert-path':
[ false, " Path where new cert.pem is saved", 'string'
, ':configDir/live/:hostname/cert.pem' ]
, 'fullchain-path':
[ false, " Path where new fullchain.pem (cert + chain) is saved", 'string'
, ':configDir/live/:hostname/fullchain.pem' ]
, 'chain-path':
[ false, " Path where new chain.pem is saved", 'string'
, ':configDir/live/:hostname/chain.pem' ]
, 'bundle-path':
[ false, " Path where new bundle.pem (fullchain + privkey) is saved", 'string'
, ':configDir/live/:hostname/bundle.pem' ]
, 'privkey-path':
[ 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' ]
, 'renew-within':
[ false, " Renew certificates this many days before expiry", 'int'
, 11 ]
, staging:
[ false, " Use Let's Encrypt v02 staging API", 'boolean'
, false ]
, standalone:
[ false, " Obtain certs using a \"standalone\" webserver", 'boolean'
, false ]
, manual:
[ 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 ]
, debug:
[ false, " show traces and logs", 'boolean'
, false ]
});
// ignore certonly and extraneous arguments
cli.main(function(_, options) {
console.log('');
var args = {};
var homedir = require('os').homedir();
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) {
val = val.replace(/(\:configDir)|(\:config)/, args.configDir);
}
args[key] = val;
});
if (args.domains) {
args.domains = args.domains.split(',');
}
if (!(Array.isArray(args.domains) && args.domains.length) || !args.email || !args.agreeTos) {
console.error("\nUsage: greenlock certonly --standalone --domains example.com --email user@example.com --agree-tos");
console.error("\nSee greenlock --help for more details\n");
return;
}
if (args.tlsSni01Port) {
// [@agnat]: Coerce to string. cli returns a number although we request a string.
args.tlsSni01Port = "" + args.tlsSni01Port;
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;
args.http01Port = args.http01Port.split(',').map(function (port) {
return parseInt(port, 10);
});
}
mkdirp(args.configDir, function (err) {
if (err) {
console.error("Could not create --config-dir '" + args.configDir + "':", err.code);
console.error("Try setting --config-dir '/tmp'");
return;
}
require('../').run(args).then(function (status) {
process.exit(status);
});
});
});