Files
ProxmoxVEDHelperScripts/ct/companion.sh
Grant Labutis 7970b1b9e0 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
2026-03-23 14:31:46 -04:00

72 lines
2.2 KiB
Bash

#!/usr/bin/env bash
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="Companion"
var_tags="${var_tags:-automation;media}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-512}"
var_disk="${var_disk:-8}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -f /opt/companion/companion_headless.sh ]]; then
msg_error "No ${APP} Installation Found!"
exit 1
fi
RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20")
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 ~/.companion 2>/dev/null)" ]]; then
msg_ok "No update required. ${APP} is already at v${RELEASE}"
exit
fi
msg_info "Stopping ${APP}"
systemctl stop companion
msg_ok "Stopped ${APP}"
msg_info "Updating ${APP} to v${RELEASE}"
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_ok "Update Successful"
exit
}
start
build_container
description
msg_ok "Completed successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8000${CL}"