{DPHacks} a website for everything camera hack related.
Postinstall script to be used with Raspberry Pi's CM Provisioning System (https://github.com/raspberrypi/cmprovision)
This script has been tested with Raspberry Pi OS Bullseye edition realeased April 8th 2022 and after.
It takes advantage of the user configuration file.
Replace fields surrounded by <> with the values you want assigned during provisioning.
Copy and paste the script below as a postinstall script.
Script will overclock CM4 to 2GHz with an over_voltage
value of 6.
Script will enable USB host mode.
Script will enable ssh.
Script will configure the America/Chicago timezone and set the keyboard layout to US. Change this as appropriate.
Replace <SSID>
with your network's SSID.
Replace <SSID encrypted psk>
with the encrypted passphrase. Type the command below in terminal in a different linux machine (like a Raspberry Pi)
wpa_passphrase <SSID> <SSID Passphrase>
Replace <country>
with the two letter ISO country code of your choice.
Replace <user>
and <hashed password>
with the desired values. Type the command below to get the hashed password value.
echo 'mypassword' | openssl passwd -6 -stdin
The script is configured to use the Compute Module's serial number as the hostname. Feel free to change this as needed.
#!/bin/sh
set -e
#boot partition files
mkdir -p /mnt/boot
mount -t vfat $PART1 /mnt/boot
sed -i "/[CM4].*/a arm_freq=2000\nover_voltage=6" /mnt/boot/config.txt
sed -i "/[CM4].*/a dtoverlay=dwc2,dr_mode=host" /mnt/boot/config.txt
touch /mnt/boot/ssh
echo '<user>:<hashed password>' > /mnt/boot/userconf
cat >/mnt/boot/wpa_supplicant.conf <<'WPAEOF'
country=<country>
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ap_scan=1
update_config=1
network={
ssid="<SSID>"
psk=<SSID encrypted psk>
}
WPAEOF
umount /mnt/boot
#root partition
mkdir -p /mnt/root
mount -t ext4 $PART2 /mnt/root
new_host=$SERIAL
echo $new_host >/mnt/root/etc/hostname
sed -i "s/127.0.1.1.*raspberrypi/127.0.1.1\t${new_host}/g" /mnt/root/etc/hosts
echo "America/Chicago" >/mnt/root/etc/timezone
cat >/mnt/root/etc/default/keyboard <<'KBEOF'
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
KBEOF
umount /mnt/root