Last active
October 8, 2024 23:40
-
-
Save yunginnanet/c275706b2045ad431c9e33386e50b34c to your computer and use it in GitHub Desktop.
lxd-client.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| _port=${LXD_PORT:-"8443"} | |
| _fqdn=${LXD_FQDN:-"ebaumsworld.com"} | |
| set -e | |
| function req { | |
| go version || return 1 | |
| git version || return 1 | |
| ssh -V || return 1 | |
| } | |
| function ensure_path { | |
| grep -e 'PATH.*\.local/bin' ~/.bashrc >/dev/null && lxc version >/dev/null && return 0 | |
| echo "adding ~/.local/bin to your path via ~/.bashrc..." | |
| #shellcheck disable=SC2016 | |
| echo 'export PATH=$HOME/.local/bin:$PATH' >>~/.bashrc || return 1 | |
| #shellcheck disable=SC1090 | |
| source ~/.bashrc || return 1 | |
| lxc version >/dev/null || return 1 | |
| } | |
| req || exit 1 | |
| export CGO_ENABLED=0 | |
| if [ "$_fqdn" == "ebaumsworld.com" ]; then | |
| echo "enter fqdn for lxd endpoint for which you have permissions:" | |
| read -r _fqdn | |
| fi | |
| exec 3<>"/dev/tcp/$_fqdn/$_port" || ssh "$_fqdn" "lxc config set core.https_address '[::]:8443'" || exit 1 | |
| # warm user account to assert that we have a certificate associated with the user in the case that it's new | |
| ssh "$_fqdn" "lxc list" >/dev/null | |
| token="$(ssh "$_fqdn" 'lxc config trust add --name $(whoami)' | grep -v token)" || exit 1 | |
| git clone https://github.com/lxc/lxd || cd lxd || exit 1 | |
| cd lxd/lxc || exit 1 | |
| go build -v ./ || exit 1 | |
| mv lxc ~/.local/bin/ || exit 1 | |
| # following optional if you already have this in your path | |
| if ! ensure_path; then if ! lxc version; then echo "FUBAR!? we need 'lxc' in our path... please debug and try again"; fi; fi | |
| # but you need these \/ | |
| lxc remote add "$_fqdn" "$token" | |
| lxc remote set-default "$_fqdn" | |
| lxc list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment