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:
@@ -1,26 +1,18 @@
|
||||
#!/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
|
||||
# Author: glabutis
|
||||
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
|
||||
# Source: https://github.com/bitfocus/companion
|
||||
|
||||
# App Default Values
|
||||
APP="Companion"
|
||||
var_tags="${var_tags:-automation;media}"
|
||||
# Tags for Proxmox VE (max 2, no spaces, semicolon-separated)
|
||||
var_cpu="${var_cpu:-2}"
|
||||
# Number of cores (default: 2)
|
||||
var_ram="${var_ram:-512}"
|
||||
# RAM in MB (default: 512)
|
||||
var_disk="${var_disk:-8}"
|
||||
# Disk space in GB (default: 8)
|
||||
var_os="${var_os:-debian}"
|
||||
# Default OS
|
||||
var_version="${var_version:-12}"
|
||||
# Default OS version
|
||||
var_unprivileged="${var_unprivileged:-1}"
|
||||
# 1 = unprivileged container, 0 = privileged
|
||||
|
||||
header_info "$APP"
|
||||
variables
|
||||
@@ -38,24 +30,15 @@ function update_script() {
|
||||
fi
|
||||
|
||||
RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20")
|
||||
RELEASE=$(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('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
|
||||
")
|
||||
PACKAGE_JSON=$(echo "$RELEASE_JSON" | jq -c '(if type == "array" then . else .packages end) | [.[] | select(.target=="linux-tgz" and (.uri | contains("linux-x64")))] | first')
|
||||
RELEASE=$(echo "$PACKAGE_JSON" | jq -r '.version // empty')
|
||||
ASSET_URL=$(echo "$PACKAGE_JSON" | jq -r '.uri // empty')
|
||||
if [[ -z "$RELEASE" || -z "$ASSET_URL" ]]; then
|
||||
msg_error "Could not resolve a matching Linux x64 Companion package from the Bitfocus API."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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}"
|
||||
exit
|
||||
fi
|
||||
@@ -65,23 +48,15 @@ for pkg in data.get('packages', data if isinstance(data, list) else []):
|
||||
msg_ok "Stopped ${APP}"
|
||||
|
||||
msg_info "Updating ${APP} to v${RELEASE}"
|
||||
rm -rf /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
|
||||
CLEAN_INSTALL=1 fetch_and_deploy_from_url "$ASSET_URL" "/opt/companion"
|
||||
chown -R companion:companion /opt/companion
|
||||
echo "${RELEASE}" >~/.companion
|
||||
msg_ok "Updated ${APP} to v${RELEASE}"
|
||||
|
||||
msg_info "Starting ${APP}"
|
||||
systemctl start companion
|
||||
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"
|
||||
exit
|
||||
}
|
||||
|
||||
@@ -15,47 +15,31 @@ update_os
|
||||
|
||||
msg_info "Installing Dependencies"
|
||||
$STD apt-get install -y \
|
||||
curl \
|
||||
sudo \
|
||||
mc \
|
||||
python3 \
|
||||
jq \
|
||||
libusb-1.0-0
|
||||
msg_ok "Installed Dependencies"
|
||||
|
||||
msg_info "Fetching Latest Bitfocus Companion Release"
|
||||
RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20")
|
||||
RELEASE=$(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('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."
|
||||
PACKAGE_JSON=$(echo "$RELEASE_JSON" | jq -c '(if type == "array" then . else .packages end) | [.[] | select(.target=="linux-tgz" and (.uri | contains("linux-x64")))] | first')
|
||||
RELEASE=$(echo "$PACKAGE_JSON" | jq -r '.version // empty')
|
||||
ASSET_URL=$(echo "$PACKAGE_JSON" | jq -r '.uri // empty')
|
||||
if [[ -z "$RELEASE" || -z "$ASSET_URL" ]]; then
|
||||
msg_error "Could not resolve a matching Linux x64 Companion package from the Bitfocus API."
|
||||
exit 1
|
||||
fi
|
||||
msg_ok "Found Companion v${RELEASE}"
|
||||
|
||||
msg_info "Downloading Bitfocus Companion v${RELEASE}"
|
||||
mkdir -p /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
|
||||
fetch_and_deploy_from_url "$ASSET_URL" "/opt/companion"
|
||||
msg_ok "Downloaded and Extracted Bitfocus Companion v${RELEASE}"
|
||||
|
||||
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_info "Creating companion User"
|
||||
@@ -90,12 +74,8 @@ EOF
|
||||
systemctl enable -q --now companion
|
||||
msg_ok "Created Service"
|
||||
|
||||
echo "${RELEASE}" >/opt/companion_version.txt
|
||||
echo "${RELEASE}" >~/.companion
|
||||
|
||||
motd_ssh
|
||||
customize
|
||||
|
||||
msg_info "Cleaning up"
|
||||
$STD apt-get -y autoremove
|
||||
$STD apt-get -y autoclean
|
||||
msg_ok "Cleaned"
|
||||
cleanup_lxc
|
||||
|
||||
Reference in New Issue
Block a user