From 44cbde1ec8c9c0b2c19edee3aadd1058df782451 Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:36:47 -0400 Subject: [PATCH 1/9] feat: add Bitfocus Companion LXC installer --- ct/companion.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ct/companion.sh diff --git a/ct/companion.sh b/ct/companion.sh new file mode 100644 index 00000000..39810015 --- /dev/null +++ b/ct/companion.sh @@ -0,0 +1,67 @@ +#!/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}" +var_keyctl="${var_keyctl:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + + if [[ ! -d /opt/companion ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + + CURRENT="" + [[ -f /opt/companion-config/version.txt ]] && CURRENT=$(cat /opt/companion-config/version.txt) + + RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") + LATEST=$(echo "$RELEASE_JSON" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') + + if [[ "$CURRENT" == "$LATEST" ]]; then + msg_ok "Already running Bitfocus Companion ${LATEST} — no update needed." + exit + fi + + ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') + + msg_info "Updating ${APP} to ${LATEST}" + systemctl stop companion + 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 + chown -R companion:companion /opt/companion + systemctl start companion + echo "${LATEST}" >/opt/companion-config/version.txt + msg_ok "Updated ${APP} to ${LATEST}" + 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}" From 6fa8bc3d0c518a6453089f1a308e25b090622e40 Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:36:47 -0400 Subject: [PATCH 2/9] feat: add Bitfocus Companion install script --- install/companion-install.sh | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 install/companion-install.sh diff --git a/install/companion-install.sh b/install/companion-install.sh new file mode 100644 index 00000000..9cfdfc35 --- /dev/null +++ b/install/companion-install.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# 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 + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get install -y \ + 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" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') +ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') + +if [[ -z "$ASSET_URL" ]]; then + msg_error "Could not locate a Linux x64 release from the Bitfocus API." + exit 1 +fi +msg_ok "Found Companion ${RELEASE}" + +msg_info "Downloading Bitfocus Companion ${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 +msg_ok "Downloaded and Extracted Bitfocus Companion ${RELEASE}" + +msg_info "Installing udev Rules" +[[ -f /opt/companion/50-companion-headless.rules ]] && cp /opt/companion/50-companion-headless.rules /etc/udev/rules.d/ +msg_ok "Installed udev Rules" + +msg_info "Creating companion User" +useradd --system --no-create-home --shell /usr/sbin/nologin companion 2>/dev/null || true +mkdir -p /opt/companion-config +chown -R companion:companion /opt/companion-config +chown -R companion:companion /opt/companion +msg_ok "Created companion User" + +msg_info "Creating Service" +cat </etc/systemd/system/companion.service +[Unit] +Description=Bitfocus Companion +After=network.target +Wants=network-online.target + +[Service] +Type=simple +User=companion +ExecStart=/opt/companion/companion_headless.sh --config-dir /opt/companion-config +WorkingDirectory=/opt/companion +Restart=on-failure +RestartSec=5 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=companion +Environment=NODE_ENV=production + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now companion +msg_ok "Created Service" + +echo "${RELEASE}" >/opt/companion-config/version.txt + +motd_ssh +customize +cleanup_lxc From 8c3de2e51ac9d42ecad0e11f6108ff24aa4a16b0 Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:36:48 -0400 Subject: [PATCH 3/9] feat: add Bitfocus Companion metadata --- json/companion.json | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 json/companion.json diff --git a/json/companion.json b/json/companion.json new file mode 100644 index 00000000..1c5f5e5c --- /dev/null +++ b/json/companion.json @@ -0,0 +1,43 @@ +{ + "name": "Bitfocus Companion", + "slug": "companion", + "categories": [ + 12 + ], + "date_created": "2026-03-16", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 8000, + "documentation": "https://user.bitfocus.io/docs", + "website": "https://bitfocus.io/companion", + "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/bitfocus-companion.webp", + "description": "Bitfocus Companion enables Stream Decks and other controllers to trigger actions in broadcast software. Installs headless with systemd, fetching the latest release from the Bitfocus API.", + "install_methods": [ + { + "type": "default", + "script": "ct/companion.sh", + "resources": { + "cpu": 2, + "ram": 512, + "hdd": 8, + "os": "Debian", + "version": "12" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "Companion v4.x downloads are served through the Bitfocus API, not GitHub Releases.", + "type": "info" + }, + { + "text": "Requires libusb for USB device (Stream Deck) bindings.", + "type": "info" + } + ] +} From 955fd17d34ca062ecf82ab59a5d2fe4752cf688f Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:39:40 -0400 Subject: [PATCH 4/9] fix: align with contribution standards --- ct/companion.sh | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/ct/companion.sh b/ct/companion.sh index 39810015..f0c03115 100644 --- a/ct/companion.sh +++ b/ct/companion.sh @@ -1,19 +1,26 @@ #!/usr/bin/env bash -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) +source <(curl -s 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}" -var_keyctl="${var_keyctl:-1}" +# 1 = unprivileged container, 0 = privileged header_info "$APP" variables @@ -25,35 +32,44 @@ function update_script() { check_container_storage check_container_resources - if [[ ! -d /opt/companion ]]; then + if [[ ! -f /opt/companion/companion_headless.sh ]]; then msg_error "No ${APP} Installation Found!" exit fi - CURRENT="" - [[ -f /opt/companion-config/version.txt ]] && CURRENT=$(cat /opt/companion-config/version.txt) - RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") - LATEST=$(echo "$RELEASE_JSON" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') + RELEASE=$(echo "$RELEASE_JSON" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') - if [[ "$CURRENT" == "$LATEST" ]]; then - msg_ok "Already running Bitfocus Companion ${LATEST} — no update needed." + if [[ "${RELEASE}" == "$(cat /opt/companion_version.txt 2>/dev/null)" ]]; then + msg_ok "No update required. ${APP} is already at v${RELEASE}" exit fi ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') - msg_info "Updating ${APP} to ${LATEST}" + msg_info "Stopping ${APP}" systemctl stop companion + 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 chown -R companion:companion /opt/companion + msg_ok "Updated ${APP} to v${RELEASE}" + + msg_info "Starting ${APP}" systemctl start companion - echo "${LATEST}" >/opt/companion-config/version.txt - msg_ok "Updated ${APP} to ${LATEST}" + 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 } @@ -61,7 +77,7 @@ start build_container description -msg_ok "Completed Successfully!\n" +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}" From 2d96d881c2a0e15f81682c480e99bee5cfe8b94f Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:39:41 -0400 Subject: [PATCH 5/9] fix: align with contribution standards --- install/companion-install.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/install/companion-install.sh b/install/companion-install.sh index 9cfdfc35..73099d08 100644 --- a/install/companion-install.sh +++ b/install/companion-install.sh @@ -15,6 +15,9 @@ update_os msg_info "Installing Dependencies" $STD apt-get install -y \ + curl \ + sudo \ + mc \ libusb-1.0-0 msg_ok "Installed Dependencies" @@ -27,14 +30,14 @@ if [[ -z "$ASSET_URL" ]]; then msg_error "Could not locate a Linux x64 release from the Bitfocus API." exit 1 fi -msg_ok "Found Companion ${RELEASE}" +msg_ok "Found Companion v${RELEASE}" -msg_info "Downloading Bitfocus Companion ${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 -msg_ok "Downloaded and Extracted Bitfocus Companion ${RELEASE}" +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/ @@ -72,8 +75,12 @@ EOF systemctl enable -q --now companion msg_ok "Created Service" -echo "${RELEASE}" >/opt/companion-config/version.txt +echo "${RELEASE}" >/opt/companion_version.txt motd_ssh customize -cleanup_lxc + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" From f071b5df349380e7272b34d202d09d6485bdbba1 Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:39:42 -0400 Subject: [PATCH 6/9] fix: correct category (19=Automation), lowercase os, cleanup --- json/companion.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json/companion.json b/json/companion.json index 1c5f5e5c..d6489334 100644 --- a/json/companion.json +++ b/json/companion.json @@ -2,7 +2,7 @@ "name": "Bitfocus Companion", "slug": "companion", "categories": [ - 12 + 19 ], "date_created": "2026-03-16", "type": "ct", @@ -11,8 +11,8 @@ "interface_port": 8000, "documentation": "https://user.bitfocus.io/docs", "website": "https://bitfocus.io/companion", - "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/bitfocus-companion.webp", - "description": "Bitfocus Companion enables Stream Decks and other controllers to trigger actions in broadcast software. Installs headless with systemd, fetching the latest release from the Bitfocus API.", + "logo": "https://raw.githubusercontent.com/bitfocus/companion/main/assets/icon.png", + "description": "Bitfocus Companion enables the Elgato Stream Deck and other controllers to trigger actions in broadcast software. Installs headless with a dedicated system user and systemd service, fetching the latest release via the Bitfocus API.", "install_methods": [ { "type": "default", @@ -21,7 +21,7 @@ "cpu": 2, "ram": 512, "hdd": 8, - "os": "Debian", + "os": "debian", "version": "12" } } From 7d0e8ba7bbce78519785c477ea3782c6691cf59f Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:55:09 -0400 Subject: [PATCH 7/9] fix: exit 1 on missing install, robust JSON parsing via python3 --- ct/companion.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ct/companion.sh b/ct/companion.sh index f0c03115..6e0cbf88 100644 --- a/ct/companion.sh +++ b/ct/companion.sh @@ -34,19 +34,32 @@ function update_script() { if [[ ! -f /opt/companion/companion_headless.sh ]]; then msg_error "No ${APP} Installation Found!" - exit + exit 1 fi RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") - RELEASE=$(echo "$RELEASE_JSON" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') + 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 [[ "${RELEASE}" == "$(cat /opt/companion_version.txt 2>/dev/null)" ]]; then msg_ok "No update required. ${APP} is already at v${RELEASE}" exit fi - ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') - msg_info "Stopping ${APP}" systemctl stop companion msg_ok "Stopped ${APP}" From 5987230f99a2c8e62c793c200e3d9faaed9e37d9 Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:55:10 -0400 Subject: [PATCH 8/9] fix: parse API JSON by package object to ensure version/URL stay in sync --- install/companion-install.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/install/companion-install.sh b/install/companion-install.sh index 73099d08..1c9ddd31 100644 --- a/install/companion-install.sh +++ b/install/companion-install.sh @@ -18,13 +18,28 @@ $STD apt-get install -y \ curl \ sudo \ mc \ + python3 \ 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" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') -ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') +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." From 7970b1b9e0700804f52869128a5e7a5412bf998a Mon Sep 17 00:00:00 2001 From: Grant Labutis Date: Mon, 23 Mar 2026 14:31:46 -0400 Subject: [PATCH 9/9] 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 --- ct/companion.sh | 47 +++++++++-------------------------- install/companion-install.sh | 48 +++++++++++------------------------- 2 files changed, 25 insertions(+), 70 deletions(-) diff --git a/ct/companion.sh b/ct/companion.sh index 6e0cbf88..83cbffe1 100644 --- a/ct/companion.sh +++ b/ct/companion.sh @@ -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 } diff --git a/install/companion-install.sh b/install/companion-install.sh index 1c9ddd31..ec3cfee8 100644 --- a/install/companion-install.sh +++ b/install/companion-install.sh @@ -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