an eink camera running on an rpi zero 2 w

feat: move to ink user and add setup scripts

dunkirk.sh 5b2fb2f7 7993b39b

verified
-85
.github/workflows/image-generator.yaml
···
-
name: Raspberry Pi Camera Setup
-
-
on:
-
release:
-
types: [published]
-
branches: [main]
-
-
jobs:
-
build:
-
runs-on: ubuntu-latest
-
-
steps:
-
- name: Checkout repository
-
uses: actions/checkout@v3
-
-
- name: Modify Raspberry Pi OS Image
-
uses: dtcooper/rpi-image-modifier@v1
-
id: create-image
-
with:
-
base-image-url: https://downloads.raspberrypi.org/raspios_lite_armhf_latest
-
image-path: raspios-camera-ssh-usb.img
-
compress-with-xz: true
-
shrink: true
-
mount-repository: true
-
run: |
-
# Set locale and timezone
-
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
-
locale-gen
-
update-locale LANG=en_US.UTF-8
-
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
-
-
# Create inky user first
-
useradd -m -s /bin/bash -G sudo,adm,dialout,cdrom,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi inky
-
echo "inky:inkycamera" | chpasswd
-
-
# Set hostname
-
echo "inky" > /etc/hostname
-
sed -i 's/raspberrypi/inky/' /etc/hosts
-
-
# Now copy camera files since /home/inky exists
-
cp -v /mounted-github-repo/src/camera_server.py /home/inky/camera_server.py
-
cp -v /mounted-github-repo/src/camera.service /etc/systemd/system/camera.service
-
-
# Set permissions
-
chown -R inky:inky /home/inky
-
-
# Configure SSH over USB
-
echo "dtoverlay=dwc2" >> /boot/config.txt
-
sed -i 's/rootwait/rootwait modules-load=dwc2,g_ether/' /boot/cmdline.txt
-
touch /boot/ssh
-
-
# Create setup script
-
cat << 'EEOF' > /home/inky/setup.sh
-
#!/bin/bash
-
sudo systemctl daemon-reload
-
sudo systemctl enable camera.service
-
sudo systemctl start camera.service
-
EEOF
-
chmod +x /home/inky/setup.sh
-
-
# Create and configure rc.local
-
cat << 'EOF' > /etc/rc.local
-
#!/bin/sh -e
-
/home/inky/setup.sh
-
exit 0
-
EOF
-
chmod +x /etc/rc.local
-
-
# Install required packages
-
apt-get update
-
apt-get install -y python3-picamera2 python3-websockets
-
apt-get clean
-
-
- name: Upload image as artifact
-
uses: actions/upload-artifact@v4
-
with:
-
name: raspberry-pi-camera-image
-
path: ${{ steps.create-image.outputs.image-path }}
-
-
- name: Upload Release Asset
-
uses: softprops/action-gh-release@v1
-
with:
-
files: ${{ steps.create-image.outputs.image-path }}
-
env:
-
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
+7 -3
README.md
···
## Setup
-
Put raspberry pi os lite 64-bit onto an SD card using the Raspberry Pi Imager and in the configureation step make sure to 1) add your SSH key and 2) set the user:password to `inky:inkycamera`. Oh and also make sure to add your wifi creds so we can update and install packages.
+
Put raspberry pi os lite 64-bit onto an SD card using the Raspberry Pi Imager and in the configureation step make sure to 1) add your SSH key and 2) set the user:password to `ink:inkycamera`. Oh and also make sure to add your wifi creds so we can update and install packages.
Next you need to configure network over usb so we can ssh in easily and be able to access the photo webserver.
···
now ssh in:
```bash
-
ssh ink@inkpress.local
+
ssh ink@inky.local
# Default password: inkycamera
```
-
The firmware instructions are in [`src/README.md`](src/README.md)
+
The firmware instructions are in [`src/README.md`](src/README.md) or you can run the following to auto configure
+
+
```bash
+
bash -c "$(curl -fsSL hack.club/crgqvn)"
+
```
## Build Notes
+66
configure-gadget.sh
···
+
#!/bin/bash
+
# setup_gadget_mode.sh - Script to configure USB gadget mode on a Raspberry Pi SD card
+
+
# Check if running as root
+
if [ "$EUID" -ne 0 ]; then
+
echo "Please run as root"
+
exit 1
+
fi
+
+
# Check if SD card boot partition is provided
+
if [ $# -lt 1 ]; then
+
echo "Usage: $0 /path/to/sd_card_boot_partition"
+
exit 1
+
fi
+
+
BOOT_PARTITION=$1
+
+
# Verify the boot partition exists
+
if [ ! -d "$BOOT_PARTITION" ]; then
+
echo "Error: Boot partition not found at $BOOT_PARTITION"
+
exit 1
+
fi
+
+
echo "Configuring USB gadget mode on $BOOT_PARTITION..."
+
+
# Modify config.txt to enable dwc2 overlay
+
CONFIG_FILE="$BOOT_PARTITION/config.txt"
+
if [ -f "$CONFIG_FILE" ]; then
+
if ! grep -q "dtoverlay=dwc2" "$CONFIG_FILE"; then
+
echo "Adding dtoverlay=dwc2 to config.txt..."
+
echo "dtoverlay=dwc2" >> "$CONFIG_FILE"
+
else
+
echo "dtoverlay=dwc2 already exists in config.txt"
+
fi
+
else
+
echo "Error: config.txt not found in boot partition"
+
exit 1
+
fi
+
+
# Modify cmdline.txt to load required modules
+
CMDLINE_FILE="$BOOT_PARTITION/cmdline.txt"
+
if [ -f "$CMDLINE_FILE" ]; then
+
if ! grep -q "modules-load=dwc2,g_ether" "$CMDLINE_FILE"; then
+
echo "Adding modules-load=dwc2,g_ether to cmdline.txt..."
+
sed -i 's/$/ modules-load=dwc2,g_ether/' "$CMDLINE_FILE"
+
else
+
echo "modules-load=dwc2,g_ether already exists in cmdline.txt"
+
fi
+
else
+
echo "Error: cmdline.txt not found in boot partition"
+
exit 1
+
fi
+
+
# Create empty ssh file to enable SSH
+
SSH_FILE="$BOOT_PARTITION/ssh"
+
if [ ! -f "$SSH_FILE" ]; then
+
echo "Creating empty ssh file to enable SSH..."
+
touch "$SSH_FILE"
+
else
+
echo "SSH already enabled"
+
fi
+
+
echo "USB gadget mode configuration complete!"
+
echo "Now you can insert the SD card into your Raspberry Pi and boot it."
+
echo "After booting, you should be able to connect via: ssh ink@inky.local"
+
echo "Default password: inkycamera"
+65
setup.sh
···
+
#!/bin/bash
+
# inky_setup.sh - auto setup the inky server
+
+
# Check if running as root
+
if [ "$EUID" -ne 0 ]; then
+
echo "Please run as root or with sudo"
+
exit 1
+
fi
+
+
echo "Setting up Inky camera server from GitHub repository..."
+
+
# Update system packages and install dependencies
+
echo "Updating package lists and installing dependencies..."
+
apt update
+
apt install -y python3-picamera2 python3-websockets python3-rpi.gpio git
+
+
# Create directory for storing photos
+
echo "Creating photos directory..."
+
mkdir -p /home/ink/photos
+
chown ink:ink /home/ink/photos
+
+
# Clone the repository
+
echo "Cloning repository from GitHub..."
+
cd /home/ink
+
if [ -d "/home/ink/inky" ]; then
+
cd /home/ink/inky
+
git pull
+
else
+
git clone https://github.com/taciturnaxolotl/inky.git
+
fi
+
chown -R ink:ink /home/ink/inky
+
+
# Copy camera_server.py to user's home directory
+
echo "Setting up camera server..."
+
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
+
+
# Copy and set up systemd service
+
echo "Setting up systemd service..."
+
cp /home/ink/inky/src/camera.service /etc/systemd/system/
+
+
# Test the camera
+
echo "Testing camera..."
+
if command -v rpicam-still &> /dev/null; then
+
mkdir -p /tmp/camera_test
+
if rpicam-still -o /tmp/camera_test/test.jpg; then
+
echo "Camera test successful!"
+
else
+
echo "Camera test failed. Please check your camera connection."
+
fi
+
else
+
echo "rpicam-still not found. Please make sure the camera is properly enabled."
+
fi
+
+
# Enable and start the service
+
echo "Enabling and starting camera service..."
+
systemctl daemon-reload
+
systemctl enable camera.service
+
systemctl start camera.service
+
+
echo "Setup complete!"
+
echo "Camera server should now be running."
+
echo "You can access the web interface at: http://inky.local"
+
echo "Check service status with: sudo systemctl status camera"
+2 -2
src/camera.service
···
After=network.target
[Service]
-
ExecStart=/usr/bin/python3 /home/inky/camera_server.py
-
WorkingDirectory=/home/inky
+
ExecStart=/usr/bin/python3 /home/ink/camera_server.py
+
WorkingDirectory=/home/ink
StandardOutput=inherit
StandardError=inherit
Restart=always
+2 -2
src/camera_server.py
···
logger = logging.getLogger('camera_server')
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-
file_handler = logging.FileHandler('/home/inky/camera_server.log')
+
file_handler = logging.FileHandler('/home/ink/camera_server.log')
file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
···
class Config:
BUTTON_PIN = 17
-
PHOTO_DIR = "/home/inky/photos"
+
PHOTO_DIR = "/home/ink/photos"
WEB_PORT = 80
WS_PORT = 8765
PHOTO_RESOLUTION = (2592, 1944)