fix: address coderabbitai and CrazyWolf13 review feedback

- Remove inline comments from var_ declarations in ct/companion.sh
- Replace dual python3 JSON calls with single jq query parsing both
  RELEASE and ASSET_URL from the same package object, preventing
  version/URL mismatch across different package entries
- Add validation for both RELEASE and ASSET_URL (previously only
  ASSET_URL was checked in install script)
- Move version file from /opt/companion_version.txt to ~/.companion
  per project convention
- Use fetch_and_deploy_from_url framework helper instead of manual
  curl/tar/rm in both update_script and install script
- Remove redundant dependencies (curl, sudo, mc, python3); add jq
- Reload udev rules after copying (udevadm control --reload-rules &&
  udevadm trigger) so USB permissions apply immediately
- Replace manual apt-get autoremove/autoclean with cleanup_lxc
This commit is contained in:
Grant Labutis
2026-03-23 14:31:46 -04:00
parent 5987230f99
commit 7970b1b9e0
2 changed files with 25 additions and 70 deletions

View File

@@ -1,26 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
# Copyright (c) 2021-2026 community-scripts ORG # Copyright (c) 2021-2026 community-scripts ORG
# Author: glabutis # Author: glabutis
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://github.com/bitfocus/companion # Source: https://github.com/bitfocus/companion
# App Default Values
APP="Companion" APP="Companion"
var_tags="${var_tags:-automation;media}" var_tags="${var_tags:-automation;media}"
# Tags for Proxmox VE (max 2, no spaces, semicolon-separated)
var_cpu="${var_cpu:-2}" var_cpu="${var_cpu:-2}"
# Number of cores (default: 2)
var_ram="${var_ram:-512}" var_ram="${var_ram:-512}"
# RAM in MB (default: 512)
var_disk="${var_disk:-8}" var_disk="${var_disk:-8}"
# Disk space in GB (default: 8)
var_os="${var_os:-debian}" var_os="${var_os:-debian}"
# Default OS
var_version="${var_version:-12}" var_version="${var_version:-12}"
# Default OS version
var_unprivileged="${var_unprivileged:-1}" var_unprivileged="${var_unprivileged:-1}"
# 1 = unprivileged container, 0 = privileged
header_info "$APP" header_info "$APP"
variables variables
@@ -38,24 +30,15 @@ function update_script() {
fi fi
RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20")
RELEASE=$(echo "$RELEASE_JSON" | python3 -c " PACKAGE_JSON=$(echo "$RELEASE_JSON" | jq -c '(if type == "array" then . else .packages end) | [.[] | select(.target=="linux-tgz" and (.uri | contains("linux-x64")))] | first')
import sys, json RELEASE=$(echo "$PACKAGE_JSON" | jq -r '.version // empty')
data = json.load(sys.stdin) ASSET_URL=$(echo "$PACKAGE_JSON" | jq -r '.uri // empty')
for pkg in data.get('packages', data if isinstance(data, list) else []): if [[ -z "$RELEASE" || -z "$ASSET_URL" ]]; then
if pkg.get('target') == 'linux-tgz': msg_error "Could not resolve a matching Linux x64 Companion package from the Bitfocus API."
print(pkg.get('version', '')) exit 1
break fi
")
ASSET_URL=$(echo "$RELEASE_JSON" | python3 -c "
import sys, json
data = json.load(sys.stdin)
for pkg in data.get('packages', data if isinstance(data, list) else []):
if pkg.get('target') == 'linux-tgz':
print(pkg.get('uri', ''))
break
")
if [[ "${RELEASE}" == "$(cat /opt/companion_version.txt 2>/dev/null)" ]]; then if [[ "${RELEASE}" == "$(cat ~/.companion 2>/dev/null)" ]]; then
msg_ok "No update required. ${APP} is already at v${RELEASE}" msg_ok "No update required. ${APP} is already at v${RELEASE}"
exit exit
fi fi
@@ -65,23 +48,15 @@ for pkg in data.get('packages', data if isinstance(data, list) else []):
msg_ok "Stopped ${APP}" msg_ok "Stopped ${APP}"
msg_info "Updating ${APP} to v${RELEASE}" msg_info "Updating ${APP} to v${RELEASE}"
rm -rf /opt/companion CLEAN_INSTALL=1 fetch_and_deploy_from_url "$ASSET_URL" "/opt/companion"
mkdir -p /opt/companion
curl -fsSL "$ASSET_URL" -o /tmp/companion.tar.gz
tar -xzf /tmp/companion.tar.gz -C /opt/companion --strip-components=1
rm -f /tmp/companion.tar.gz
chown -R companion:companion /opt/companion chown -R companion:companion /opt/companion
echo "${RELEASE}" >~/.companion
msg_ok "Updated ${APP} to v${RELEASE}" msg_ok "Updated ${APP} to v${RELEASE}"
msg_info "Starting ${APP}" msg_info "Starting ${APP}"
systemctl start companion systemctl start companion
msg_ok "Started ${APP}" msg_ok "Started ${APP}"
msg_info "Cleaning Up"
rm -f /tmp/companion.tar.gz
msg_ok "Cleanup Completed"
echo "${RELEASE}" >/opt/companion_version.txt
msg_ok "Update Successful" msg_ok "Update Successful"
exit exit
} }

View File

@@ -15,47 +15,31 @@ update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y \ $STD apt-get install -y \
curl \ jq \
sudo \
mc \
python3 \
libusb-1.0-0 libusb-1.0-0
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
msg_info "Fetching Latest Bitfocus Companion Release" msg_info "Fetching Latest Bitfocus Companion Release"
RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20")
RELEASE=$(echo "$RELEASE_JSON" | python3 -c " PACKAGE_JSON=$(echo "$RELEASE_JSON" | jq -c '(if type == "array" then . else .packages end) | [.[] | select(.target=="linux-tgz" and (.uri | contains("linux-x64")))] | first')
import sys, json RELEASE=$(echo "$PACKAGE_JSON" | jq -r '.version // empty')
data = json.load(sys.stdin) ASSET_URL=$(echo "$PACKAGE_JSON" | jq -r '.uri // empty')
for pkg in data.get('packages', data if isinstance(data, list) else []): if [[ -z "$RELEASE" || -z "$ASSET_URL" ]]; then
if pkg.get('target') == 'linux-tgz': msg_error "Could not resolve a matching Linux x64 Companion package from the Bitfocus API."
print(pkg.get('version', ''))
break
")
ASSET_URL=$(echo "$RELEASE_JSON" | python3 -c "
import sys, json
data = json.load(sys.stdin)
for pkg in data.get('packages', data if isinstance(data, list) else []):
if pkg.get('target') == 'linux-tgz':
print(pkg.get('uri', ''))
break
")
if [[ -z "$ASSET_URL" ]]; then
msg_error "Could not locate a Linux x64 release from the Bitfocus API."
exit 1 exit 1
fi fi
msg_ok "Found Companion v${RELEASE}" msg_ok "Found Companion v${RELEASE}"
msg_info "Downloading Bitfocus Companion v${RELEASE}" msg_info "Downloading Bitfocus Companion v${RELEASE}"
mkdir -p /opt/companion fetch_and_deploy_from_url "$ASSET_URL" "/opt/companion"
curl -fsSL "$ASSET_URL" -o /tmp/companion.tar.gz
$STD tar -xzf /tmp/companion.tar.gz -C /opt/companion --strip-components=1
rm -f /tmp/companion.tar.gz
msg_ok "Downloaded and Extracted Bitfocus Companion v${RELEASE}" msg_ok "Downloaded and Extracted Bitfocus Companion v${RELEASE}"
msg_info "Installing udev Rules" msg_info "Installing udev Rules"
[[ -f /opt/companion/50-companion-headless.rules ]] && cp /opt/companion/50-companion-headless.rules /etc/udev/rules.d/ if [[ -f /opt/companion/50-companion-headless.rules ]]; then
cp /opt/companion/50-companion-headless.rules /etc/udev/rules.d/
udevadm control --reload-rules
udevadm trigger
fi
msg_ok "Installed udev Rules" msg_ok "Installed udev Rules"
msg_info "Creating companion User" msg_info "Creating companion User"
@@ -90,12 +74,8 @@ EOF
systemctl enable -q --now companion systemctl enable -q --now companion
msg_ok "Created Service" msg_ok "Created Service"
echo "${RELEASE}" >/opt/companion_version.txt echo "${RELEASE}" >~/.companion
motd_ssh motd_ssh
customize customize
cleanup_lxc
msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"