tools: replace most ndnsec shell wrappers with symlinks
Change-Id: I40488dddaaee13ee4391e906646b9f651b26c2de
diff --git a/tools/ndnsec/main.cpp b/tools/ndnsec/main.cpp
index c0be01b..9c8e64e 100644
--- a/tools/ndnsec/main.cpp
+++ b/tools/ndnsec/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -25,6 +25,7 @@
#include "ndn-cxx/version.hpp"
#include <boost/exception/diagnostic_information.hpp>
+#include <boost/filesystem/path.hpp>
#include <iostream>
NDN_LOG_INIT(ndnsec);
@@ -52,29 +53,39 @@
int
main(int argc, char* argv[])
{
- if (argc < 2) {
+ boost::filesystem::path p(argv[0]);
+ std::string basename(p.filename().string());
+ std::string command;
+ if (basename.rfind("ndnsec-", 0) == 0) {
+ command = basename.substr(std::strlen("ndnsec-"));
+ }
+ else if (argc >= 2) {
+ command = argv[1];
+ argc--;
+ argv++;
+ }
+ else {
std::cerr << NDNSEC_HELP_TEXT << std::endl;
return 2;
}
+ NDN_LOG_TRACE("Command: " << command);
- using namespace ndn::ndnsec;
-
- std::string command(argv[1]);
try {
+ using namespace ndn::ndnsec;
if (command == "help") { std::cout << NDNSEC_HELP_TEXT << std::endl; }
else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING << std::endl; }
- else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); }
- else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); }
- else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); }
- else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); }
- else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); }
- else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); }
- else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); }
- else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); }
- else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
- else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); }
- else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); }
- else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
+ else if (command == "list") { return ndnsec_list(argc, argv); }
+ else if (command == "get-default") { return ndnsec_get_default(argc, argv); }
+ else if (command == "set-default") { return ndnsec_set_default(argc, argv); }
+ else if (command == "delete") { return ndnsec_delete(argc, argv); }
+ else if (command == "key-gen") { return ndnsec_key_gen(argc, argv); }
+ else if (command == "sign-req") { return ndnsec_sign_req(argc, argv); }
+ else if (command == "cert-gen") { return ndnsec_cert_gen(argc, argv); }
+ else if (command == "cert-dump") { return ndnsec_cert_dump(argc, argv); }
+ else if (command == "cert-install") { return ndnsec_cert_install(argc, argv); }
+ else if (command == "export") { return ndnsec_export(argc, argv); }
+ else if (command == "import") { return ndnsec_import(argc, argv); }
+ else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc, argv); }
else {
std::cerr << "ERROR: Unknown command '" << command << "'\n"
<< "\n"
diff --git a/tools/ndnsec/wscript b/tools/ndnsec/wscript
index 9f61ae4..caac9fc 100644
--- a/tools/ndnsec/wscript
+++ b/tools/ndnsec/wscript
@@ -8,7 +8,13 @@
features='pch',
headers='ndnsec-pch.hpp',
use='ndn-cxx')
+
bld.program(name='tool-ndnsec',
target=top + 'bin/ndnsec',
source=['main.cpp'],
use='tool-ndnsec-objects')
+
+ for cmd in ('list', 'get-default', 'set-default', 'delete',
+ 'key-gen', 'sign-req', 'cert-gen', 'cert-install',
+ 'cert-dump', 'export', 'import', 'unlock-tpm'):
+ bld.symlink_as('${BINDIR}/ndnsec-%s' % cmd, 'ndnsec')
diff --git a/tools/wrapper/ndnsec-cert-dump.sh b/tools/wrapper/ndnsec-cert-dump.sh
deleted file mode 100644
index 240a9b3..0000000
--- a/tools/wrapper/ndnsec-cert-dump.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec cert-dump "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-cert-gen.sh b/tools/wrapper/ndnsec-cert-gen.sh
deleted file mode 100644
index 9479ac5..0000000
--- a/tools/wrapper/ndnsec-cert-gen.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec cert-gen "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-cert-install.sh b/tools/wrapper/ndnsec-cert-install.sh
deleted file mode 100644
index 4338823..0000000
--- a/tools/wrapper/ndnsec-cert-install.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec cert-install "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-delete.sh b/tools/wrapper/ndnsec-delete.sh
deleted file mode 100644
index 5d8a05c..0000000
--- a/tools/wrapper/ndnsec-delete.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec delete "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-export.sh b/tools/wrapper/ndnsec-export.sh
deleted file mode 100644
index 50b7229..0000000
--- a/tools/wrapper/ndnsec-export.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec export "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-get-default.sh b/tools/wrapper/ndnsec-get-default.sh
deleted file mode 100644
index d1ef31d..0000000
--- a/tools/wrapper/ndnsec-get-default.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec get-default "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-import.sh b/tools/wrapper/ndnsec-import.sh
deleted file mode 100644
index e05774e..0000000
--- a/tools/wrapper/ndnsec-import.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec import "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-key-gen.sh b/tools/wrapper/ndnsec-key-gen.sh
deleted file mode 100644
index 0e3bde9..0000000
--- a/tools/wrapper/ndnsec-key-gen.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec key-gen "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-list.sh b/tools/wrapper/ndnsec-list.sh
deleted file mode 100644
index 454ac6e..0000000
--- a/tools/wrapper/ndnsec-list.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec list "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-set-default.sh b/tools/wrapper/ndnsec-set-default.sh
deleted file mode 100644
index dfcd03b..0000000
--- a/tools/wrapper/ndnsec-set-default.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec set-default "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-sign-req.sh b/tools/wrapper/ndnsec-sign-req.sh
deleted file mode 100644
index 15aef6c..0000000
--- a/tools/wrapper/ndnsec-sign-req.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec sign-req "$@"
\ No newline at end of file
diff --git a/tools/wrapper/ndnsec-unlock-tpm.sh b/tools/wrapper/ndnsec-unlock-tpm.sh
deleted file mode 100644
index ec8d0a9..0000000
--- a/tools/wrapper/ndnsec-unlock-tpm.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!@SH@
-
-`dirname "$0"`/ndnsec unlock-tpm "$@"
\ No newline at end of file