From 66a7d5f9e2a12df4c6a8285f043c051ca0d2c16b Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 18 Aug 2024 19:51:38 -0500 Subject: [PATCH] Move-install-script-to-image-modifier (#25) Copy the install.sh script to here and redirect the image installation scripts to use this version. Clean up the redundancies in the install scripts. Once this is accepted, the https://git.io/JJrEP short URL should be updated to point to install.sh in this repo and it should be deleted from the Photonvision repo. --- install.sh | 203 ++++++++++++++++++++++++++++++++++++++++++ install_limelight.sh | 17 ++-- install_limelight3.sh | 1 + install_opi5.sh | 35 ++------ install_pi.sh | 18 ++-- install_snakeyes.sh | 1 + 6 files changed, 220 insertions(+), 55 deletions(-) create mode 100755 install.sh mode change 100644 => 100755 install_limelight3.sh mode change 100644 => 100755 install_snakeyes.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..43b9eee --- /dev/null +++ b/install.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +package_is_installed(){ + dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "ok installed" +} + +help() { + echo "This script installs Photonvision." + echo "It must be run as root." + echo + echo "Syntax: sudo ./install.sh [-h|m|n|q]" + echo " options:" + echo " -h Display this help message." + echo " -m Install and configure NetworkManager (Ubuntu only)." + echo " -n Disable networking. This will also prevent installation of NetworkManager." + echo " -q Silent install, automatically accepts all defaults. For non-interactive use." + echo +} + +INSTALL_NETWORK_MANAGER="false" + +while getopts ":hmnq" name; do + case "$name" in + h) + help + exit 0 + ;; + m) INSTALL_NETWORK_MANAGER="true" + ;; + n) DISABLE_NETWORKING="true" + ;; + q) QUIET="true" + ;; + \?) + echo "Error: Invalid option -- '$OPTARG'" + echo "Try './install.sh -h' for more information." + exit 1 + esac +done + +shift $(($OPTIND -1)) + +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +ARCH=$(uname -m) +ARCH_NAME="" +if [ "$ARCH" = "aarch64" ]; then + ARCH_NAME="linuxarm64" +elif [ "$ARCH" = "armv7l" ]; then + echo "ARM32 is not supported by PhotonVision. Exiting." + exit 1 +elif [ "$ARCH" = "x86_64" ]; then + ARCH_NAME="linuxx64" +else + if [ "$#" -ne 1 ]; then + echo "Can't determine current arch; please provide it (one of):" + echo "" + echo "- linuxarm64 (64-bit Linux ARM)" + echo "- linuxx64 (64-bit Linux)" + exit 1 + else + echo "Can't detect arch (got $ARCH) -- using user-provided $1" + ARCH_NAME=$1 + fi +fi + +echo "This is the installation script for PhotonVision." +echo "Installing for platform $ARCH_NAME" + +DISTRO=$(lsb_release -is) +if [[ "$DISTRO" = "Ubuntu" && "$INSTALL_NETWORK_MANAGER" != "true" && -z "$QUIET" && -z "$DISABLE_NETWORKING" ]]; then + echo "" + echo "Photonvision uses NetworkManager to control networking on your device." + read -p "Do you want this script to install and configure NetworkManager? [y/N]: " response + if [[ $response == [yY] || $response == [yY][eE][sS] ]]; then + INSTALL_NETWORK_MANAGER="true" + fi +fi + +echo "Update package list" +apt-get update + +echo "Installing curl..." +apt-get install --yes curl +echo "curl installation complete." + +echo "Installing avahi-daemon..." +apt-get install --yes avahi-daemon +echo "avahi-daemon installation complete." + +echo "Installing cpufrequtils..." +apt-get install --yes cpufrequtils +echo "cpufrequtils installation complete." + +echo "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 +fi + +echo "Installing libatomic" +apt-get install --yes libatomic1 +echo "libatomic installation complete." + +if [[ "$INSTALL_NETWORK_MANAGER" == "true" ]]; then + echo "Installing network-manager..." + apt-get install --yes network-manager net-tools + systemctl disable systemd-networkd-wait-online.service + cat > /etc/netplan/00-default-nm-renderer.yaml < /lib/systemd/system/photonvision.service < /etc/NetworkManager/conf.d/50-ignore-carrier.conf <