summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile2
-rw-r--r--create.c (renamed from setup.c)2
-rw-r--r--destroy.c40
-rw-r--r--ssh-command.sh35
5 files changed, 64 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index db06a66..cd963a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,9 @@
 chroot.tar
+create
+destroy
 ingest
 ptee
 root
-setup
 ssh-command
 tags
 view
diff --git a/Makefile b/Makefile
index 58e7cc9..e37fc70 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-BINS = ingest ptee setup ssh-command view
+BINS = create destroy ingest ptee ssh-command view
 USER = stream
 
 CFLAGS += -Wall -Wextra -Wpedantic
diff --git a/setup.c b/create.c
index 92509e3..49cadb6 100644
--- a/setup.c
+++ b/create.c
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
     if (argc < 2) errx(EX_USAGE, "missing public id");
 
     uint32_t id[4];
-    char public[7 + 32 + 1];
+    char public[10 + 32 + 1];
     char private[8 + 32 + 1];
 
     arc4random_buf(id, sizeof(id));
diff --git a/destroy.c b/destroy.c
new file mode 100644
index 0000000..02355f0
--- /dev/null
+++ b/destroy.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2018  Causal Agent June <june@causal.agency>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <err.h>
+#include <fcntl.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+    if (argc < 2) errx(EX_USAGE, "missing private id");
+
+    int fd = open("private", 0);
+    if (fd < 0) err(EX_NOINPUT, "private");
+
+    const char *private = argv[1];
+    char public[10 + 32 + 1] = {0};
+    ssize_t n = readlinkat(fd, private, public, sizeof(public) - 1);
+    if (n < 0) err(EX_NOINPUT, "%s", private);
+
+    int error = unlinkat(fd, public, 0);
+    if (error) err(EX_NOINPUT, "%s", public);
+
+    error = unlinkat(fd, private, 0);
+    if (error) err(EX_NOINPUT, "%s", private);
+
+    return EX_OK;
+}
diff --git a/ssh-command.sh b/ssh-command.sh
index 4433717..3381d40 100644
--- a/ssh-command.sh
+++ b/ssh-command.sh
@@ -6,35 +6,39 @@ GIT_URL=git@ascii.town:stream.git
 
 welcome() {
     echo
-    echo 'Welcome to Twinch dot ptee vee!'
+    echo ' [~ The Stream at ASCII Town ~] '
     echo
-    echo 'To view a public stream, run one of the following commands:'
-    echo
-
     cd public
     for id in *; do
         echo "    ssh -t $SSH_URL $id"
     done
     echo
+    echo ' [~ A Stream of Your Own ~] '
+    echo
+    echo "    ssh -t $SSH_URL start"
 }
 
 start() {
-    local id
-    id=$(setup $1)
+    local public private trash
+    read -p 'Public ID: ' -r public trash
+    public=${public##*/}
+    private=$(create $public)
+    echo "Private ID: $private"
     echo
-    echo 'Stream created!'
+    echo ' [~ Stop ~] '
     echo
-    echo 'To view the stream, run:'
+    echo "    ssh -t $SSH_URL stop $private"
     echo
-    echo "    ssh -t $SSH_URL $1"
+    echo ' [~ View ~] '
     echo
-    echo 'To broadcast to the stream, run:'
+    echo "    ssh -t $SSH_URL $public"
     echo
-    echo "    git clone $GIT_URL"
-    echo "    cd stream"
-    echo "    make ptee"
-    echo "    ./ptee | ssh $SSH_URL ingest $id"
+    echo ' [~ Broadcast ~] '
     echo
+    echo "    git clone $GIT_URL"
+    echo '    cd stream'
+    echo '    make ptee'
+    echo "    ./ptee | ssh $SSH_URL ingest $private"
 }
 
 if [ -z "${SSH_ORIGINAL_COMMAND:-}" ]; then
@@ -43,7 +47,8 @@ if [ -z "${SSH_ORIGINAL_COMMAND:-}" ]; then
 else
     set $SSH_ORIGINAL_COMMAND
     case $1 in
-        start) start ${2##*/} ;;
+        start) start ;;
+        stop) exec destroy ${2##*/} ;;
         ingest) exec ingest private/${2##*/} ;;
         view) exec view public/${2##*/} ;;
         *) exec view public/${1##*/} ;;