| 1 | #!/bin/sh |
| 2 | |
| 3 | if grep -q '^disable_trigger=1' /etc/update-raspberrypi-bootloader.conf 2>/dev/null; then |
| 4 | exit 0 |
| 5 | fi |
| 6 | |
| 7 | # see https://www.raspberrypi.com/documentation/computers/config_txt.html#kernel |
| 8 | # use the last found kernel for for example vmlinuz-rpi16k gets preference over |
| 9 | # vmlinuz-rpi |
| 10 | for i in /boot/vmlinuz* /boot/vmlinuz-lts /boot/vmlinuz-rpi /boot/vmlinuz-rpi*; do |
| 11 | if [ -e "$i" ]; then |
| 12 | kernel="${i#/boot/}" |
| 13 | initramfs="initramfs${kernel#vmlinuz}" |
| 14 | fi |
| 15 | done |
| 16 | |
| 17 | if [ -z "$kernel" ]; then |
| 18 | echo "$0: WARNING: no kernel found" >&2 |
| 19 | exit |
| 20 | fi |
| 21 | |
| 22 | case "$(uname -m)" in |
| 23 | aarch64) arm_64bit=1;; |
| 24 | *) arm_64bit=0;; |
| 25 | esac |
| 26 | |
| 27 | # busybox sed has no q command support so use grep to test pattern first |
| 28 | if grep -q '^kernel=' /boot/config.txt 2>/dev/null && \ |
| 29 | grep -q '^initramfs' /boot/config.txt && \ |
| 30 | grep -q '^arm_64bit=' /boot/config.txt; then |
| 31 | cp -fa /boot/config.txt /boot/config.txt.new |
| 32 | sed -i -e "s/^kernel=.*/kernel=$kernel/" \ |
| 33 | -e "s/^initramfs.*/initramfs $initramfs/" \ |
| 34 | -e "s/^arm_64bit=.*/arm_64bit=$arm_64bit/" /boot/config.txt.new |
| 35 | else |
| 36 | cat > /boot/config.txt.new <<-EOF |
| 37 | # do not modify this file as it will be overwritten on upgrade. |
| 38 | # create and/or modify usercfg.txt instead. |
| 39 | # https://www.raspberrypi.com/documentation/computers/config_txt.html |
| 40 | # |
| 41 | |
| 42 | kernel=$kernel |
| 43 | initramfs $initramfs |
| 44 | arm_64bit=$arm_64bit |
| 45 | include usercfg.txt |
| 46 | EOF |
| 47 | fi |
| 48 | |
| 49 | if diff -bBN /boot/config.txt.new /boot/config.txt >/dev/null; then |
| 50 | rm -f /boot/config.txt.new |
| 51 | else |
| 52 | mv -f /boot/config.txt /boot/config.txt.old 2>/dev/null |
| 53 | mv -f /boot/config.txt.new /boot/config.txt |
| 54 | echo "$0: INFO: replaced config.txt and saved config.txt.old, with following changes:" |
| 55 | diff -bBN /boot/config.txt.old /boot/config.txt 2>/dev/null |
| 56 | fi |
| 57 | |
| 58 | echo "Configured kernel $kernel / $initramfs" |