an eink camera running on an rpi zero 2 w
at main 3.3 kB view raw
1#!/bin/bash 2# inky_setup.sh - auto setup the inky server 3 4# Check if this is being run from a file 5if [ -f "$0" ]; then 6 echo "Checking for updated setup script..." 7 LATEST=$(curl -s https://raw.githubusercontent.com/taciturnaxolotl/inky/refs/heads/main/setup.sh) 8 LATEST_HASH=$(echo "$LATEST" | sha256sum | cut -d' ' -f1) 9 CURRENT_HASH=$(cat "$0" | sha256sum | cut -d' ' -f1) 10 if [ $? -eq 0 ] && [ ! -z "$LATEST" ] && [ "$LATEST_HASH" != "$CURRENT_HASH" ]; then 11 echo "Applying latest version..." 12 echo "$LATEST" > "$0" 13 exec "$0" "$@" 14 exit 0 15 fi 16else 17 echo "Creating setup script file..." 18 curl -s https://raw.githubusercontent.com/taciturnaxolotl/inky/refs/heads/main/setup.sh > setup.sh 19 chmod +x setup.sh 20 exec ./setup.sh "$@" 21 exit 0 22fi 23 24# Check if running as root 25if [ "$EUID" -ne 0 ]; then 26 echo "Please run as root or with sudo" 27 exit 1 28fi 29 30echo "Setting up Inky camera server from GitHub repository..." 31 32# Check for existing repository 33cd /home/ink 34if [ -d "/home/ink/inky" ]; then 35 read -p "Repository already exists. Would you like to update it? (y/n) " -n 1 -r 36 echo 37 if [[ $REPLY =~ ^[Yy]$ ]]; then 38 cd /home/ink/inky 39 git pull 40 41 cp /home/ink/inky/src/camera_server.py /home/ink/ && chown ink:ink /home/ink/camera_server.py && chmod +x /home/ink/camera_server.py 42 cp /home/ink/inky/src/eink-4gray.png /home/ink/ && chown ink:ink /home/ink/eink-4gray.png 43 44 # Just restart the service since it's an update 45 echo "Restarting camera service..." 46 systemctl restart camera.service 47 else 48 echo "Okay, not updating" 49 exit 50 fi 51else 52 # Update system packages and install dependencies 53 echo "Updating package lists and installing dependencies..." 54 apt update 55 apt install -y python3-picamera2 python3-websockets python3-rpi.gpio git imagemagick 56 57 # Create directory for storing photos 58 echo "Creating photos directory..." 59 mkdir -p /home/ink/photos 60 chown ink:ink /home/ink/photos 61 62 git clone https://github.com/taciturnaxolotl/inky.git 63 64 chown -R ink:ink /home/ink/inky 65 66 # Copy camera_server.py to user's home directory 67 echo "Setting up camera server..." 68 cp /home/ink/inky/src/camera_server.py /home/ink/ 69 chown ink:ink /home/ink/camera_server.py 70 chmod +x /home/ink/camera_server.py 71 72 # copy dither palate 73 cp /home/ink/inky/src/eink-4gray.png /home/ink/ 74 chown ink:ink /home/ink/eink-4gray.png 75 76 # Copy and set up systemd service 77 echo "Setting up systemd service..." 78 cp /home/ink/inky/src/camera.service /etc/systemd/system/ 79 80 # Test the camera 81 echo "Testing camera..." 82 if command -v rpicam-still &> /dev/null; then 83 mkdir -p /tmp/camera_test 84 if rpicam-still -o /tmp/camera_test/test.jpg; then 85 echo "Camera test successful!" 86 else 87 echo "Camera test failed. Please check your camera connection." 88 fi 89 else 90 echo "rpicam-still not found. Please make sure the camera is properly enabled." 91 fi 92 93 # Enable and start the service 94 echo "Enabling and starting camera service..." 95 systemctl daemon-reload 96 systemctl enable camera.service 97 systemctl start camera.service 98fi 99 100echo "Setup complete!" 101echo "Camera server should now be running." 102echo "You can access the web interface at: http://inky.local" 103echo "Check service status with: sudo systemctl status camera"