This repository has no description
1name: Raspberry Pi Camera Setup
2
3on:
4 release:
5 types: [published]
6 branches: [main]
7
8jobs:
9 build:
10 runs-on: ubuntu-latest
11
12 steps:
13 - name: Checkout repository
14 uses: actions/checkout@v3
15
16 - name: Install dependencies
17 run: |
18 sudo apt-get update
19 sudo apt-get install -y wget unzip xz-utils fdsk dosfstools qemu-user-static git
20 git clone https://github.com/Drewsif/PiShrink.git
21 cd PiShrink
22 sudo install -m 755 pishrink.sh /usr/local/bin
23
24 - name: Download Raspberry Pi OS Lite
25 run: |
26 wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest -O raspios.zip
27 unzip raspios.zip
28 mv *.img raspios.img
29
30 - name: Mount image and setup SSH over USB
31 run: |
32 # Create a loop device to interact with the image
33 LOOP_DEV=$(sudo losetup -f --show raspios.img)
34
35 # Ensure we can see the partitions
36 sudo partprobe $LOOP_DEV
37
38 # Mount the boot partition
39 sudo mkdir -p /mnt/boot
40 sudo mount ${LOOP_DEV}p1 /mnt/boot
41
42 # Configure SSH over USB
43 echo "dtoverlay=dwc2" | sudo tee -a /mnt/boot/config.txt
44 sudo sed -i 's/rootwait/rootwait modules-load=dwc2,g_ether/' /mnt/boot/cmdline.txt
45 sudo touch /mnt/boot/ssh
46
47 # Unmount boot partition
48 sudo umount /mnt/boot
49
50 # Mount the root filesystem
51 sudo mkdir -p /mnt/rootfs
52 sudo mount ${LOOP_DEV}p2 /mnt/rootfs
53
54 # Create inky user and home directory
55 sudo mkdir -p /mnt/rootfs/home/inky
56
57 # Copy camera script to the image
58 sudo cp ./src/camera_server.py /mnt/rootfs/home/inky/camera_server.py
59
60 # Setup service
61 sudo mkdir -p /mnt/rootfs/etc/systemd/system
62 sudo cp ./src/camera.service /mnt/rootfs/etc/systemd/system/camera.service
63
64 # Create a script to enable the service on first boot
65 cat << 'EOF' | sudo tee /mnt/rootfs/home/inky/setup.sh
66 #!/bin/bash
67 sudo systemctl daemon-reload
68 sudo systemctl enable camera.service
69 sudo systemctl start camera.service
70 EOF
71
72 sudo chmod +x /mnt/rootfs/home/inky/setup.sh
73
74 # Add script to rc.local to run on first boot
75 sudo sed -i 's@exit 0@/home/inky/setup.sh\nexit 0@' /mnt/rootfs/etc/rc.local
76
77 # Set the hostname to inky
78 echo "inky" | sudo tee /mnt/rootfs/etc/hostname
79 sudo sed -i 's/raspberrypi/inky/' /mnt/rootfs/etc/hosts
80
81 # Install required packages using chroot
82 sudo cp /usr/bin/qemu-arm-static /mnt/rootfs/usr/bin/
83 cat << 'EOF' | sudo chroot /mnt/rootfs
84 # Create inky user
85 useradd -m -s /bin/bash -G sudo,adm,dialout,cdrom,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi inky
86 echo "inky:inkycamera" | chpasswd
87
88 # Set permissions
89 chown -R inky:inky /home/inky
90
91 # Install required packages
92 apt-get update
93 apt-get install -y python3-picamera2 python3-websockets
94 apt-get clean
95 EOF
96
97 # Unmount and clean up
98 sudo umount /mnt/rootfs
99 sudo losetup -d $LOOP_DEV
100
101 - name: Shrink image
102 run: |
103 sudo pishrink.sh -z raspios.img
104 mv raspios.img.xz raspios-camera-ssh-usb.img.xz
105
106 - name: Upload image as artifact
107 uses: actions/upload-artifact@v4
108 with:
109 name: raspberry-pi-camera-image
110 path: raspios-camera-ssh-usb.img.xz
111
112 - name: Upload Release Asset
113 uses: softprops/action-gh-release@v1
114 with:
115 files: raspios-camera-ssh-usb.img.xz
116 env:
117 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}