Compare commits

...

1 Commits

Author SHA1 Message Date
CanbiZ (MickLesk)
3ea51f5a62 Add Alpine support and improve Tailscale install
Detect Alpine inside the LXC container and install Tailscale via apk (add community repo if missing), enable/start the service. Preserve Debian/Ubuntu install path but improve DNS resolution checks, temporarily override /etc/resolv.conf if DNS appears blocked, and restore it afterwards. Switch pct exec to use sh -c, tighten command existence checks and redirections, ensure curl and keyring directory are present, add Tailscale apt source and install package. Overall robustness and error-handling improvements for installing Tailscale in containers.
2026-02-26 10:01:41 +01:00

View File

@@ -76,12 +76,33 @@ grep -q "lxc.mount.entry: /dev/net/tun" "$CTID_CONFIG_PATH" || echo "lxc.mount.e
header_info header_info
msg_info "Installing Tailscale in CT $CTID" msg_info "Installing Tailscale in CT $CTID"
pct exec "$CTID" -- bash -c ' pct exec "$CTID" -- sh -c '
set -e set -e
# Detect OS inside container
if [ -f /etc/alpine-release ]; then
# ── Alpine Linux ──
echo "[INFO] Alpine Linux detected, installing Tailscale via apk..."
# Enable community repo if not already enabled
if ! grep -q "^[^#].*community" /etc/apk/repositories 2>/dev/null; then
ALPINE_VERSION=$(cat /etc/alpine-release | cut -d. -f1,2)
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/community" >> /etc/apk/repositories
fi
apk update
apk add --no-cache tailscale
# Enable and start Tailscale service
rc-update add tailscale default 2>/dev/null || true
rc-service tailscale start 2>/dev/null || true
else
# ── Debian / Ubuntu ──
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
# Source os-release properly (handles quoted values) # Source os-release properly (handles quoted values)
source /etc/os-release . /etc/os-release
# Fallback if DNS is poisoned or blocked # Fallback if DNS is poisoned or blocked
ORIG_RESOLV="/etc/resolv.conf" ORIG_RESOLV="/etc/resolv.conf"
@@ -89,20 +110,20 @@ BACKUP_RESOLV="/tmp/resolv.conf.backup"
# Check DNS resolution using multiple methods (dig may not be installed) # Check DNS resolution using multiple methods (dig may not be installed)
dns_check_failed=true dns_check_failed=true
if command -v dig &>/dev/null; then if command -v dig >/dev/null 2>&1; then
if dig +short pkgs.tailscale.com 2>/dev/null | grep -qvE "^127\.|^0\.0\.0\.0$|^$"; then if dig +short pkgs.tailscale.com 2>/dev/null | grep -qvE "^127\.|^0\.0\.0\.0$|^$"; then
dns_check_failed=false dns_check_failed=false
fi fi
elif command -v host &>/dev/null; then elif command -v host >/dev/null 2>&1; then
if host pkgs.tailscale.com 2>/dev/null | grep -q "has address"; then if host pkgs.tailscale.com 2>/dev/null | grep -q "has address"; then
dns_check_failed=false dns_check_failed=false
fi fi
elif command -v nslookup &>/dev/null; then elif command -v nslookup >/dev/null 2>&1; then
if nslookup pkgs.tailscale.com 2>/dev/null | grep -q "Address:"; then if nslookup pkgs.tailscale.com 2>/dev/null | grep -q "Address:"; then
dns_check_failed=false dns_check_failed=false
fi fi
elif command -v getent &>/dev/null; then elif command -v getent >/dev/null 2>&1; then
if getent hosts pkgs.tailscale.com &>/dev/null; then if getent hosts pkgs.tailscale.com >/dev/null 2>&1; then
dns_check_failed=false dns_check_failed=false
fi fi
else else
@@ -117,11 +138,10 @@ if $dns_check_failed; then
echo "nameserver 1.1.1.1" >"$ORIG_RESOLV" echo "nameserver 1.1.1.1" >"$ORIG_RESOLV"
fi fi
if ! command -v curl &>/dev/null; then if ! command -v curl >/dev/null 2>&1; then
echo "[INFO] curl not found, installing..." echo "[INFO] curl not found, installing..."
apt-get update -qq apt-get update -qq
apt update -qq apt-get install -y curl >/dev/null
apt install -y curl >/dev/null
fi fi
# Ensure keyrings directory exists # Ensure keyrings directory exists
@@ -134,13 +154,13 @@ echo "deb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://
>/etc/apt/sources.list.d/tailscale.list >/etc/apt/sources.list.d/tailscale.list
apt-get update -qq apt-get update -qq
apt update -qq apt-get install -y tailscale >/dev/null
apt install -y tailscale >/dev/null
if [[ -f /tmp/resolv.conf.backup ]]; then if [ -f /tmp/resolv.conf.backup ]; then
echo "[INFO] Restoring original /etc/resolv.conf" echo "[INFO] Restoring original /etc/resolv.conf"
mv /tmp/resolv.conf.backup /etc/resolv.conf mv /tmp/resolv.conf.backup /etc/resolv.conf
fi fi
fi
' '
TAGS=$(awk -F': ' '/^tags:/ {print $2}' "$CTID_CONFIG_PATH") TAGS=$(awk -F': ' '/^tags:/ {print $2}' "$CTID_CONFIG_PATH")