Enable strict mode and explicitly declare all used variables.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
import { access, basename, dirname, mkstemp, open, writefile } from 'fs';
function assert(cond, message) {
import { access, basename, dirname, mkstemp, open, writefile } from 'fs';
function assert(cond, message) {
+let unet_tool = "unet-tool";
let script_dir = sourcepath(0, true);
let script_dir = sourcepath(0, true);
if (basename(script_dir) == "scripts") {
unet_tool = `${dirname(script_dir)}/unet-tool`;
assert(access(unet_tool, "x"), "unet-tool missing");
if (basename(script_dir) == "scripts") {
unet_tool = `${dirname(script_dir)}/unet-tool`;
assert(access(unet_tool, "x"), "unet-tool missing");
-} else {
- unet_tool = "unet-tool";
port: 51830,
pex_port: 51831,
keepalive: 10,
port: 51830,
pex_port: 51831,
keepalive: 10,
if (length(ARGV) < 2)
exit(usage());
if (length(ARGV) < 2)
exit(usage());
-file = shift(ARGV);
-command = shift(ARGV);
+let file = shift(ARGV);
+let command = shift(ARGV);
int: function(object, name, val) {
object[name] = int(val);
},
int: function(object, name, val) {
object[name] = int(val);
},
+const service_field_types = {
vxlan: {
id: "int",
port: "int",
vxlan: {
id: "int",
port: "int",
set_list() {
local field="$1"
set_list() {
local field="$1"
-args = {};
-print_only = false;
- for (arg in ARGV) {
- vals = match(arg, /^(.[[:alnum:]_-]*)=(.*)$/);
+ for (let arg in ARGV) {
+ let vals = match(arg, /^(.[[:alnum:]_-]*)=(.*)$/);
assert(vals, `Invalid argument: ${arg}`);
args[vals[1]] = vals[2]
}
assert(vals, `Invalid argument: ${arg}`);
args[vals[1]] = vals[2]
}
}
function set_fields(object, list) {
}
function set_fields(object, list) {
set_field(list[f], object, f, args[f]);
}
set_field(list[f], object, f, args[f]);
}
system(`ssh ${host} sh <&${fh.fileno()} >&${fh2.fileno()}`);
fh.close();
system(`ssh ${host} sh <&${fh.fileno()} >&${fh2.fileno()}`);
fh.close();
fh2.seek();
while (line = fh2.read("line")) {
fh2.seek();
while (line = fh2.read("line")) {
}
while (substr(ARGV[0], 0, 1) == "-") {
}
while (substr(ARGV[0], 0, 1) == "-") {
if (opt == "--")
break;
else if (opt == "-p")
if (opt == "--")
break;
else if (opt == "-p")
+let hostname, ssh_host, servicename;
+
if (command in [ "add-host", "set-host", "add-ssh-host", "set-ssh-host" ]) {
hostname = shift(ARGV);
assert(hostname, "Missing host name argument");
if (command in [ "add-host", "set-host", "add-ssh-host", "set-ssh-host" ]) {
hostname = shift(ARGV);
assert(hostname, "Missing host name argument");
command = replace(command, "ssh-", "");
}
command = replace(command, "ssh-", "");
}
if (command == "create") {
net_data = {
config: {},
if (command == "create") {
net_data = {
config: {},
assert(fh, `Could not open input file ${file}`);
try {
assert(fh, `Could not open input file ${file}`);
try {
}
if (command == "create") {
}
if (command == "create") {
- for (key, val in defaults)
+ for (let key, val in defaults)
args[key] ??= `${val}`;
if (!access(`${file}.key`))
system(`${unet_tool} -G > ${file}.key`);
}
if (command == "sign") {
args[key] ??= `${val}`;
if (!access(`${file}.key`))
system(`${unet_tool} -G > ${file}.key`);
}
if (command == "sign") {
- ret = system(`${unet_tool} -S -K ${file}.key -o ${file}.bin ${file}`);
+ let ret = system(`${unet_tool} -S -K ${file}.key -o ${file}.bin ${file}`);
if (ret != 0)
exit(ret);
if (args.upload) {
if (ret != 0)
exit(ret);
if (args.upload) {
- hosts = split(args.upload, ",");
- for (host in hosts) {
+ for (let host in split(args.upload, ",")) {
warn(`Uploading ${file}.bin to ${host}\n`);
ret = system(`${unet_tool} -U ${host} -K ${file}.key ${file}.bin`);
if (ret)
warn(`Uploading ${file}.bin to ${host}\n`);
ret = system(`${unet_tool} -U ${host} -K ${file}.key ${file}.bin`);
if (ret)
assert(false, "Unknown command");
}
assert(false, "Unknown command");
}
-net_data_json = sprintf("%.J\n", net_data);
+const net_data_json = sprintf("%.J\n", net_data);
+
if (print_only)
print(net_data_json);
else
if (print_only)
print(net_data_json);
else