From 1dff52dd17d8e2debea7bda9424f436a9953a174 Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 18:02:26 -0600 Subject: [PATCH 1/8] Fix checking for releases --- install.sh | 191 +++++++++++++++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 85 deletions(-) diff --git a/install.sh b/install.sh index cb8f650d..027cf6ef 100755 --- a/install.sh +++ b/install.sh @@ -20,7 +20,7 @@ die() { debug() { if [ -z "$QUIET" ] ; then for arg in "$@"; do - echo "$arg" + echo "$TEST$arg" done fi } @@ -34,15 +34,19 @@ install_if_missing() { debug "Found existing $1. Skipping..." # Always mark our upstream apt deps as held back, which will prevent the package # from being automatically installed, upgraded or removed - apt-mark manual "$1" + if [[ -z $TEST ]]; then + apt-mark manual "$1" + fi return fi debug "Installing $1..." - apt-get install --yes "$1" - # Always mark our upstream apt deps as held back, which will prevent the package - # from being automatically installed, upgraded or removed - apt-mark manual "$1" + if [[ -z $TEST ]]; then + apt-get install --yes "$1" + # Always mark our upstream apt deps as held back, which will prevent the package + # from being automatically installed, upgraded or removed + apt-mark manual "$1" + fi debug "$1 installation complete." } @@ -64,31 +68,15 @@ get_photonvision_releases() { } get_versions() { - if [ -z "$PHOTON_VISION_VERSIONS" ] ; then - PHOTON_VISION_VERSIONS=$(get_photonvision_releases | \ - sed -En 's/\"tag_name\": \"v([0-9]+\.[0-9]+\.[0-9]+)(-(beta|alpha)(-[0-9])?(\.[0-9]+)?)?\",/\1\2/p' | \ - sed 's/^[[:space:]]*//') - fi + PHOTON_VISION_RELEASES="$(wget -qO- https://api.github.com/repos/photonvision/photonvision/releases?per_page=$1)" + PHOTON_VISION_VERSIONS=$(get_photonvision_releases | \ + sed -En 's/\"tag_name\": \"(Dev|v.+)\",/\1/p' | \ + sed 's/^[[:space:]]*//' + ) echo "$PHOTON_VISION_VERSIONS" } -is_version_available() { - local target_version="$1" - - # latest is a special case - if [ "$target_version" = "latest" ]; then - return 0 - fi - - # Check if multiple lines are match. You can only match 1. - if [ "$(get_versions | grep -cFx "$target_version")" -ne 1 ] ; then - return 1 - fi - - return 0 -} - is_chroot() { if systemd-detect-virt -r; then return 0 @@ -106,12 +94,13 @@ Syntax: sudo ./install.sh [options] options: -h, --help Display this help message. - -l, --list-versions - Lists all available versions of PhotonVision. + -l [count], --list-versions=[count] + Lists the most recent versions of PhotonVision. + Count: Number of recent versions to show, max value is 100. + Default: 30 -v , --version= Specifies which version of PhotonVision to install. If not specified, the latest stable release is installed. - Ignores leading 'v's. -a , --arch= Install PhotonVision for the specified architecture. Supported values: aarch64, x86_64 @@ -133,11 +122,17 @@ EOF INSTALL_NETWORK_MANAGER="ask" VERSION="latest" -while getopts "hlv:a:mnq-:" OPT; do +while getopts "hlv:a:mnqt-:" OPT; do if [ "$OPT" = "-" ]; then OPT="${OPTARG%%=*}" # extract long option name OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + else + nextopt=${!OPTIND} # check for an optional argument followinng a short option + if [[ -n $nextopt && $nextopt != -* ]]; then + OPTIND=$((OPTIND + 1)) + OPTARG=$nextopt + fi fi case "$OPT" in @@ -146,17 +141,19 @@ while getopts "hlv:a:mnq-:" OPT; do exit 0 ;; l | list-versions) - get_versions + COUNT=${OPTARG:-30} + get_versions "$COUNT" exit 0 ;; v | version) needs_arg - VERSION=${OPTARG#v} # drop leading 'v's + VERSION=${OPTARG} ;; a | arch) needs_arg; ARCH=$OPTARG ;; m | install-nm) - INSTALL_NETWORK_MANAGER="$(echo "${OPTARG:-'yes'}" | tr '[:upper:]' '[:lower:]')" + INSTALL_NETWORK_MANAGER="$(echo "${OPTARG:-yes}" | tr '[:upper:]' '[:lower:]')" + echo "$INSTALL_NETWORK_MANAGER" case "$INSTALL_NETWORK_MANAGER" in yes) ;; @@ -173,6 +170,8 @@ while getopts "hlv:a:mnq-:" OPT; do ;; q | quiet) QUIET="true" ;; + t | test) TEST="[TEST]:" + ;; \?) # Handle invalid short options die "Error: Invalid option -$OPTARG" \ "See './install.sh -h' for more information." @@ -184,7 +183,7 @@ while getopts "hlv:a:mnq-:" OPT; do esac done -if [ "$(id -u)" != "0" ]; then +if [[ "$(id -u)" != "0" && -z $TEST ]]; then die "This script must be run as root" fi @@ -214,6 +213,24 @@ fi debug "This is the installation script for PhotonVision." debug "Installing for platform $ARCH" +# make sure that we are downloading a valid version +if [ "$VERSION" = "latest" ] ; then + RELEASE_URL="https://api.github.com/repos/photonvision/photonvision/releases/latest" +else + RELEASE_URL="https://api.github.com/repos/photonvision/photonvision/releases/tags/$VERSION" +fi + +DOWNLOAD_URL=$(curl -sk "$RELEASE_URL" | + grep "browser_download_url.*$ARCH_NAME.jar" | + cut -d : -f 2,3 | + tr -d '"' + ) + +if [[ -z $DOWNLOAD_URL ]] ; then + die "PhotonVision '$VERSION' is not available for $ARCH_NAME!" \ + "See ./install --list-versions for a complete list of available versions." +fi + DISTRO=$(lsb_release -is) # Only ask if it makes sense to do so. @@ -236,7 +253,9 @@ if [[ "$INSTALL_NETWORK_MANAGER" == "ask" ]]; then fi debug "Updating package list..." -apt-get update +if [[ -z $TEST ]]; then + apt-get update +fi debug "Updated package list." install_if_missing curl @@ -248,10 +267,12 @@ install_if_missing sqlite3 install_if_missing openjdk-17-jre-headless debug "Setting cpufrequtils to performance mode" -if [ -f /etc/default/cpufrequtils ]; then - sed -i -e 's/^#\?GOVERNOR=.*$/GOVERNOR=performance/' /etc/default/cpufrequtils -else - echo 'GOVERNOR=performance' > /etc/default/cpufrequtils +if [[ -z $TEST ]]; then + if [ -f /etc/default/cpufrequtils ]; then + sed -i -e 's/^#\?GOVERNOR=.*$/GOVERNOR=performance/' /etc/default/cpufrequtils + else + echo 'GOVERNOR=performance' > /etc/default/cpufrequtils + fi fi if [[ "$INSTALL_NETWORK_MANAGER" == "yes" ]]; then @@ -260,21 +281,25 @@ if [[ "$INSTALL_NETWORK_MANAGER" == "yes" ]]; then install_if_missing net-tools debug "Configuring..." - systemctl disable systemd-networkd-wait-online.service - if [[ -d /etc/netplan/ ]]; then - cat > /etc/netplan/00-default-nm-renderer.yaml < /etc/netplan/00-default-nm-renderer.yaml < /lib/systemd/system/photonvision.service < /lib/systemd/system/photonvision.service < Date: Sun, 26 Jan 2025 18:11:26 -0600 Subject: [PATCH 2/8] document test mode --- install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.sh b/install.sh index 027cf6ef..d3765439 100755 --- a/install.sh +++ b/install.sh @@ -115,6 +115,9 @@ Syntax: sudo ./install.sh [options] -q, --quiet Silent install, automatically accepts all defaults. For non-interactive use. Makes -m,--install-nm default to "no". + -t, --test + Run in test mode. All actions that make chnages to the system + are suppressed. EOF } From 8dff268f5431eeb316464d0e14c281a8c97161ca Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 18:49:17 -0600 Subject: [PATCH 3/8] show every tag --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index d3765439..7003adba 100755 --- a/install.sh +++ b/install.sh @@ -71,7 +71,7 @@ get_versions() { PHOTON_VISION_RELEASES="$(wget -qO- https://api.github.com/repos/photonvision/photonvision/releases?per_page=$1)" PHOTON_VISION_VERSIONS=$(get_photonvision_releases | \ - sed -En 's/\"tag_name\": \"(Dev|v.+)\",/\1/p' | \ + sed -En 's/\"tag_name\": \"(.+)\",/\1/p' | \ sed 's/^[[:space:]]*//' ) echo "$PHOTON_VISION_VERSIONS" From 2235a0f7960923e3149905f69d148501ebb04c97 Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 19:52:09 -0600 Subject: [PATCH 4/8] Verbose is too much when running as a script --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 7003adba..80459900 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Verbose and exit on errors -set -ex +# Exit on errors +set -e needs_arg() { if [ -z "$OPTARG" ]; then From f1251b459b8b4704c88eeb692b91c49f4e45dd48 Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 19:55:11 -0600 Subject: [PATCH 5/8] minor corrections --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 80459900..bba384d2 100755 --- a/install.sh +++ b/install.sh @@ -231,7 +231,7 @@ DOWNLOAD_URL=$(curl -sk "$RELEASE_URL" | if [[ -z $DOWNLOAD_URL ]] ; then die "PhotonVision '$VERSION' is not available for $ARCH_NAME!" \ - "See ./install --list-versions for a complete list of available versions." + "See ./install --list-versions for a list of available versions." fi DISTRO=$(lsb_release -is) @@ -311,7 +311,7 @@ install_if_missing libsuitesparseconfig5 debug "" -debug "Downloading PhotonVision '$VERSION' ..." +debug "Downloading PhotonVision '$VERSION'..." if [[ -z $TEST ]]; then mkdir -p /opt/photonvision From 7bfafccdf5d7657269bfe2e9cfa0a55339ae1b0a Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 20:07:34 -0600 Subject: [PATCH 6/8] little more cleanup --- install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install.sh b/install.sh index bba384d2..d239bcc0 100755 --- a/install.sh +++ b/install.sh @@ -156,7 +156,6 @@ while getopts "hlv:a:mnqt-:" OPT; do ;; m | install-nm) INSTALL_NETWORK_MANAGER="$(echo "${OPTARG:-yes}" | tr '[:upper:]' '[:lower:]')" - echo "$INSTALL_NETWORK_MANAGER" case "$INSTALL_NETWORK_MANAGER" in yes) ;; From d9573929ffe0e883eae104bd7f8d5315f4b15c26 Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 26 Jan 2025 20:27:05 -0600 Subject: [PATCH 7/8] remove unused function --- install.sh | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/install.sh b/install.sh index d239bcc0..598f369a 100755 --- a/install.sh +++ b/install.sh @@ -50,23 +50,6 @@ install_if_missing() { debug "$1 installation complete." } -get_photonvision_releases() { - # Return cached input - if [ -n "$PHOTON_VISION_RELEASES" ] ; then - echo "$PHOTON_VISION_RELEASES" - return - fi - - # Use curl if available, otherwise fallback to wget - if command -v curl > /dev/null 2>&1 ; then - PHOTON_VISION_RELEASES="$(curl -sk https://api.github.com/repos/photonvision/photonvision/releases)" - else - PHOTON_VISION_RELEASES="$(wget -qO- https://api.github.com/repos/photonvision/photonvision/releases)" - fi - - echo "$PHOTON_VISION_RELEASES" -} - get_versions() { PHOTON_VISION_RELEASES="$(wget -qO- https://api.github.com/repos/photonvision/photonvision/releases?per_page=$1)" @@ -185,6 +168,8 @@ while getopts "hlv:a:mnqt-:" OPT; do esac done +debug "This is the installation script for PhotonVision." + if [[ "$(id -u)" != "0" && -z $TEST ]]; then die "This script must be run as root" fi @@ -212,7 +197,6 @@ else "Run './install.sh -h' for more information." fi -debug "This is the installation script for PhotonVision." debug "Installing for platform $ARCH" # make sure that we are downloading a valid version @@ -278,7 +262,7 @@ if [[ -z $TEST ]]; then fi if [[ "$INSTALL_NETWORK_MANAGER" == "yes" ]]; then - debug "NetworkManager installation specified. Installing components..." + debug "NetworkManager installation requested. Installing components..." install_if_missing network-manager install_if_missing net-tools @@ -330,14 +314,12 @@ if [[ -z $TEST ]]; then # service --status-all doesn't list photonvision on OrangePi use systemctl instead: if [[ $(systemctl --quiet is-active photonvision) = "active" ]]; then debug "PhotonVision is already running. Stopping service." - if [[ -z $TEST ]]; then systemctl stop photonvision systemctl disable photonvision rm /lib/systemd/system/photonvision.service rm /etc/systemd/system/photonvision.service systemctl daemon-reload systemctl reset-failed - fi fi cat > /lib/systemd/system/photonvision.service < Date: Sat, 1 Feb 2025 20:12:47 -0600 Subject: [PATCH 8/8] use correct repository for x86 --- install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 598f369a..d3866d53 100755 --- a/install.sh +++ b/install.sh @@ -284,7 +284,11 @@ debug "Installing additional math packages" if [[ "$DISTRO" = "Ubuntu" && -z $(apt-cache search libcholmod3) ]]; then debug "Adding jammy to list of apt sources" if [[ -z $TEST ]]; then - add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe' + if [[ "$ARCH" = "x86_64" ]]; then + add-apt-repository -y -S 'deb http://security.ubuntu.com/ubuntu jammy main universe' + else + add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe' + fi fi fi