Autodetect incus/lxd unless specific YNHDEV_BACKEND

This commit is contained in:
selfhoster1312 2024-08-25 10:15:57 +02:00
parent 8db653ea9e
commit 2490e35731
3 changed files with 12 additions and 7 deletions

View file

@ -33,9 +33,9 @@ assert_we_are_connected_to_the_internets() {
assert_we_have_all_dependencies() { assert_we_have_all_dependencies() {
deps=("lynx" "jq" "python3" "pip3") deps=("lynx" "jq" "python3" "pip3")
if [[ "${YNHDEV_BACKEND:-}" == "incus" ]]; then if [[ "${lxc}" == "incus" ]]; then
deps+=(incus) deps+=(incus)
else elif [[ "${lxc}" == "lxc" ]]; then
deps+=(lxc lxd) deps+=(lxc lxd)
fi fi
@ -87,7 +87,7 @@ function set_incus_remote()
function check_lxc_setup() function check_lxc_setup()
{ {
if [[ "${YNHDEV_BACKEND:-}" == "incus" ]]; then if [[ "${lxc}" == "incus" ]]; then
check_incus_setup check_incus_setup
else else
check_lxd_setup check_lxd_setup

View file

@ -3,10 +3,15 @@
# Check for LXC or Incus # Check for LXC or Incus
function switch_lxc_incus() function switch_lxc_incus()
{ {
if [[ "${YNHDEV_BACKEND:-}" == "incus" ]]; then if [[ -z "${YNHDEV_BACKEND:-}" ]]; then
lxc=incus # Autodetect because no preference was specified
if command -v incus 2>&1 >/dev/null; then
lxc="incus"
else else
lxc=lxc lxc="lxc"
fi
else
lxc="${YNHDEV_BACKEND}"
fi fi
} }

View file

@ -24,7 +24,7 @@ print_help() {
-S, --storage-dir DIRECTORY Where to store temporary test files like yunohost backups -S, --storage-dir DIRECTORY Where to store temporary test files like yunohost backups
-h, --help Display this help -h, --help Display this help
Pass YNHDEV_BACKEND=incus to use incus instead of lxd. Pass YNHDEV_BACKEND=incus|lxd to use a specific LXD-compatible backend.
EOF EOF
exit 0 exit 0