1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00
Natanael Copa 3197427cb3 Add incus support
Incus provides meta-data via unix socket /dev/incus/sock
https://linuxcontainers.org/incus/docs/main/dev-incus/
2024-06-28 11:40:22 +02:00

44 lines
854 B
Bash
Executable File

#!/bin/sh
input="$(cat)"
host=""
port=""
local_port=1024
case "$input" in
-*) echo "nc: bad input: \$input" >&2; exit 1;;
esac
while [ ! -z "$1" ]; do
case "$1" in
-w) shift 2;;
-p) local_port="$2"; shift 2;;
*) if [ -z "$host" ]; then
host="$1"
elif [ -z "$port" ]; then
port="$1";
fi
shift 1
;;
esac
done
case "$CLOUD" in
scaleway)
if [ $local_port -gt 1023 ]; then
NC_CONTENT="invalid local port"
else
NC_CONTENT="$(cat ${NC_FILE:-$host.txt})"
fi
printf "HTTP/1.1 200 OK\r\n\r\n%s" "$NC_CONTENT"
;;
incus)
set -- $input # GET $URL HTTP/1.0
url="$2"
NC_CONTENT="$(cat ${NC_FILE:-${host%:*}.txt})"
len=$(printf "%s" "$NC_CONTENT" | wc -c)
printf "HTTP/1.0 200 $url OK\r\nContent-Type: application/json\r\nContent-Length: $len\r\n\r\n%s" \
"$NC_CONTENT"
;;
*)
echo "token-foo"
;;
esac