From ad8211243d46cc63e230548896f41d3e7d4dfa57 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sat, 30 Nov 2024 14:28:24 +0100 Subject: [PATCH] init --- dlinux | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 dlinux diff --git a/dlinux b/dlinux new file mode 100755 index 0000000..2cd122c --- /dev/null +++ b/dlinux @@ -0,0 +1,41 @@ +#!/bin/bash + +KEY_FILE=~/.dlinux-cli.key + +if [ ! -f $KEY_FILE ]; then + echo -e "Key file not found, run:\necho \"[YOUR-API-KEY]\" > $KEY_FILE" + exit 1 +fi + +API_KEY="$(cat $KEY_FILE)" + +print_help() { + printf " +$0 hello - Get a hello message +$0 name - Get your SSHID +" +} + +# Helper function + +call_api() { + curl -X $1 -H "x-ssh-auth: $API_KEY" "https://api.ssh.surf/$2" +} + +# Commands + +command_hello() { + call_api GET hello | jq .message +} + +command_name() { + call_api GET name | jq .message +} + +# Command handler + +if [ $1 ]; then + command_$1 +else + print_help +fi