···
- name: Checkout repository
uses: actions/checkout@v3
-
- name: Install dependencies
-
sudo apt-get install -y wget unzip xz-utils fdsk dosfstools qemu-user-static git
-
git clone https://github.com/Drewsif/PiShrink.git
-
sudo install -m 755 pishrink.sh /usr/local/bin
-
- name: Download Raspberry Pi OS Lite
-
wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest -O raspios.zip
-
- name: Mount image and setup SSH over USB
-
# Create a loop device to interact with the image
-
LOOP_DEV=$(sudo losetup -f --show raspios.img)
-
# Ensure we can see the partitions
-
sudo partprobe $LOOP_DEV
-
# Mount the boot partition
-
sudo mkdir -p /mnt/boot
-
sudo mount ${LOOP_DEV}p1 /mnt/boot
-
# Configure SSH over USB
-
echo "dtoverlay=dwc2" | sudo tee -a /mnt/boot/config.txt
-
sudo sed -i 's/rootwait/rootwait modules-load=dwc2,g_ether/' /mnt/boot/cmdline.txt
-
sudo touch /mnt/boot/ssh
-
# Unmount boot partition
-
# Mount the root filesystem
-
sudo mkdir -p /mnt/rootfs
-
sudo mount ${LOOP_DEV}p2 /mnt/rootfs
-
# Create inky user and home directory
-
sudo mkdir -p /mnt/rootfs/home/inky
-
# Copy camera script to the image
-
sudo cp ./src/camera_server.py /mnt/rootfs/home/inky/camera_server.py
-
sudo mkdir -p /mnt/rootfs/etc/systemd/system
-
sudo cp ./src/camera.service /mnt/rootfs/etc/systemd/system/camera.service
-
# Create a script to enable the service on first boot
-
cat << 'EOF' | sudo tee /mnt/rootfs/home/inky/setup.sh
-
sudo systemctl daemon-reload
-
sudo systemctl enable camera.service
-
sudo systemctl start camera.service
-
sudo chmod +x /mnt/rootfs/home/inky/setup.sh
-
# Add script to rc.local to run on first boot
-
sudo sed -i 's@exit 0@/home/inky/setup.sh\nexit 0@' /mnt/rootfs/etc/rc.local
-
# Set the hostname to inky
-
echo "inky" | sudo tee /mnt/rootfs/etc/hostname
-
sudo sed -i 's/raspberrypi/inky/' /mnt/rootfs/etc/hosts
-
# Install required packages using chroot
-
sudo cp /usr/bin/qemu-arm-static /mnt/rootfs/usr/bin/
-
cat << 'EOF' | sudo chroot /mnt/rootfs
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
chown -R inky:inky /home/inky
-
# Install required packages
-
apt-get install -y python3-picamera2 python3-websockets
-
sudo umount /mnt/rootfs
-
sudo losetup -d $LOOP_DEV
-
sudo pishrink.sh -z raspios.img
-
mv raspios.img.xz raspios-camera-ssh-usb.img.xz
- name: Upload image as artifact
uses: actions/upload-artifact@v4
name: raspberry-pi-camera-image
-
path: raspios-camera-ssh-usb.img.xz
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
-
files: raspios-camera-ssh-usb.img.xz
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}