Skip to content

Instantly share code, notes, and snippets.

@cgobat
Last active October 11, 2023 16:03
Show Gist options
  • Save cgobat/72d5705e65822a4e06363a444b1d2022 to your computer and use it in GitHub Desktop.
Save cgobat/72d5705e65822a4e06363a444b1d2022 to your computer and use it in GitHub Desktop.
Raspberry Pi setup script for astronomy. Portions from https://github.com/rlancaste/AstroPi3. Run `git clone https://gist.github.com/72d5705e65822a4e06363a444b1d2022.git scripts` to start.
print("This script has moved to https://github.com/cgobat/astro-instruments/blob/main/AstroHQ/astro_hq.py")
#!/bin/bash
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
USERHOME=$(sudo -u $SUDO_USER -H bash -c 'echo $HOME')
echo "SUDO_USER: $SUDO_USER"
echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "USERHOME: $USERHOME"
sudo apt install -y libnova-dev libcfitsio-dev libusb-1.0-0-dev libusb-dev zlib1g-dev libgsl-dev build-essential cmake git libjpeg-dev libcurl4-gnutls-dev libtiff-dev
sudo apt install -y libftdi-dev libgps-dev libraw-dev libdc1394-22-dev libgphoto2-dev libboost-dev libboost-regex-dev librtlsdr-dev liblimesuite-dev libftdi1-dev
sudo apt install -y ffmpeg libavcodec-dev libavdevice-dev libfftw3-dev libev-dev
if [ ! -d $USERHOME/GitHub/indi ]; then
echo "Cloning indilib/indi from GitHub"
mkdir -p $USERHOME/Github
cd $USERHOME/GitHub
sudo -u $SUDO_USER git clone --depth=1 https://github.com/indilib/indi
else
echo "Pulling latest indilib/indi from GitHub"
fi
cd $USERHOME/GitHub/indi
sudo -u $SUDO_USER git pull
echo "Building and Installing Core LibINDI"
mkdir -p $USERHOME/GitHub/build/indi-core
cd $USERHOME/GitHub/build/indi-core
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo $ASTROROOT/indi
sudo make -j $(expr $(nproc) + 1)
sudo make install
#!/bin/bash
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
USERHOME=$(sudo -u $SUDO_USER -H bash -c 'echo $HOME')
DRIVER_NAME=$1
if [ ! -d $USERHOME/GitHub/indi-3rdparty ]; then
echo "Cloning indilib/indi-3rdparty from GitHub"
mkdir -p $USERHOME/GitHub
cd $USERHOME/GitHub
git clone --depth=1 https://github.com/indilib/indi-3rdparty
else
echo "Pulling latest indilib/indi-3rdparty from GitHub"
cd $USERHOME/GitHub/indi-3rdparty
git pull
fi
mkdir -p $USERHOME/GitHub/build/$DRIVER_NAME
cd $USERHOME/GitHub/build/$DRIVER_NAME
sudo -u $SUDO_USER cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug $USERHOME/GitHub/indi-3rdparty/$DRIVER_NAME
sudo -u $SUDO_USER make -j $(expr $(nproc) + 1)
sudo -u $SUDO_USER make install
echo "Finished building/installing $DRIVER_NAME"
# https://learn.adafruit.com/adafruit-mini-pitft-135x240-color-tft-add-on-for-raspberry-pi/python-stats
import time
import subprocess
import digitalio
import board
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import st7789
# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
# Config for display baudrate (default max is 24mhz):
BAUDRATE = 64000000
# Setup SPI bus using hardware SPI:
spi = board.SPI()
# Create the ST7789 display:
disp = st7789.ST7789(
spi,
cs=cs_pin,
dc=dc_pin,
rst=reset_pin,
baudrate=BAUDRATE,
width=135,
height=240,
x_offset=53,
y_offset=40,
)
#!/bin/bash
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
USERHOME=$(sudo -u $SUDO_USER -H bash -c 'echo $HOME')
echo "SUDO_USER: $SUDO_USER"
echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "USERHOME: $USERHOME"
while true
do
read -p "Do these vars look okay? [Y/N] " continue_exec
if [ $continue_exec = 'n' ] || [ $continue_exec = 'N' ]; then
exit
elif [ $continue_exec = 'y' ] || [ $continue_exec = 'Y' ]; then
break
else
echo "Choose Y/N"
fi
done
cd $USERHOME # go home
ASTROROOT=$USERHOME/AstroRoot
if [ ! -f "/etc/apt/sources.list.d/astroberry.list" ]; then
echo "Adding astroberry APT repository to sources"
wget -O - https://www.astroberry.io/repo/key | sudo apt-key add -
sudo su -c "echo 'deb https://www.astroberry.io/repo/ bullseye main' > /etc/apt/sources.list.d/astroberry.list"
sudo apt update -y
fi
read -p "Update APT packages? [Y/N] " update_apt
if [ $update_apt = 'y' ] || [ $update_apt = 'Y' ]; then
# update APT packages
sudo apt upgrade -y
sudo apt install -y libnova-dev libcfitsio-dev libusb-1.0-0-dev libusb-dev zlib1g-dev libgsl-dev build-essential cmake git libjpeg-dev libcurl4-gnutls-dev libtiff-dev
sudo apt install -y libftdi-dev libgps-dev libraw-dev libdc1394-22-dev libgphoto2-dev libboost-dev libboost-regex-dev librtlsdr-dev liblimesuite-dev libftdi1-dev
sudo apt install -y ffmpeg libavcodec-dev libavdevice-dev libfftw3-dev libev-dev
break
elif [ $update_apt = 'n' ] || [ $update_apt = 'N' ]; then
echo "Skipping APT update. Hopefully all requirements are already satisfied."
break
fi
read -p "Build/install INDI core? [Y/N] " install_indi
if [ $install_indi = 'y' ] || [ $install_indi = 'Y' ]; then
# get INDI
echo "Building and Installing INDI"
if [ ! -d $ASTROROOT ]; then
sudo -u $SUDO_USER mkdir $ASTROROOT
fi
if [ ! -d $ASTROROOT/indi ]
then
cd $ASTROROOT
sudo -u $SUDO_USER git clone --depth=1 https://github.com/indilib/indi
sudo -u $SUDO_USER mkdir -p $ASTROROOT/indi-build
fi
cd $ASTROROOT/indi
sudo -u $SUDO_USER git pull
echo "Building and Installing Core LibINDI"
sudo -u $SUDO_USER mkdir -p $ASTROROOT/indi-build/indi-core
cd $ASTROROOT/indi-build/indi-core
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo $ASTROROOT/indi
sudo make -j $(expr $(nproc) + 1)
sudo make install
else
echo "Skipping INDI core installation"
fi
read -p "Install *all* INDI 3rd-party drivers? [Y/N] " install_indi3p
if [ $install_indi3p = 'y' ] || [ $install_indi3p = 'Y' ]; then
# This builds and installs INDI 3rd Party
echo "Building and Installing INDI 3rd Party"
if [ ! -d $ASTROROOT/indi-3rdparty ]; then
cd $ASTROROOT
sudo -u $SUDO_USER git clone --depth=1 https://github.com/indilib/indi-3rdparty
sudo -u $SUDO_USER mkdir -p $ASTROROOT/indi-build
fi
cd $ASTROROOT/indi-3rdparty
sudo -u $SUDO_USER git pull
sudo -u $SUDO_USER mkdir -p $ASTROROOT/indi-build/3rdparty-Libraries
cd $ASTROROOT/indi-build/3rdparty-Libraries
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_LIBS=1 $ASTROROOT/indi-3rdparty
sudo make -j $(expr $(nproc) + 1)
sudo make install
fi
read -p "Install/set up Python modules? [Y/N] " pip_install
if [ $pip_install = 'y' ] || [ $pip_install = 'Y' ]; then
# set up Adafruit Mini PiTFT
echo "Setting up PiTFT display"
sudo -u $SUDO_USER pip install --upgrade spidev adafruit-circuitpython-rgb-display Pillow
sudo apt install -y fonts-dejavu
if [ -f "$SCRIPT_DIR/pitft.py" ]; then
if [ -f "$USERHOME/bin/pitft.py" ]; then
rm -f $USERHOME/bin/pitft.py
fi
if [ ! -d $USERHOME/bin ]; then
mkdir $USERHOME/bin
fi
cp $SCRIPT_DIR/pitft.py $USERHOME/bin/
fi
break
else
echo "Skipping Python setup"
break
fi
echo "Cleaning up..."
sudo apt autoremove
while true
do
read -p "Done. Reboot now? [Y/N] " reboot_now
if [ $reboot_now = 'n' ] || [ $reboot_now = 'N' ]; then
exit
elif [ $reboot_now = 'y' ] || [ $reboot_now = 'Y' ]; then
sudo shutdown -r now
else
echo "Choose Y/N"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment