diff --git a/bin/lxd-create-home-bind b/bin/incus-create-home-bind similarity index 61% rename from bin/lxd-create-home-bind rename to bin/incus-create-home-bind index 1563229..6989b6b 100755 --- a/bin/lxd-create-home-bind +++ b/bin/incus-create-home-bind @@ -1,25 +1,26 @@ #!/bin/bash -e # -# Create a LXD with the specified name (and optionally ubuntu release) and -# bind-mount current user's home directory. +# Create an Incus container with the specified name (and optionally image name) +# and bind-mount current user's home directory. SCRIPTNAME=$(basename "$0") -DEFAULT_IMAGE="jammy" -LXD_PROFILE="home-bind" +DEFAULT_IMAGE="ubuntu/jammy/cloud" +PROFILE="home-bind" +CLI="${CLI:-incus}" ensure_profile() { - if ! lxc profile show "$LXD_PROFILE" >/dev/null 2>&1; then - lxc profile create "$LXD_PROFILE" + if ! "$CLI" profile show "$PROFILE" >/dev/null 2>&1; then + "$CLI" profile create "$PROFILE" fi local uid uid=$(id -u "$USER") # ensure it's up to date - cat < [ubuntu-release]" + echo "Usage: $SCRIPTNAME [image]" exit 1 fi diff --git a/bin/lxd-ip b/bin/lxd-ip deleted file mode 100755 index 67a37bd..0000000 --- a/bin/lxd-ip +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -# -# Return the IP address of a LXD container. -# -# Usage: lxd-ip [iface] - -name="$1" -iface="${2:-eth0}" - -if [ -z "$name" ]; then - echo "Missing container name" - exit 1 -fi - -lxc info "$name" | awk ' -BEGIN { - while ($1 != "'"$iface"':") { - getline; - } - while ($0 !~ "IP addresses:") { - getline; - } - while ($0 !~ "global") { - getline; - } - split($2, tokens, /\//); - print tokens[1]; -} -' diff --git a/bin/ssh-incus b/bin/ssh-incus new file mode 100755 index 0000000..b24d245 --- /dev/null +++ b/bin/ssh-incus @@ -0,0 +1,44 @@ +#!/bin/bash -e +# +# Ssh to an Incus container by name. + + +hostname="$1" +shift 1 + + +container_ip() { + local name="$1" + local iface="${2:-eth0}" + + incus info "$name" | awk ' +BEGIN { + while ($1 != "'"$iface"':") { + getline; + } + while ($0 !~ "IP addresses:") { + getline; + } + while ($0 !~ "global") { + getline; + } + split($2, tokens, /\//); + print tokens[1]; +} +' +} + + +if [ -z "$hostname" ]; then + echo "Missing container name" + exit 1 +fi + +ip=$(container_ip "$hostname") +if [ -z "$ip" ]; then + echo "Address not found" + exit 2 +fi + +# shellcheck disable=SC2029 +ssh "$USER@$ip" "$@" diff --git a/bin/ssh-lxd b/bin/ssh-lxd deleted file mode 100755 index 1116171..0000000 --- a/bin/ssh-lxd +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# -# Ssh to a LXD container by name. - - -hostname="$1" -shift 1 - - -if [ -z "$hostname" ]; then - echo "Missing container name" - exit 1 -fi - -ip=$(lxd-ip "$hostname") -if [ -z "$ip" ]; then - echo "Address not found" - exit 2 -fi - -# shellcheck disable=SC2029 -ssh "$USER@$ip" "$@" diff --git a/rc.d/300-completion.sh b/rc.d/300-completion.sh index 31367ab..fbdf58b 100644 --- a/rc.d/300-completion.sh +++ b/rc.d/300-completion.sh @@ -12,13 +12,13 @@ if is_interactive; then } complete -F _bcomp_s s - _bcomp_ssh_lxd() { + _bcomp_ssh_incus() { local cur="${COMP_WORDS[COMP_CWORD]}" local sources - sources="$(lxc list --columns=ns | awk '$4 == "RUNNING" { print $2; }')" + sources="$(incus list --columns=ns | awk '$4 == "RUNNING" { print $2; }')" mapfile -t COMPREPLY < <(compgen -W "$sources" -- "$cur") } - complete -F _bcomp_ssh_lxd ssh-lxd + complete -F _bcomp_ssh_incus ssh-incus _bcomp_prompt_set() { local cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/rc.d/700-lxc-hooks.sh b/rc.d/700-container-hooks.sh similarity index 91% rename from rc.d/700-lxc-hooks.sh rename to rc.d/700-container-hooks.sh index ccc789f..29beff3 100644 --- a/rc.d/700-lxc-hooks.sh +++ b/rc.d/700-container-hooks.sh @@ -1,6 +1,6 @@ # shellcheck disable=SC1090 # -# Hook for LXC/LXD login setup +# Hook for containers login setup if [ "$(container_type)" = "lxc" ]; then