-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.func
More file actions
86 lines (73 loc) · 2.41 KB
/
Copy pathplatform.func
File metadata and controls
86 lines (73 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# ==============================================================================
# LXC-PLATFORM.FUNC - PROXMOX VE / INCUS PLATFORM DETECTION
# ==============================================================================
#
# Detects whether scripts run on a Proxmox VE host, an Incus host, or inside
# a container (update mode). Used by build.func to load the correct backend.
#
# Override: export LXC_PLATFORM=pve|incus|incus-container|container
#
# ==============================================================================
[[ -n "${_LXC_PLATFORM_FUNC_LOADED:-}" ]] && return
_LXC_PLATFORM_FUNC_LOADED=1
detect_lxc_platform() {
if [[ -n "${LXC_PLATFORM:-}" ]]; then
echo "$LXC_PLATFORM"
return
fi
if command -v pveversion &>/dev/null; then
echo "pve"
return
fi
if command -v incus &>/dev/null && incus info &>/dev/null 2>&1; then
echo "incus"
return
fi
if [[ -S /dev/incus/sock ]] || [[ -f /etc/profile.d/incus-motd.sh ]]; then
echo "incus-container"
return
fi
echo "container"
}
is_incus_lxc_backend() {
local platform
platform="$(detect_lxc_platform)"
[[ "$platform" == "incus" || "$platform" == "incus-container" ]]
}
is_incus_host() {
[[ "$(detect_lxc_platform)" == "incus" ]]
}
is_incus_container() {
[[ "$(detect_lxc_platform)" == "incus-container" ]]
}
# Writable state directory for defaults/diagnostics.
# Root (or writable /usr/local) → /usr/local/community-scripts
# Non-root Incus users → ~/.config/community-scripts
community_scripts_dir() {
if [[ -n "${COMMUNITY_SCRIPTS_STATE_DIR:-}" ]]; then
mkdir -p "$COMMUNITY_SCRIPTS_STATE_DIR" 2>/dev/null || true
echo "$COMMUNITY_SCRIPTS_STATE_DIR"
return 0
fi
local system_dir="/usr/local/community-scripts"
if [[ "$(id -u)" -eq 0 ]]; then
mkdir -p "$system_dir" 2>/dev/null || true
echo "$system_dir"
return 0
fi
if [[ -d "$system_dir" && -w "$system_dir" ]]; then
echo "$system_dir"
return 0
fi
if mkdir -p "$system_dir" 2>/dev/null && [[ -w "$system_dir" ]]; then
echo "$system_dir"
return 0
fi
local user_dir="${XDG_CONFIG_HOME:-${HOME:-/tmp}/.config}/community-scripts"
mkdir -p "$user_dir" 2>/dev/null || user_dir="/tmp/community-scripts-$$"
mkdir -p "$user_dir" 2>/dev/null || true
echo "$user_dir"
}