Skip to content

Commit

Permalink
use incus instead of lxd by default
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Jan 7, 2024
1 parent b7c6d3a commit 1bf2fbc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 65 deletions.
21 changes: 11 additions & 10 deletions bin/lxd-create-home-bind → bin/incus-create-home-bind
Original file line number Diff line number Diff line change
@@ -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 <<EOF | lxc profile edit "$LXD_PROFILE"
name: $LXD_PROFILE
cat <<EOF | "$CLI" profile edit "$PROFILE"
name: $PROFILE
description: Bind-mount home
config:
raw.idmap: both $uid $uid
Expand All @@ -46,15 +47,15 @@ EOF
create_container() {
local container="$1"
local release="$2"
lxc launch "$release" "$container" -p default -p "$LXD_PROFILE"
"$CLI" launch "$release" "$container" -p default -p "$PROFILE"
}


container="$1"
release="${2:-$DEFAULT_IMAGE}"

if [ -z "$container" ]; then
echo "Usage: $SCRIPTNAME <container-name> [ubuntu-release]"
echo "Usage: $SCRIPTNAME <container-name> [image]"
exit 1
fi

Expand Down
29 changes: 0 additions & 29 deletions bin/lxd-ip

This file was deleted.

44 changes: 44 additions & 0 deletions bin/ssh-incus
Original file line number Diff line number Diff line change
@@ -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" "$@"
22 changes: 0 additions & 22 deletions bin/ssh-lxd

This file was deleted.

6 changes: 3 additions & 3 deletions rc.d/300-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down
2 changes: 1 addition & 1 deletion rc.d/700-lxc-hooks.sh → rc.d/700-container-hooks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# shellcheck disable=SC1090
#
# Hook for LXC/LXD login setup
# Hook for containers login setup


if [ "$(container_type)" = "lxc" ]; then
Expand Down

0 comments on commit 1bf2fbc

Please sign in to comment.