dlinux-cli/dlinux
2024-11-30 14:28:24 +01:00

42 lines
562 B
Bash
Executable File

#!/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