1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2026-06-21 00:07:16 +03:00

29 lines
765 B
Bash

# Incus Instance Metadata
# vim:set filetype=sh:
# shellcheck shell=sh
# https://linuxcontainers.org/incus/docs/main/dev-incus/
: "${IMDS_API_VERSION:=1.0}"
IMDS_URI="/$IMDS_API_VERSION/meta-data"
IMDS_LOCAL_HOSTNAME="local-hostname"
IMDS_HOSTNAME="local-hostname"
IMDS_ENDPOINT=local:/dev/incus/sock
_imds() {
printf "GET %s HTTP/1.0\n\n" "$IMDS_URI" \
| nc "$IMDS_ENDPOINT" | dos2unix \
| awk -F ': ' -v key="$1" '$1 == key { print $2 }'
}
_imds_userdata() {
printf "GET /1.0/config/user.user-data HTTP/1.0\n\n" \
| nc "$IMDS_ENDPOINT" | sed '1,/^\r$/d'
}
_imds_ssh_keys() {
# extract ssh_authorized_keys from user-data
_imds_userdata \
| awk '/^ssh_authorized_keys:/ {flag=1; next} /^[a-z]/ {flag=0} flag && /^ *- / {sub(/^ *- /, ""); print}'
}