Skip to content

Instantly share code, notes, and snippets.

@yiays
Last active September 14, 2025 03:35
Show Gist options
  • Save yiays/5811aa50a8866e4a73b46a4af9a978e5 to your computer and use it in GitHub Desktop.
Save yiays/5811aa50a8866e4a73b46a4af9a978e5 to your computer and use it in GitHub Desktop.
Pi 1 Bookworm Motioneye Setup
#!/bin/bash
# This script installs MotionEye on a Raspberry Pi 1 or Zero
# Included is a tool to send Discord webhook events whenever a motion event is triggered
echo
echo "Assuming a fresh installation of Raspberry Pi OS Bookworm - lite is recommended"
echo
echo "Installing motion..."
echo
# Increase graphics memory allocation, default is 64MB
echo "gpu_mem = 128" | sudo tee -a /boot/firmware/config.txt > /dev/null
# Update repos and packages
sudo apt update
sudo apt upgrade -y
# install motion from official github
# this is the last release of motion for the Pi 1 / Zero
wget https://github.com/Motion-Project/motion/releases/download/release-4.6.0/pi_bookworm_motion_4.6.0-1_armhf.deb
sudo apt install ./pi_bookworm_motion_4.6.0-1_armhf.deb -y
rm pi_bookworm_motion_4.6.0-1_armhf.deb
echo
echo "At this point, motion is set up and working. Continue to install motioneye."
read -p "Do you want to continue [Y/n]? " response
response=${response,,} # convert to lowercase
if [[ "$response" =~ ^(n|no)$ ]]; then
exit 1
fi
echo
echo "Installing motioneye..."
echo
# motioneye dependencies - https://github.com/motioneye-project/motioneye?tab=readme-ov-file#installation
# setup pip
sudo apt --no-install-recommends install python3 python3-dev gcc libjpeg62-turbo-dev libcurl4-openssl-dev libssl-dev -y
curl -sSfO 'https://bootstrap.pypa.io/get-pip.py'
sudo python3 get-pip.py
# disable venv requirement
grep -q '\[global\]' /etc/pip.conf 2> /dev/null || printf '%b' '[global]\n' | sudo tee -a /etc/pip.conf > /dev/null
sudo sed -i '/^\[global\]/a\break-system-packages=true' /etc/pip.conf
sudo python3 get-pip.py
rm get-pip.py
sudo python3 -m pip install --pre motioneye
sudo motioneye_init
sudo service motioneye stop
# run the web ui on port 80
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.11
sudo sed -i 's|^port.*|port 80' /etc/motioneye/motioneye.conf
sudo service motioneye start
echo
echo "Motioneye should be running and available on port 80 now."
echo "The default login is 'admin' with no password"
echo
echo "Compatibility features for old picam modules will be installed next."
read -p "Do you want to continue [Y/n]? " response
response=${response,,} # convert to lowercase
if [[ "$response" =~ ^(n|no)$ ]]; then
exit 1
fi
echo
echo "Installing legacy camera compatibility features..."
echo
# change the config
sudo service motioneye stop
# install dependencies
sudo apt install libcamera-tools libcamera-v4l2
# change motion binary path so libcamerify is called first
echo $'#!/bin/sh\n/usr/bin/libcamerify /usr/bin/motion "$@"' | sudo tee /usr/bin/libcamerifymotion > /dev/null
sudo chmod +x /usr/bin/libcamerifymotion
sudo sed -i 's|^#motion_binary.*|motion_binary /usr/bin/libcamerifymotion|' /etc/motioneye/motioneye.conf
# everything should be working
sudo service motioneye start
echo
echo "Legacy camera compatibility tools have been installed."
echo "If you comtinue, discord.sh will be installed next."
read -p "Do you want to continue [Y/n]? " response
response=${response,,} # convert to lowercase
if [[ "$response" =~ ^(n|no)$ ]]; then
exit 1
fi
echo "Installing discord.sh..."
sudo apt install jq -y
wget https://github.com/fieu/discord.sh/releases/latest/download/discord.sh
sudo chown root:root discord.sh
sudo chmod +x discord.sh
sudo mv discord.sh /usr/bin/
echo
echo "discord.sh is now installed. To use it, enable \"Run a Command\" in motion notifications"
echo "and paste the following in the command section;"
echo
echo $'sleep 1 && ln -sfn "$(ls -t1d /var/lib/motioneye/Camera1/*/* | grep jpg | head -n1)" /var/lib/motioneye/Camera1/lastsnap.jpg && /usr/bin/discord.sh --webhook-url "WEBHOOK_URL_GOES_HERE" --text "CAMERA_NAME_GOES_HERE" --file "/var/lib/motioneye/Camera1/lastsnap.jpg"'
echo
echo "Note: do not end your event command with an &"
echo "To get your webhook url, create a webhook in a channel on Discord."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment