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