86 lines
2.6 KiB
Bash
Executable file
86 lines
2.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
function print_help() {
|
|
echo "Usage: $0 -t [pitfttype] -i target.img"
|
|
echo " -h Print this help"
|
|
echo " -t [type] Specify the type of PiTFT: '28r' (PID 1601) or '28c' (PID 1983) or '35r' or '22'"
|
|
echo " -i [target] Specify an ISO to perform install on (a recent Pi Foundation Raspbian)"
|
|
echo
|
|
echo "You must specify a type of display."
|
|
exit 1
|
|
}
|
|
|
|
args=$(getopt -uo 'ht:i:' -- $*)
|
|
[ $? != 0 ] && print_help
|
|
set -- $args
|
|
|
|
for i
|
|
do
|
|
case "$i"
|
|
in
|
|
-h)
|
|
print_help
|
|
;;
|
|
-t)
|
|
pitfttype="$2"
|
|
echo "Type = ${2}"
|
|
shift
|
|
shift
|
|
;;
|
|
-i)
|
|
target_image="$2"
|
|
echo "Image = ${2}"
|
|
shift
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "$0 must be run as root. try: sudo $0"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ]
|
|
then
|
|
echo "Type must be '28r' (2.8\" resistive, PID 1601) or '28c' (2.8\" capacitive, PID 1983) or '35r' (3.5\" Resistive) or '22' (2.2\" no touch)"
|
|
print_help
|
|
fi
|
|
|
|
target_mnt="/media/raspbian-target"
|
|
|
|
# assemble a mostly-legit filesystem by mounting / and /boot from the target
|
|
# iso, plus /dev from the host pi (/dev/(u)random seems to be required by
|
|
# recent versions of GPG):
|
|
echo "Mounting $target_image on $target_mnt"
|
|
kpartx -av $target_image
|
|
mkdir -p $target_mnt
|
|
mount /dev/dm-1 $target_mnt
|
|
mount /dev/dm-0 $target_mnt/boot
|
|
mkdir -p $target_mnt/dev
|
|
mount --bind /dev $target_mnt/dev
|
|
|
|
echo "Dropping you into Bash before install"
|
|
chroot $target_mnt sudo /bin/bash
|
|
|
|
echo "Adding apt.adafruit.com to sources.list"
|
|
curl -SLs https://apt.adafruit.com/add | chroot $target_mnt /bin/bash
|
|
|
|
# pin apt.adafruit.com origin for anything installed there:
|
|
echo -e "Package: *\nPin: origin \"apt.adafruit.com\"\nPin-Priority: 1001" | chroot $target_mnt bash -c "cat > /etc/apt/preferences.d/adafruit"
|
|
|
|
echo "Installing kernel and adafruit-pitft-helper"
|
|
chroot $target_mnt sudo apt-get install raspberrypi-bootloader
|
|
chroot $target_mnt sudo apt-get install adafruit-pitft-helper
|
|
|
|
echo "Running adafruit-pitft-helper"
|
|
chroot $target_mnt sudo adafruit-pitft-helper -t $pitfttype
|
|
|
|
echo "Dropping you into Bash after install"
|
|
chroot $target_mnt sudo /bin/bash
|
|
|
|
echo "Unmounting $target_image"
|
|
umount $target_mnt/boot
|
|
umount $target_mnt/dev
|
|
umount $target_mnt
|
|
kpartx -d $target_image
|