Skip to content

Commit

Permalink
Move-install-script-to-image-modifier (PhotonVision#25)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crschardt authored Aug 19, 2024
1 parent 8601dc9 commit 66a7d5f
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 55 deletions.
203 changes: 203 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
network:
renderer: NetworkManager
EOF
echo "network-manager installation complete."
fi

echo "Installing the JRE..."
if ! package_is_installed openjdk-17-jre-headless
then
apt-get install --yes openjdk-17-jre-headless
fi
echo "JRE installation complete."

echo "Installing additional math packages"
if [[ "$DISTRO" = "Ubuntu" && -z $(apt-cache search libcholmod3) ]]; then
echo "Adding jammy to list of apt sources"
add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe'
apt-get --quiet update
fi
apt-get install --yes libcholmod3 liblapack3 libsuitesparseconfig5

echo "Installing v4l-utils..."
apt-get install --yes v4l-utils
echo "v4l-utils installation complete."

echo "Installing sqlite3"
apt-get install --yes sqlite3

echo "Downloading latest stable release of PhotonVision..."
mkdir -p /opt/photonvision
cd /opt/photonvision
curl -sk https://api.github.com/repos/photonvision/photonvision/releases/latest |
grep "browser_download_url.*$ARCH_NAME.jar" |
cut -d : -f 2,3 |
tr -d '"' |
wget -qi - -O photonvision.jar
echo "Downloaded latest stable release of PhotonVision."

echo "Creating the PhotonVision systemd service..."

# service --status-all doesn't list photonvision on OrangePi use systemctl instead:
if systemctl --quiet is-active photonvision; then
echo "PhotonVision is already running. Stopping service."
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

cat > /lib/systemd/system/photonvision.service <<EOF
[Unit]
Description=Service that runs PhotonVision
[Service]
WorkingDirectory=/opt/photonvision
# Run photonvision at "nice" -10, which is higher priority than standard
Nice=-10
# for non-uniform CPUs, like big.LITTLE, you want to select the big cores
# look up the right values for your CPU
# AllowedCPUs=4-7
ExecStart=/usr/bin/java -Xmx512m -jar /opt/photonvision/photonvision.jar
ExecStop=/bin/systemctl kill photonvision
Type=simple
Restart=on-failure
RestartSec=1
[Install]
WantedBy=multi-user.target
EOF

if [ "$DISABLE_NETWORKING" = "true" ]; then
sed -i "s/photonvision.jar/photonvision.jar -n/" /lib/systemd/system/photonvision.service
fi

if [[ -n $(cat /proc/cpuinfo | grep "RK3588") ]]; then
echo "This has a Rockchip RK3588, enabling high A76 cores"
sed -i 's/# AllowedCPUs=4-7/AllowedCPUs=4-7/g' /lib/systemd/system/photonvision.service
fi

cp /lib/systemd/system/photonvision.service /etc/systemd/system/photonvision.service
chmod 644 /etc/systemd/system/photonvision.service
systemctl daemon-reload
systemctl enable photonvision.service

echo "Created PhotonVision systemd service."

echo "PhotonVision installation successful."
17 changes: 5 additions & 12 deletions install_limelight.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Run normal photon installer

wget https://git.io/JJrEP -O install.sh
chmod +x install.sh
./install.sh
rm install.sh


chmod +x ./install.sh
./install.sh -q

# edit boot partition
install -m 644 limelight/config.txt /boot/
Expand Down Expand Up @@ -34,12 +29,10 @@ apt-get autoremove -y
echo "Installing additional things"
sudo apt-get update
apt-get install -y pigpiod pigpio device-tree-compiler libraspberrypi-bin
apt-get install -y network-manager
apt-get install -y net-tools
apt-get install -y network-manager net-tools
# libcamera-driver stuff
apt-get install -y libegl1 libopengl0 libopencv-core406 libgl1-mesa-dri libcamera0.1 libgbm1 libatomic1
# mrcal stuff
apt-get install -y libcholmod3 liblapack3 libsuitesparseconfig5
apt-get install -y libegl1 libopengl0 libopencv-core406 libgl1-mesa-dri libcamera0.1 libgbm1


rm -rf /var/lib/apt/lists/*
apt-get clean
Expand Down
1 change: 1 addition & 0 deletions install_limelight3.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Run the pi install script
chmod +x ./install_pi.sh
./install_pi.sh

# Add the one extra file for the LL3
Expand Down
35 changes: 5 additions & 30 deletions install_opi5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@ freed=$(( before - after ))
echo "Freed up $freed KiB"

# run Photonvision install script
wget https://git.io/JJrEP -O install.sh
chmod +x install.sh

sed -i 's/# AllowedCPUs=4-7/AllowedCPUs=0-7/g' install.sh

chmod +x ./install.sh
./install.sh -m -q
rm install.sh

echo "Installing additional things"

apt-get install --yes --quiet network-manager net-tools libatomic1
apt-get install --yes --quiet libc6 libstdc++6

# let netplan create the config during cloud-init
rm -f /etc/netplan/00-default-nm-renderer.yaml
Expand All @@ -54,17 +48,12 @@ cp -f ./OPi5_CIDATA/network-config /boot/network-config
# add customized user-data file for cloud-init
cp -f ./OPi5_CIDATA/user-data /boot/user-data

# tell NetworkManager not to wait for the carrier on ethernet, which can delay boot
# when the coprocessor isn't connected to the ethernet
# cat > /etc/NetworkManager/conf.d/50-ignore-carrier.conf <<EOF
# [main]
# ignore-carrier=*
# EOF

# modify photonvision.service to wait for the network before starting
# this helps ensure that photonvision detects the network the first time it starts
# but it may cause a startup delay if the coprocessor isn't connected to a network
sed -i '/Description/aAfter=network-online.target' /etc/systemd/system/photonvision.service
sed -i '/Description/aAfter=network-online.target' /lib/systemd/system/photonvision.service
cp /lib/systemd/system/photonvision.service /etc/systemd/system/photonvision.service
chmod 644 /etc/systemd/system/photonvision.service
cat /etc/systemd/system/photonvision.service

# networkd isn't being used, this causes an unnecessary delay
Expand All @@ -73,20 +62,6 @@ systemctl disable systemd-networkd-wait-online.service
# the bluetooth service isn't needed and causes a delay at boot
systemctl disable ap6275p-bluetooth.service

apt-get install --yes --quiet libc6 libstdc++6

if [ $(cat /etc/lsb-release | grep -c "24.04") -gt 0 ]; then
# add jammy to apt sources
echo "Adding jammy to list of apt sources"
add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe'
fi

apt-get --quiet update

# mrcal stuff
apt-get install --yes --quiet libcholmod3 liblapack3 libsuitesparseconfig5


rm -rf /var/lib/apt/lists/*
apt-get --yes --quiet clean

Expand Down
18 changes: 5 additions & 13 deletions install_pi.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Run normal photon installer

wget https://git.io/JJrEP -O install.sh
chmod +x install.sh
./install.sh
rm install.sh

chmod +x ./install.sh
./install.sh -q

# and edit boot partition
install -m 644 config.txt /boot/
Expand All @@ -23,20 +19,16 @@ systemctl enable ssh
systemctl enable pigpiod

# Remove extra packages too

echo "Purging extra things"
apt-get purge -y python3 gdb gcc g++ linux-headers* libgcc*-dev device-tree-compiler
apt-get autoremove -y

echo "Installing additional things"
sudo apt-get update
apt-get install -y pigpiod pigpio device-tree-compiler libraspberrypi-bin
apt-get install -y network-manager
apt-get install -y net-tools
# libcamera-driver stuff + libatomic1 for wpilib
apt-get install -y libegl1 libopengl0 libopencv-core406 libgl1-mesa-dri libcamera0.1 libgbm1 libatomic1
# mrcal stuff
apt-get install -y libcholmod3 liblapack3 libsuitesparseconfig5
apt-get install -y network-manager net-tools
# libcamera-driver stuff
apt-get install -y libegl1 libopengl0 libopencv-core406 libgl1-mesa-dri libcamera0.1 libgbm1


rm -rf /var/lib/apt/lists/*
Expand Down
1 change: 1 addition & 0 deletions install_snakeyes.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Run the pi install script
chmod +x ./install_pi.sh
./install_pi.sh

# Add the one extra file for the snakeyes hardware config
Expand Down

0 comments on commit 66a7d5f

Please sign in to comment.