about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2024-10-24 16:24:33 +0300
committerNakidai <nakidai@disroot.org>2024-10-24 16:24:33 +0300
commitafd4daf9217ba7e8dcc9ca31ceb32f93ded7f12c (patch)
treea4a4a0c67856683ae47d3faf1d062699870cfba4
downloadthrougha-afd4daf9217ba7e8dcc9ca31ceb32f93ded7f12c.tar.gz
througha-afd4daf9217ba7e8dcc9ca31ceb32f93ded7f12c.zip
Add code v1.0.0
-rw-r--r--.gitignore1
-rw-r--r--LICENSE10
-rw-r--r--Makefile3
-rw-r--r--README4
-rw-r--r--througha.c43
5 files changed, 61 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..14237b3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+througha
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7ae8865
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,10 @@
+Permission to use, copy, modify, and/or distribute this software for
+any purpose with or without fee is hereby granted.
+
+THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
+FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..46b8529
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,3 @@
+all: througha
+clean:
+	rm -f througha
diff --git a/README b/README
new file mode 100644
index 0000000..b9d844b
--- /dev/null
+++ b/README
@@ -0,0 +1,4 @@
+Simple script for running command under a proxy.
+
+It unsets all variables with "_proxy" in their name and then sets "all_proxy"
+variable to first argument if it's not a dash.
diff --git a/througha.c b/througha.c
new file mode 100644
index 0000000..f12793c
--- /dev/null
+++ b/througha.c
@@ -0,0 +1,43 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+
+void usage(const char *name, const char *message)
+{
+    fprintf(
+        stderr,
+        "usage: %1$s proxy command [arg [arg [...]]]\n"
+        "  the proxy parameter may be set to '-' so no proxy will be used\n"
+        "%1$s: %2$s\n",
+        name, message
+    );
+    exit(1);
+}
+
+int main(int argc, char **argv, char **env)
+{
+    if (argc < 2)
+        usage(argv[0], "no proxy was specified");
+    else if (argc < 3)
+        usage(argv[0], "no command was specified");
+
+    for (char **envp = env; *envp != NULL; ++envp)
+    {
+        *strchr(*envp, '=') = '\0';
+
+        for (char *cp = *envp; *cp != '\0'; ++cp)
+            *cp = tolower(*cp);
+
+        if (strstr(*envp, "_proxy"))
+            unsetenv(*envp);
+    }
+
+    if (strcmp(argv[1], "-"))
+        setenv("all_proxy", argv[1], 1);
+
+    return execvp(argv[2], &argv[2]);
+}