#!/bin/sh
lxd_channel() {
    channel_version="latest"

    # lxd follows a pattern of $VERSION/stable/ubuntu-$VERSION
    # default in development is "latest"
    # with major version assigned and opened prior to Ubuntu release
    # shellcheck disable=SC1091
    [ -r /etc/os-release ] && . /etc/os-release
    channel_suffix="stable/ubuntu-${VERSION_ID}"
    case "${UBUNTU_CODENAME:-""}" in
      "jammy")
        channel_version="5.0";;
      "focal")
        channel_version="4.0";;
      *)
        ;;
    esac
    echo "${channel_version}/${channel_suffix}"
}

snap install lxd --channel="$(lxd_channel)" 1>&2
echo 1
