diff --git a/bin/reform-chat b/bin/reform-chat index b27205665517c61059bba4bde5e65d2e955f30bd..4d3040a365cdfa771300eb66ee1d41948e19c131 100755 --- a/bin/reform-chat +++ b/bin/reform-chat @@ -2,24 +2,24 @@ set -eu -usage () { - echo "Join the #mnt-reform chat room on irc.libera.chat" >&2 - echo "under a random pseudonym" >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Join the #mnt-reform chat room on irc.libera.chat" >&2 + echo "under a random pseudonym" >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ]; then - if [ "$1" != "--help" ]; then - echo "E: too many arguments" >&2 - usage - exit 1 - fi - usage - exit 0 + if [ "$1" != "--help" ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + usage + exit 0 fi exec irc -c '#mnt-reform' -p 6697 "reform$(shuf -i 0-32767 -n 1)" SSLIRC/irc.libera.chat diff --git a/bin/reform-check b/bin/reform-check index b97b059813b12d3f17f2cd8c4cc1fb08bd0d633d..5a74b3cd498519d3046309021ef7bb683b154038 100755 --- a/bin/reform-check +++ b/bin/reform-check @@ -18,86 +18,111 @@ set -eu usage() { - echo "This script checks the integrity of your MNT reform setup. It is meant for" >&2 - echo "two main use-cases:" >&2 - echo >&2 - echo " 1. somebody has a problem with their reform and to debug the problem it" >&2 - echo " would be useful to know how their system differs from the default" >&2 - echo " 2. somebody installed their system several months ago and now wants to find" >&2 - echo " out which things have since been added or changed in the defaults that" >&2 - echo " they might want to apply to their running setup as well" >&2 - echo >&2 - echo "Running this script as non-root will give you a diff between the files in" >&2 - echo "/etc/skel and those in your \$HOME. Running this script as root performs the" >&2 - echo "system-wide checks." >&2 - echo >&2 - echo "Usage: $0 [--help] [--mirror={mntre.com,reform.debian.net}]" >&2; - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 - echo " --mirror=MIRROR Force MIRROR, either mntre.com or reform.debian.net" >&2 + echo "This script checks the integrity of your MNT reform setup. It is meant for" >&2 + echo "two main use-cases:" >&2 + echo >&2 + echo " 1. somebody has a problem with their reform and to debug the problem it" >&2 + echo " would be useful to know how their system differs from the default" >&2 + echo " 2. somebody installed their system several months ago and now wants to find" >&2 + echo " out which things have since been added or changed in the defaults that" >&2 + echo " they might want to apply to their running setup as well" >&2 + echo >&2 + echo "Running this script as non-root will give you a diff between the files in" >&2 + echo '/etc/skel and those in your $HOME. Running this script as root performs the' >&2 + echo "system-wide checks." >&2 + echo >&2 + echo "Usage: $0 [--help] [--mirror={mntre.com,reform.debian.net}]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 + echo " --mirror=MIRROR Force MIRROR, either mntre.com or reform.debian.net" >&2 } MIRROR= if [ "$#" -gt 0 ]; then case "$1" in - --help) usage; exit 0 ;; - --mirror=mntre.com) - if [ "$#" -gt 1 ]; then echo "E: too many arguments" >&2; usage; exit 1; fi - MIRROR="mntre.com";; - --mirror=reform.debian.net) - if [ "$#" -gt 1 ]; then echo "E: too many arguments" >&2; usage; exit 1; fi - MIRROR="reform.debian.net";; - --mirror=*) echo "E: invalid argument for --mirror" >&2; usage; exit 1;; - --mirror) - if [ "$#" -eq 1 ]; then echo "E: missing argument" >&2; usage; exit 1 - elif [ "$#" -gt 2 ]; then echo "E: too many arguments" >&2; usage; exit 1; fi - case "$2" in - mntre.com) MIRROR="mntre.com" ;; - reform.debian.net) MIRROR="reform.debian.net" ;; - esac -esac; fi + --help) + usage + exit 0 + ;; + --mirror=mntre.com) + if [ "$#" -gt 1 ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + MIRROR="mntre.com" + ;; + --mirror=reform.debian.net) + if [ "$#" -gt 1 ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + MIRROR="reform.debian.net" + ;; + --mirror=*) + echo "E: invalid argument for --mirror" >&2 + usage + exit 1 + ;; + --mirror) + if [ "$#" -eq 1 ]; then + echo "E: missing argument" >&2 + usage + exit 1 + elif [ "$#" -gt 2 ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + case "$2" in + mntre.com) MIRROR="mntre.com" ;; + reform.debian.net) MIRROR="reform.debian.net" ;; + esac + ;; +esac fi if [ "$(id -u)" -ne 0 ]; then - for path in $(cd /etc/skel && find . -type f); do - if [ ! -e "$HOME/$path" ]; then - echo "W: $path doesn't exist in current \$HOME" >&2 - elif ! cmp --quiet "/etc/skel/$path" "$HOME/$path"; then - echo "W: local version of $path has modifications:" >&2 - diff -u "/etc/skel/$path" "$HOME/$path" || true - fi - done - echo "I: Running reform-check as the normal user only diffs your current" - echo "I: configuration in your \$HOME against the contents in /etc/skel." - echo "I: To run a system-wide check, run this script as the root user." - exit 0 + for path in $(cd /etc/skel && find . -type f); do + if [ ! -e "$HOME/$path" ]; then + echo "W: $path doesn't exist in current \$HOME" >&2 + elif ! cmp --quiet "/etc/skel/$path" "$HOME/$path"; then + echo "W: local version of $path has modifications:" >&2 + diff -u "/etc/skel/$path" "$HOME/$path" || true + fi + done + echo "I: Running reform-check as the normal user only diffs your current" + echo 'I: configuration in your $HOME against the contents in /etc/skel.' + echo "I: To run a system-wide check, run this script as the root user." + exit 0 fi if [ -z "$MIRROR" ] && grep --silent '^URIs: https://reform.debian.net/debian/\?$' /etc/apt/sources.list.d/reform*.sources 2>/dev/null; then - echo "I: reform.debian.net is configured as a mirror in /etc/apt/sources.list.d" >&2 - echo "I: Assuming reform.debian.net stable mirror for this script" >&2 - echo "I: If this is incorrect, you can set the mirror to its default by" >&2 - echo "I: re-running this script with --mirror=mntre.com" - MIRROR="reform.debian.net" + echo "I: reform.debian.net is configured as a mirror in /etc/apt/sources.list.d" >&2 + echo "I: Assuming reform.debian.net stable mirror for this script" >&2 + echo "I: If this is incorrect, you can set the mirror to its default by" >&2 + echo "I: re-running this script with --mirror=mntre.com" + MIRROR="reform.debian.net" fi if [ -z "$MIRROR" ]; then - MIRROR="mntre.com" + MIRROR="mntre.com" fi if [ -z "$(apt-get indextargets)" ]; then - echo "E: the apt cache is empty. Please run 'apt update' before running reform-check" >&2 - exit 1 + echo "E: the apt cache is empty. Please run 'apt update' before running reform-check" >&2 + exit 1 fi # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi echo "I: Your platform name is: $(cat /proc/device-tree/model)" >&2 @@ -106,25 +131,25 @@ echo "I: Your installed kernel version: $(dpkg-query --show --showformat '${Vers echo "I: Your installed reform-tools version: $(dpkg-query --show --showformat '${Version}' reform-tools)" >&2 if [ ! -e "/etc/flash-kernel/machine" ]; then - # /etc/flash-kernel/machine not existing is only a potential problem - # on imx8mq - case "$(cat /proc/device-tree/model)" in - "MNT Reform 2"|"MNT Reform 2 HDMI") echo "W: /etc/flash-kernel/machine does not exist" >&2 ;; - esac + # /etc/flash-kernel/machine not existing is only a potential problem + # on imx8mq + case "$(cat /proc/device-tree/model)" in + "MNT Reform 2" | "MNT Reform 2 HDMI") echo "W: /etc/flash-kernel/machine does not exist" >&2 ;; + esac fi if [ ! -e "/proc/device-tree/model" ]; then - echo "E: /proc/device-tree/model does not exist" >&2 + echo "E: /proc/device-tree/model does not exist" >&2 fi if [ -e "/etc/flash-kernel/machine" ] && [ -e "/proc/device-tree/model" ] && [ "$(cat /proc/device-tree/model)" != "$(cat /etc/flash-kernel/machine)" ]; then - echo "E: your currently loaded dtb is not the one referenced by flash-kernel" >&2 + echo "E: your currently loaded dtb is not the one referenced by flash-kernel" >&2 fi PKGSGUI="xwayland xterm sway fonts-inter fonts-noto-color-emoji waybar swayidle swaylock mesa-utils lxpolkit wayland-protocols wofi wireplumber papirus-icon-theme libglib2.0-bin gsettings-desktop-schemas gnome-disk-utility gnome-themes-extra-data gnome-icon-theme gnome-settings-daemon gnome-system-monitor grim slurp gedit evince mpv sxiv gvfs-backends unicode-data engrampa neverball minetest qt5ct kde-style-breeze dunst pasystray wev wf-recorder wayvnc network-manager-gnome blueman pavucontrol thunar" case "$MIRROR" in - mntre.com) PKGSGUI="$PKGSGUI wayfire reform-firedecor firefox tuigreet";; - reform.debian.net) PKGSGUI="$PKGSGUI firefox-esr";; + mntre.com) PKGSGUI="$PKGSGUI wayfire reform-firedecor firefox tuigreet" ;; + reform.debian.net) PKGSGUI="$PKGSGUI firefox-esr" ;; esac PKGSTOOLS="bmap-tools brightnessctl fonts-font-awesome fonts-jetbrains-mono foot gir1.2-ayatanaappindicator3-0.1 gir1.2-notify-0.7 gnome-system-monitor ircii pavucontrol pulseaudio-utils python3 python3-gi thunar x11-xserver-utils" PKGSNET="iproute2 iptables inetutils-ping elinks isc-dhcp-client netcat-traditional net-tools network-manager nfacct ntp ntpdate rsync telnet traceroute wpasupplicant curl wget w3m rfkill ifupdown netbase openssh-client firmware-realtek" @@ -133,53 +158,53 @@ PKGSUTILS="busybox console-data console-setup cpio file flash-kernel gnupg gpgv PKGSMISC="brightnessctl brightness-udev ca-certificates debian-archive-keyring dialog gpm ncurses-term locales bash-completion man-db cryptsetup-initramfs reform-tools gpiod firmware-misc-nonfree linux-image-mnt-reform-arm64 linux-headers-mnt-reform-arm64" case "$MIRROR" in - mntre.com) aptprefcontent="Package: *\nPin: release n=reform, l=reform\nPin-Priority: 990\n";; - reform.debian.net) aptprefcontent="Package: *\nPin: origin \"reform.debian.net\"\nPin-Priority: 999\n";; + mntre.com) aptprefcontent="Package: *\nPin: release n=reform, l=reform\nPin-Priority: 990\n" ;; + reform.debian.net) aptprefcontent="Package: *\nPin: origin \"reform.debian.net\"\nPin-Priority: 999\n" ;; esac if [ ! -e /etc/apt/preferences.d/reform.pref ]; then - echo "E: /etc/apt/preferences.d/reform.pref doesn't exist" >&2 - echo "E: you should not install packages on this system unless you know what you are doing" >&2 - echo "E: /etc/apt/preferences.d/reform.pref should contain the following lines:" >&2 - printf "$aptprefcontent" >&2 + echo "E: /etc/apt/preferences.d/reform.pref doesn't exist" >&2 + echo "E: you should not install packages on this system unless you know what you are doing" >&2 + echo "E: /etc/apt/preferences.d/reform.pref should contain the following lines:" >&2 + printf "$aptprefcontent" >&2 else - if ! printf "$aptprefcontent" | cmp --quiet - /etc/apt/preferences.d/reform.pref; then - echo "W: unexpected content in /etc/apt/preferences.d/reform.pref:" >&2 - printf "$aptprefcontent" | diff -u - /etc/apt/preferences.d/reform.pref || true - echo "W: you should not install packages on this system unless you know what you are doing" >&2 - fi + if ! printf "$aptprefcontent" | cmp --quiet - /etc/apt/preferences.d/reform.pref; then + echo "W: unexpected content in /etc/apt/preferences.d/reform.pref:" >&2 + printf "$aptprefcontent" | diff -u - /etc/apt/preferences.d/reform.pref || true + echo "W: you should not install packages on this system unless you know what you are doing" >&2 + fi fi notinstalled= for package in $PKGSGUI $PKGSTOOLS $PKGSNET $PKGSADMIN $PKGSUTILS $PKGSMISC; do - if ! dpkg-query --showformat '${db:Status-Status}\n' --show "$package" 2>/dev/null | grep -q '^installed$'; then - notinstalled="$notinstalled $package" - fi + if ! dpkg-query --showformat '${db:Status-Status}\n' --show "$package" 2>/dev/null | grep -q '^installed$'; then + notinstalled="$notinstalled $package" + fi done if [ -n "$notinstalled" ]; then - echo "I: not installed: $(echo "$notinstalled" | tr " " "\n" | sort | tr "\n" " ")" >&2 + echo "I: not installed: $(echo "$notinstalled" | tr " " "\n" | sort | tr "\n" " ")" >&2 fi if [ -z "$(findmnt --fstab --noheadings --evaluate --mountpoint / --output SOURCE)" ]; then - echo "E: your /etc/fstab does not have an entry for /" >&2 - echo "E: your / device probably is: $(findmnt --noheadings --evaluate --mountpoint / --output SOURCE)" >&2 - echo "E: add this to your /etc/fstab:" >&2 - echo "$(findmnt --noheadings --evaluate --mountpoint / --output SOURCE) / auto errors=remount-ro 0 1" >&2 + echo "E: your /etc/fstab does not have an entry for /" >&2 + echo "E: your / device probably is: $(findmnt --noheadings --evaluate --mountpoint / --output SOURCE)" >&2 + echo "E: add this to your /etc/fstab:" >&2 + echo "$(findmnt --noheadings --evaluate --mountpoint / --output SOURCE) / auto errors=remount-ro 0 1" >&2 fi if [ -z "$(findmnt --fstab --noheadings --evaluate --mountpoint /boot --output SOURCE)" ]; then - echo "E: your /etc/fstab does not have an entry for /boot" >&2 - if [ "$EMMC_BOOT" = true ]; then - echo "E: for eMMC booting, add:" >&2 - echo "/dev/${DEV_MMC}p1 /boot auto errors=remount-ro 0 1" >&2 - fi - if [ "$SD_BOOT" = true ]; then - echo "E: for SD-Card booting, add:" >&2 - echo "/dev/${DEV_SD}p1 /boot auto errors=remount-ro 0 1" >&2 - fi + echo "E: your /etc/fstab does not have an entry for /boot" >&2 + if [ "$EMMC_BOOT" = true ]; then + echo "E: for eMMC booting, add:" >&2 + echo "/dev/${DEV_MMC}p1 /boot auto errors=remount-ro 0 1" >&2 + fi + if [ "$SD_BOOT" = true ]; then + echo "E: for SD-Card booting, add:" >&2 + echo "/dev/${DEV_SD}p1 /boot auto errors=remount-ro 0 1" >&2 + fi fi if ! mountpoint --quiet /boot; then - echo "E: your /boot has nothing mounted on it -- fix your /etc/fstab" >&2 + echo "E: your /boot has nothing mounted on it -- fix your /etc/fstab" >&2 fi # FIXME: on ls1028a, also check for /boot/ls1028a-mhdpfw.bin @@ -189,301 +214,306 @@ ubootbin=$(mktemp) ret=0 /usr/lib/apt/apt-helper download-file "$ubooturl" "$ubootbin" "SHA1:$UBOOT_SHA1" >/dev/null || ret=$? if [ "$ret" != 0 ]; then - echo "E: download of $ubooturl failed" >&2 + echo "E: download of $ubooturl failed" >&2 else - if [ ! -e /boot/flash.bin ]; then - echo "W: /boot/flash.bin doesn't exist" >&2 - echo "W: You can download the latest version by running as root:" >&2 - echo "reform-flash-uboot" >&2 - elif ! cmp --quiet /boot/flash.bin "$ubootbin"; then - echo "W: /boot/flash.bin is not the latest uboot" >&2 - echo "W: You can update it to the latest version by running as root:" >&2 - echo "reform-flash-uboot" >&2 - fi - ubootsize=$(stat --format=%s "$ubootbin") - - if [ "$EMMC_BOOT" = true ] && ! cmp --quiet --bytes="$((ubootsize-FLASHBIN_OFFSET))" "--ignore-initial=$FLASHBIN_OFFSET:$UBOOT_OFFSET" "$ubootbin" "/dev/${DEV_MMC}boot0" 2>/dev/null; then - echo "W: eMMC does not contain latest uboot" >&2 - echo "W: You can update it to the latest version by running as root:" >&2 - echo "reform-flash-uboot emmc" >&2 - fi - - if [ "$SD_BOOT" = true ] && [ -e "/dev/$DEV_SD" ] && ! cmp --quiet --bytes="$((ubootsize-FLASHBIN_OFFSET))" --ignore-initial="$FLASHBIN_OFFSET:$UBOOT_OFFSET" "$ubootbin" "/dev/$DEV_SD" 2>/dev/null; then - echo "W: SD-Card does not contain latest uboot" >&2 - echo "W: You can update it to the latest version by running as root:" >&2 - echo "reform-flash-uboot sd" >&2 - fi + if [ ! -e /boot/flash.bin ]; then + echo "W: /boot/flash.bin doesn't exist" >&2 + echo "W: You can download the latest version by running as root:" >&2 + echo "reform-flash-uboot" >&2 + elif ! cmp --quiet /boot/flash.bin "$ubootbin"; then + echo "W: /boot/flash.bin is not the latest uboot" >&2 + echo "W: You can update it to the latest version by running as root:" >&2 + echo "reform-flash-uboot" >&2 + fi + ubootsize=$(stat --format=%s "$ubootbin") + + if [ "$EMMC_BOOT" = true ] && ! cmp --quiet --bytes="$((ubootsize - FLASHBIN_OFFSET))" "--ignore-initial=$FLASHBIN_OFFSET:$UBOOT_OFFSET" "$ubootbin" "/dev/${DEV_MMC}boot0" 2>/dev/null; then + echo "W: eMMC does not contain latest uboot" >&2 + echo "W: You can update it to the latest version by running as root:" >&2 + echo "reform-flash-uboot emmc" >&2 + fi + + if [ "$SD_BOOT" = true ] && [ -e "/dev/$DEV_SD" ] && ! cmp --quiet --bytes="$((ubootsize - FLASHBIN_OFFSET))" --ignore-initial="$FLASHBIN_OFFSET:$UBOOT_OFFSET" "$ubootbin" "/dev/$DEV_SD" 2>/dev/null; then + echo "W: SD-Card does not contain latest uboot" >&2 + echo "W: You can update it to the latest version by running as root:" >&2 + echo "reform-flash-uboot sd" >&2 + fi fi rm "$ubootbin" case "$(cat /proc/device-tree/model)" in "MNT Reform 2 with LS1028A Module") - mhdpfwbin=$(mktemp) - /usr/lib/apt/apt-helper download-file \ - "https://source.mnt.re/reform/reform-ls1028a-uboot/-/raw/main/ls1028a-mhdpfw.bin" \ - "$mhdpfwbin" "SHA1:fa96b9aa59d7c1e9e6ee1c0375d0bcc8f8e5b78c" >/dev/null - if [ ! -e /boot/ls1028a-mhdpfw.bin ]; then - echo "W: /boot/ls1028a-mhdpfw.bin doesn't exist" >&2 - echo "W: You can download the latest version by running as root:" >&2 - echo "reform-flash-uboot" >&2 - elif ! cmp --quiet /boot/ls1028a-mhdpfw.bin "$mhdpfwbin"; then - echo "W: /boot/ls1028a-mhdpfw.bin is not the latest uboot" >&2 - echo "W: You can update it to the latest version by running as root:" >&2 - echo "reform-flash-uboot" >&2 - fi - rm "$mhdpfwbin" - ;; + mhdpfwbin=$(mktemp) + /usr/lib/apt/apt-helper download-file \ + "https://source.mnt.re/reform/reform-ls1028a-uboot/-/raw/main/ls1028a-mhdpfw.bin" \ + "$mhdpfwbin" "SHA1:fa96b9aa59d7c1e9e6ee1c0375d0bcc8f8e5b78c" >/dev/null + if [ ! -e /boot/ls1028a-mhdpfw.bin ]; then + echo "W: /boot/ls1028a-mhdpfw.bin doesn't exist" >&2 + echo "W: You can download the latest version by running as root:" >&2 + echo "reform-flash-uboot" >&2 + elif ! cmp --quiet /boot/ls1028a-mhdpfw.bin "$mhdpfwbin"; then + echo "W: /boot/ls1028a-mhdpfw.bin is not the latest uboot" >&2 + echo "W: You can update it to the latest version by running as root:" >&2 + echo "reform-flash-uboot" >&2 + fi + rm "$mhdpfwbin" + ;; esac if [ "$EMMC_USE" = true ] && [ ! -e "/dev/${DEV_MMC}p2" ]; then - echo "W: /dev/${DEV_MMC}p2 doesn't exist." >&2 - echo "W: To update your eMMC to sysimage-v4 you can run reform-flash-rescue" >&2 - echo "W: Only run reform-flash-rescue if you intend a factory-reset of your eMMC" >&2 - echo "W: Do not use reform-flash-rescue if you boot from eMMC because this will overwrite your /boot partition" >&2 + echo "W: /dev/${DEV_MMC}p2 doesn't exist." >&2 + echo "W: To update your eMMC to sysimage-v4 you can run reform-flash-rescue" >&2 + echo "W: Only run reform-flash-rescue if you intend a factory-reset of your eMMC" >&2 + echo "W: Do not use reform-flash-rescue if you boot from eMMC because this will overwrite your /boot partition" >&2 fi if [ ! -e /etc/flash-kernel/machine ]; then - # /etc/flash-kernel/machine not existing is only a potential problem - # on imx8mq - case "$(cat /proc/device-tree/model)" in - "MNT Reform 2"|"MNT Reform 2 HDMI") - echo "E: /etc/flash-kernel/machine doesn't exist" >&2 - echo "E: It should contain either 'MNT Reform 2' (for single display) or 'MNT Reform 2 HDMI' (for dual display)." >&2 - echo "E: You can run reform-display-config as root to create a working version." >&2 - ;; - esac + # /etc/flash-kernel/machine not existing is only a potential problem + # on imx8mq + case "$(cat /proc/device-tree/model)" in + "MNT Reform 2" | "MNT Reform 2 HDMI") + echo "E: /etc/flash-kernel/machine doesn't exist" >&2 + echo "E: It should contain either 'MNT Reform 2' (for single display) or 'MNT Reform 2 HDMI' (for dual display)." >&2 + echo "E: You can run reform-display-config as root to create a working version." >&2 + ;; + esac else - case "$(cat /etc/flash-kernel/machine)" in - "MNT Reform 2") : ;; - "MNT Reform 2 HDMI") : ;; - "MNT Reform 2 with BPI-CM4 Module") echo "W: /etc/flash-kernel/machine is not needed on A311D. Consider removing it." >&2 ;; - "MNT Reform 2 with LS1028A Module") echo "W: /etc/flash-kernel/machine is not needed on LS1028A. Consider removing it." >&2 ;; - *) echo "E: unexpected content in /etc/flash-kernel/machine" >&2 ;; - esac + case "$(cat /etc/flash-kernel/machine)" in + "MNT Reform 2") : ;; + "MNT Reform 2 HDMI") : ;; + "MNT Reform 2 with BPI-CM4 Module") echo "W: /etc/flash-kernel/machine is not needed on A311D. Consider removing it." >&2 ;; + "MNT Reform 2 with LS1028A Module") echo "W: /etc/flash-kernel/machine is not needed on LS1028A. Consider removing it." >&2 ;; + *) echo "E: unexpected content in /etc/flash-kernel/machine" >&2 ;; + esac fi flashkerneldefaultcontent="LINUX_KERNEL_CMDLINE=\"\"\nLINUX_KERNEL_CMDLINE_DEFAULTS=\"\"\n" if [ ! -e /etc/default/flash-kernel ]; then - echo "E: /etc/default/flash-kernel doesn't exist" >&2 - echo "E: /etc/default/flash-kernel should contain the following lines:" >&2 - printf "$flashkerneldefaultcontent" >&2 + echo "E: /etc/default/flash-kernel doesn't exist" >&2 + echo "E: /etc/default/flash-kernel should contain the following lines:" >&2 + printf "$flashkerneldefaultcontent" >&2 else - if ! printf "$flashkerneldefaultcontent" | cmp --quiet - /etc/default/flash-kernel; then - echo "W: unexpected content in /etc/default/flash-kernel:" >&2 - printf "$flashkerneldefaultcontent" | diff -u - /etc/default/flash-kernel || true - fi + if ! printf "$flashkerneldefaultcontent" | cmp --quiet - /etc/default/flash-kernel; then + echo "W: unexpected content in /etc/default/flash-kernel:" >&2 + printf "$flashkerneldefaultcontent" | diff -u - /etc/default/flash-kernel || true + fi fi if [ -e /etc/flash-kernel/preboot.d/00reform2_preboot ]; then - if printf "# place here any u-boot commands to be executed before boot\n" | cmp --quiet - /etc/flash-kernel/preboot.d/00reform2_preboot; then - echo "E: /etc/flash-kernel/preboot.d/00reform2_preboot contains default content overriding /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 - echo "E: consider deleting /etc/flash-kernel/preboot.d/00reform2_preboot in favour of /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 - else - echo "W: your custom /etc/flash-kernel/preboot.d/00reform2_preboot is overriding /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 - fi + if printf "# place here any u-boot commands to be executed before boot\n" | cmp --quiet - /etc/flash-kernel/preboot.d/00reform2_preboot; then + echo "E: /etc/flash-kernel/preboot.d/00reform2_preboot contains default content overriding /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 + echo "E: consider deleting /etc/flash-kernel/preboot.d/00reform2_preboot in favour of /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 + else + echo "W: your custom /etc/flash-kernel/preboot.d/00reform2_preboot is overriding /usr/share/flash-kernel/preboot.d/00reform2_preboot" >&2 + fi fi if [ -e /etc/flash-kernel/ubootenv.d/00reform2_ubootenv ]; then - if printf '# setenv bootpart "1"\n# setenv prefix "/"\n# setenv kernel_addr_r "0x40480000"\n# setenv fdt_addr_r "0x50000000"\n# setenv ramdisk_addr_r "0x51000000"\n' | cmp --quiet - /etc/flash-kernel/ubootenv.d/00reform2_ubootenv; then - echo "E: /etc/flash-kernel/ubootenv.d/00reform2_ubootenv contains default content overriding /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" >&2 - echo "E: consider deleting /etc/flash-kernel/ubootenv.d/00reform2_ubootenv in favour of /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" >&2 - else - echo "W: your custom /etc/flash-kernel/ubootenv.d/00reform2_ubootenv is overriding /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" - fi + if printf '# setenv bootpart "1"\n# setenv prefix "/"\n# setenv kernel_addr_r "0x40480000"\n# setenv fdt_addr_r "0x50000000"\n# setenv ramdisk_addr_r "0x51000000"\n' | cmp --quiet - /etc/flash-kernel/ubootenv.d/00reform2_ubootenv; then + echo "E: /etc/flash-kernel/ubootenv.d/00reform2_ubootenv contains default content overriding /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" >&2 + echo "E: consider deleting /etc/flash-kernel/ubootenv.d/00reform2_ubootenv in favour of /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" >&2 + else + echo "W: your custom /etc/flash-kernel/ubootenv.d/00reform2_ubootenv is overriding /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv" + fi fi initramfstoolsmodulescontent="pwm_imx27\nnwl-dsi\nti-sn65dsi86\nimx-dcss\npanel-edp\nmux-mmio\nmxsfb\nusbhid\nimx8mq-interconnect\n" if [ -e /etc/initramfs-tools/modules ] && printf "$initramfstoolsmodulescontent" | cmp --quiet - /etc/initramfs-tools/modules; then - echo "W: /etc/initramfs-tools/modules contains default content superseded by /usr/share/initramfs-tools/modules.d/reform.conf" >&2 - echo "W: consider restoring /etc/initramfs-tools/modules to its original state by running:" >&2 - echo "sed '/^###/d' /usr/share/initramfs-tools/modules | sudo tee /etc/initramfs-tools/modules" >&2 + echo "W: /etc/initramfs-tools/modules contains default content superseded by /usr/share/initramfs-tools/modules.d/reform.conf" >&2 + echo "W: consider restoring /etc/initramfs-tools/modules to its original state by running:" >&2 + echo "sed '/^###/d' /usr/share/initramfs-tools/modules | sudo tee /etc/initramfs-tools/modules" >&2 fi if [ ! -e /etc/motd ]; then - echo "I: /etc/motd does not exist" >&2 + echo "I: /etc/motd does not exist" >&2 elif [ ! -L /etc/motd ]; then - echo "I: /etc/motd does not exist" >&2 + echo "I: /etc/motd does not exist" >&2 elif [ "$(readlink /etc/motd)" != "motd-rescue" ] && [ "$(readlink /etc/motd)" != "motd-full" ]; then - echo "I: /etc/motd does neither point to motd-rescue nor to motd-full" >&2 + echo "I: /etc/motd does neither point to motd-rescue nor to motd-full" >&2 fi if grep --quiet '^root::' /etc/shadow; then - echo "E: root account has no password (maybe run passwd -l root)" >&2 + echo "E: root account has no password (maybe run passwd -l root)" >&2 fi if [ ! -e /etc/skel/.profile ]; then - echo "E: /etc/skel/.profile doesn't exist" >&2 - echo "E: install the package bash to create it" >&2 + echo "E: /etc/skel/.profile doesn't exist" >&2 + echo "E: install the package bash to create it" >&2 else - # shellcheck disable=SC2016 - skelprofilecontent='if [ "$(whoami)" = "root" ]; then reform-help --root; elif [ -z "$WAYLAND_DISPLAY" ]; then reform-help; fi' - if [ "$(tail -1 /etc/skel/.profile)" != "$skelprofilecontent" ]; then - echo "E: unexpected last line in /etc/skel/.profile, should be:" >&2 - echo "$skelprofilecontent" >&2 - fi + # shellcheck disable=SC2016 + skelprofilecontent='if [ "$(whoami)" = "root" ]; then reform-help --root; elif [ -z "$WAYLAND_DISPLAY" ]; then reform-help; fi' + if [ "$(tail -1 /etc/skel/.profile)" != "$skelprofilecontent" ]; then + echo "E: unexpected last line in /etc/skel/.profile, should be:" >&2 + echo "$skelprofilecontent" >&2 + fi fi if [ -n "$(dpkg --verify reform-tools)" ]; then - echo "I: the following files differ from how they are shipped by reform-tools:" >&2 - dpkg --verify reform-tools + echo "I: the following files differ from how they are shipped by reform-tools:" >&2 + dpkg --verify reform-tools fi # shellcheck disable=SC2016 case "$MIRROR" in mntre.com) - if [ "$(apt-get indextargets 'Created-By: Packages' 'Repo-URI: https://mntre.com/reform-debian-repo/' --format '$(RELEASE)')" != reform ]; then - echo "E: the reform repository is not known to apt" >&2 - echo "E: add the following line to your /etc/apt/sources.list to fix this" >&2 - echo "deb [arch=arm64 trusted=yes] https://mntre.com/reform-debian-repo reform main" >&2 - fi;; + if [ "$(apt-get indextargets 'Created-By: Packages' 'Repo-URI: https://mntre.com/reform-debian-repo/' --format '$(RELEASE)')" != reform ]; then + echo "E: the reform repository is not known to apt" >&2 + echo "E: add the following line to your /etc/apt/sources.list to fix this" >&2 + echo "deb [arch=arm64 trusted=yes] https://mntre.com/reform-debian-repo reform main" >&2 + fi + ;; reform.debian.net) - case "$(apt-get indextargets 'Created-By: Packages' 'Repo-URI: https://reform.debian.net/debian/' --format '$(RELEASE)')" in - bookworm*) : ;; - *) echo "E: the reform.debian.net repository is not known to apt" >&2;; - esac;; + case "$(apt-get indextargets 'Created-By: Packages' 'Repo-URI: https://reform.debian.net/debian/' --format '$(RELEASE)')" in + bookworm*) : ;; + *) echo "E: the reform.debian.net repository is not known to apt" >&2 ;; + esac + ;; *) - echo "invalid mirror: $MIRROR" >&2 - exit 1 + echo "invalid mirror: $MIRROR" >&2 + exit 1 + ;; esac # on a311d we need non-free-firmware # shellcheck disable=SC2016 if [ "$NEED_NONFREE" = true ] && ! apt-get indextargets 'Created-By: Packages' 'Origin: Debian' 'Repo-URI: http://deb.debian.org/debian/' --format '$(COMPONENT)' | sort -u | grep --silent non-free-firmware; then - echo "W: you do not have non-free-firmware enabled" >&2 - echo "W: this is required to install non-free firmware blobs that are required for platforms like Banana Pi A311D" >&2 - echo "W: you can add a line like this to your /etc/apt/sources.list:" >&2 - echo "deb http://deb.debian.org/debian unstable non-free-firmware" >&2 + echo "W: you do not have non-free-firmware enabled" >&2 + echo "W: this is required to install non-free firmware blobs that are required for platforms like Banana Pi A311D" >&2 + echo "W: you can add a line like this to your /etc/apt/sources.list:" >&2 + echo "deb http://deb.debian.org/debian unstable non-free-firmware" >&2 fi if dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-arm64" 2>/dev/null | grep -q '^installed$'; then - case "$MIRROR" in mntre.com) - if ! apt-cache policy linux-image-arm64 | grep --quiet mntre.com; then - echo "E: the linux-image-arm64 package cannot come from the MNT repos" >&2 - fi - ;; - reform.debian.net) - if ! apt-cache policy linux-image-arm64 | grep --quiet /reform.debian.net/; then - echo "E: the linux-image-arm64 package cannot come from the reform.debian.net repos" >&2 - fi - ;; - *) - echo "invalid mirror: $MIRROR" >&2 - exit 1 - esac - echo "W: The deprecated meta-package linux-image-arm64 is installed." >&2 - if dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-mnt-reform-arm64" 2>/dev/null | grep -q '^installed$'; then - echo "W: Since the new meta-package linux-image-mnt-reform-arm64 is installed," >&2 - echo "W: the old meta-package linux-image-arm64 should be removed." >&2 - else - echo "W: Please install the new meta-package linux-image-mnt-reform-arm64" >&2 - echo "W: and remove the old meta-package linux-image-arm64." >&2 - fi - if ! dpkg-query --showformat '${Version}' --show linux-image-arm64 | grep --quiet reform; then - echo "E: the currently installed package linux-image-arm64 does not come with Reform patches" >&2 - fi + case "$MIRROR" in mntre.com) + if ! apt-cache policy linux-image-arm64 | grep --quiet mntre.com; then + echo "E: the linux-image-arm64 package cannot come from the MNT repos" >&2 + fi + ;; + reform.debian.net) + if ! apt-cache policy linux-image-arm64 | grep --quiet /reform.debian.net/; then + echo "E: the linux-image-arm64 package cannot come from the reform.debian.net repos" >&2 + fi + ;; + *) + echo "invalid mirror: $MIRROR" >&2 + exit 1 + ;; + esac + echo "W: The deprecated meta-package linux-image-arm64 is installed." >&2 + if dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-mnt-reform-arm64" 2>/dev/null | grep -q '^installed$'; then + echo "W: Since the new meta-package linux-image-mnt-reform-arm64 is installed," >&2 + echo "W: the old meta-package linux-image-arm64 should be removed." >&2 + else + echo "W: Please install the new meta-package linux-image-mnt-reform-arm64" >&2 + echo "W: and remove the old meta-package linux-image-arm64." >&2 + fi + if ! dpkg-query --showformat '${Version}' --show linux-image-arm64 | grep --quiet reform; then + echo "E: the currently installed package linux-image-arm64 does not come with Reform patches" >&2 + fi fi if dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-mnt-reform-arm64" 2>/dev/null | grep -q '^installed$'; then - case "$MIRROR" in mntre.com) - if ! apt-cache policy linux-image-mnt-reform-arm64 | grep --quiet mntre.com; then - echo "E: the linux-image-mnt-reform-arm64 package cannot come from the MNT repos" >&2 - fi - ;; - reform.debian.net) - if ! apt-cache policy linux-image-mnt-reform-arm64 | grep --quiet /reform.debian.net/; then - echo "E: the linux-image-mnt-reform-arm64 package cannot come from the reform.debian.net repos" >&2 - fi - ;; - *) - echo "invalid mirror: $MIRROR" >&2 - exit 1 - esac + case "$MIRROR" in mntre.com) + if ! apt-cache policy linux-image-mnt-reform-arm64 | grep --quiet mntre.com; then + echo "E: the linux-image-mnt-reform-arm64 package cannot come from the MNT repos" >&2 + fi + ;; + reform.debian.net) + if ! apt-cache policy linux-image-mnt-reform-arm64 | grep --quiet /reform.debian.net/; then + echo "E: the linux-image-mnt-reform-arm64 package cannot come from the reform.debian.net repos" >&2 + fi + ;; + *) + echo "invalid mirror: $MIRROR" >&2 + exit 1 + ;; + esac fi for file in /boot/initrd.img-*-reform2-arm64 /boot/vmlinuz-*-reform2-arm64; do - if [ ! -e "$file" ]; then - continue - fi - echo "I: file from deprecated kernel flavour found: $file" >&2 + if [ ! -e "$file" ]; then + continue + fi + echo "I: file from deprecated kernel flavour found: $file" >&2 done for file in /boot/initrd.img-*-mnt-reform-arm64 /boot/vmlinuz-*-mnt-reform-arm64; do - suffix="${file##/boot/}" - suffix="${suffix##initrd.img-}" - suffix="${suffix##vmlinuz-}" - if ! dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-$suffix" 2>/dev/null | grep -q '^installed$'; then - echo "I: $file does not belong to any installed kernel package" >&2 - fi + suffix="${file##/boot/}" + suffix="${suffix##initrd.img-}" + suffix="${suffix##vmlinuz-}" + if ! dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-$suffix" 2>/dev/null | grep -q '^installed$'; then + echo "I: $file does not belong to any installed kernel package" >&2 + fi done if ! dpkg-query --showformat '${db:Status-Status}\n' --show "linux-image-$(uname -r)" 2>/dev/null | grep -q '^installed$'; then - echo "E: the currently running kernel is not installed as a package" >&2 + echo "E: the currently running kernel is not installed as a package" >&2 fi if [ ! -e /boot/boot.scr ]; then - echo "E: /boot/boot.scr doesn't exist" >&2 - echo "E: run 'sudo flash-kernel' to create it" >&2 + echo "E: /boot/boot.scr doesn't exist" >&2 + echo "E: run 'sudo flash-kernel' to create it" >&2 elif ! grep --quiet "setenv fk_kvers '$(uname -r)'" /boot/boot.scr; then - echo "E: /boot/boot.scr doesn't reference the currently running kernel" >&2 + echo "E: /boot/boot.scr doesn't reference the currently running kernel" >&2 fi if [ ! -e "/boot/vmlinuz-$(uname -r)" ]; then - echo "E: no vmlinuz in /boot for the currently running kernel" >&2 + echo "E: no vmlinuz in /boot for the currently running kernel" >&2 fi if [ ! -e "/boot/initrd.img-$(uname -r)" ]; then - echo "E: no initrd.img in /boot for the currently running kernel" >&2 + echo "E: no initrd.img in /boot for the currently running kernel" >&2 fi if [ ! -e "/boot/dtb-$(uname -r)" ]; then - echo "E: no dtb-* symlink for the currently running kernel" >&2 - echo "E: run 'sudo flash-kernel' to create it" >&2 + echo "E: no dtb-* symlink for the currently running kernel" >&2 + echo "E: run 'sudo flash-kernel' to create it" >&2 elif [ ! -e "/boot/dtbs/$(uname -r)/$DTBPATH" ]; then - echo "E: device tree file $DTBPATH is missing from /boot/dtbs" >&2 + echo "E: device tree file $DTBPATH is missing from /boot/dtbs" >&2 elif [ "$(readlink "/boot/dtb-$(uname -r)")" != "dtbs/$(uname -r)/$DTBPATH" ]; then - echo "E: /boot/dtb-* symlink does not reference $DTBPATH" >&2 + echo "E: /boot/dtb-* symlink does not reference $DTBPATH" >&2 fi if [ -e "/etc/modprobe.d/reform.conf" ]; then - if cmp --quiet "/usr/lib/modprobe.d/reform.conf" "/etc/modprobe.d/reform.conf"; then - echo "W: /etc/modprobe.d/reform.conf is identical to /usr/lib/modprobe.d/reform.conf" >&2 - echo "W: and the latter succeeds the former. Consider deleting the former in favour of the latter." >&2 - else - echo "W: your custom /etc/modprobe.d/reform.conf overrides /usr/lib/modprobe.d/reform.conf" >&2 - fi + if cmp --quiet "/usr/lib/modprobe.d/reform.conf" "/etc/modprobe.d/reform.conf"; then + echo "W: /etc/modprobe.d/reform.conf is identical to /usr/lib/modprobe.d/reform.conf" >&2 + echo "W: and the latter succeeds the former. Consider deleting the former in favour of the latter." >&2 + else + echo "W: your custom /etc/modprobe.d/reform.conf overrides /usr/lib/modprobe.d/reform.conf" >&2 + fi fi if [ -e /proc/modules ] && ! grep --quiet '^reform2_lpc ' /proc/modules; then - echo "E: reform2_lpc is not loaded" >&2 + echo "E: reform2_lpc is not loaded" >&2 fi if [ ! -e "/usr/lib/modules/$(uname -r)/updates/dkms/reform2_lpc.ko" ] \ -&& [ ! -e "/usr/lib/modules/$(uname -r)/updates/dkms/reform2_lpc.ko.xz" ]; then - echo "E: /usr/lib/modules/$(uname -r)/updates/dkms/reform2_lpc.ko{.xz} does not exist" >&2 + && [ ! -e "/usr/lib/modules/$(uname -r)/updates/dkms/reform2_lpc.ko.xz" ]; then + echo "E: /usr/lib/modules/$(uname -r)/updates/dkms/reform2_lpc.ko{.xz} does not exist" >&2 fi worddiff() { - for word in $1; do - case $2 in - "$word"|"$word "*|*" $word"|*" $word "*) : ;; - *) echo "$word" ;; - esac - done + for word in $1; do + case $2 in + "$word" | "$word "* | *" $word" | *" $word "*) : ;; + *) echo "$word" ;; + esac + done } -if [ "$(tr ' ' '\n' < /proc/cmdline | sort -u)" != "$(echo "$BOOTARGS" | tr ' ' '\n' | sort -u)" ]; then - if [ -n "$(worddiff "$(cat /proc/cmdline)" "$BOOTARGS")" ]; then - echo "I: kernel boot parameters your system does use but which are not the default:" >&2 - worddiff "$(cat /proc/cmdline)" "$BOOTARGS" | sed 's/^/ + /' >&2 - fi - if [ -n "$(worddiff "$BOOTARGS" "$(cat /proc/cmdline)")" ]; then - echo "I: kernel boot parameters which are the default but your system doesn't use them:" >&2 - worddiff "$BOOTARGS" "$(cat /proc/cmdline)" | sed 's/^/ - /' >&2 - fi +if [ "$(tr ' ' '\n' </proc/cmdline | sort -u)" != "$(echo "$BOOTARGS" | tr ' ' '\n' | sort -u)" ]; then + if [ -n "$(worddiff "$(cat /proc/cmdline)" "$BOOTARGS")" ]; then + echo "I: kernel boot parameters your system does use but which are not the default:" >&2 + worddiff "$(cat /proc/cmdline)" "$BOOTARGS" | sed 's/^/ + /' >&2 + fi + if [ -n "$(worddiff "$BOOTARGS" "$(cat /proc/cmdline)")" ]; then + echo "I: kernel boot parameters which are the default but your system doesn't use them:" >&2 + worddiff "$BOOTARGS" "$(cat /proc/cmdline)" | sed 's/^/ - /' >&2 + fi fi -if [ "$(tr ' ' '\n' < /proc/cmdline | grep console= | tail -1)" != "console=tty1" ]; then - echo "W: The last console= parameter in your cmdline is not console=tty1." >&2 - echo "W: This could lead to the luks password prompt being printed to serial instead of your screen." >&2 +if [ "$(tr ' ' '\n' </proc/cmdline | grep console= | tail -1)" != "console=tty1" ]; then + echo "W: The last console= parameter in your cmdline is not console=tty1." >&2 + echo "W: This could lead to the luks password prompt being printed to serial instead of your screen." >&2 fi if ! dpkg-query --showformat '${db:Status-Status}\n' --show "linux-headers-$(uname -r)" 2>/dev/null | grep -q '^installed$'; then - echo "E: the linux header package linux-headers-$(uname -r) for the currently running kernel is not installed" >&2 + echo "E: the linux header package linux-headers-$(uname -r) for the currently running kernel is not installed" >&2 fi diff --git a/bin/reform-help b/bin/reform-help index ee17e3d440b117bd40c25a8cd4f8244c1493173c..0722564b6186a27471dfa88047e1f5d4e81faaeb 100755 --- a/bin/reform-help +++ b/bin/reform-help @@ -3,17 +3,17 @@ set -eu usage() { - echo "Prints help text for how to use the MNT Reform." >&2 - echo >&2 - echo "Usage: $0 [--desktop,--root]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --desktop Print the MNT Reform desktop help text." >&2 - echo " --root Print the MNT Reform root shell help text." >&2 + echo "Prints help text for how to use the MNT Reform." >&2 + echo >&2 + echo "Usage: $0 [--desktop,--root]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --desktop Print the MNT Reform desktop help text." >&2 + echo " --root Print the MNT Reform root shell help text." >&2 } -reform_help () { - cat << 'END' +reform_help() { + cat <<'END' Some useful commands to explore the system: Learn more about a command: [1mman[0m [1;4mname-of-command[0m @@ -31,27 +31,30 @@ List hardware/peripherals: [1mlsblk[0m [1mip a[0m View this message again: [1mreform-help[0m END - case "$(cat /proc/device-tree/model)" in - "MNT Pocket Reform with "*) - cat << 'END' ;; + case "$(cat /proc/device-tree/model)" in + "MNT Pocket Reform with "*) + cat <<'END' Read the Operator Handbook: [1mpocket-reform-handbook[0m (press % to fix contrast, Q to quit) END - *) - cat << 'END' ;; + ;; + *) + cat <<'END' Read the Operator Handbook: [1mreform-handbook[0m (press % to fix contrast, Q to quit) END - esac - cat << 'END' + ;; + esac + cat <<'END' Set keyboard layout and timezone: [1msudo reform-config[0m Chat in Reform community: [1mreform-chat[0m Select boot device: [1msudo reform-boot-config[0m END - case "$(cat /proc/device-tree/model)" in "MNT Reform 2"|"MNT Reform 2 HDMI") - cat << 'END' ;; + case "$(cat /proc/device-tree/model)" in "MNT Reform 2" | "MNT Reform 2 HDMI") + cat <<'END' Select display configuration: [1msudo reform-display-config[0m # imx8mq only END - esac - cat << 'END' + ;; + esac + cat <<'END' Set up encrypted NVMe: [1msudo reform-setup-encrypted-nvme[0m Update / install software: [1msudo apt update[0m [1mapt search [1;4mkeyword[0m @@ -65,8 +68,8 @@ Exit the chat with /quit. END } -reform_root_help () { - cat << 'END' +reform_root_help() { + cat <<'END' You are logged in as [1mroot[0m. This account can change anything in the system. To use the graphical environment [1msway[0m, @@ -83,23 +86,25 @@ Then, log out using [1mexit[0m and log in as [1;4myour-name[0m. To read the MNT Reform Operator Handbook, enter: END - case "$(cat /proc/device-tree/model)" in - "MNT Pocket Reform with "*) - cat << 'END' ;; + case "$(cat /proc/device-tree/model)" in + "MNT Pocket Reform with "*) + cat <<'END' [1mpocket-reform-handbook[0m # (in the browser, press % # to fix contrast, Q to quit) END - *) - cat << 'END' ;; + ;; + *) + cat <<'END' [1mreform-handbook[0m # (in the browser, press % # to fix contrast, Q to quit) END - esac + ;; + esac } -reform_desktop_help () { - cat /etc/motd - cat << 'END' +reform_desktop_help() { + cat /etc/motd + cat <<'END' Welcome to the MNT Reform desktop. Useful keyboard shortcuts ([1mSUPER[0m is the MNT logo key): @@ -131,36 +136,38 @@ Customize the sway or wayfire configuration: To learn more about the command line, enter: [1mreform-help[0m END - case "$(cat /proc/device-tree/model)" in - "MNT Pocket Reform with "*) - cat << 'END' ;; + case "$(cat /proc/device-tree/model)" in + "MNT Pocket Reform with "*) + cat <<'END' Read the MNT Pocket Reform handbook in a browser: [1mpocket-reform-handbook[0m END - *) - cat << 'END' ;; + ;; + *) + cat <<'END' Read the MNT Reform handbook in a browser: [1mreform-handbook[0m END - esac - echo - reform_help + ;; + esac + echo + reform_help } if [ "$#" -eq "0" ]; then - reform_help - exit + reform_help + exit elif [ "$#" -gt "1" ]; then - echo "too many arguments" >&2 - usage - exit 1 + echo "too many arguments" >&2 + usage + exit 1 fi case "$1" in - --help) usage;; - --desktop) reform_desktop_help;; - --root) reform_root_help;; - *) - echo "unknown option: $1" >&2 - usage - exit 1 - ;; + --help) usage ;; + --desktop) reform_desktop_help ;; + --root) reform_root_help ;; + *) + echo "unknown option: $1" >&2 + usage + exit 1 + ;; esac diff --git a/bin/reform-pavucontrol b/bin/reform-pavucontrol index 787c76d3d87834ea0a39fd80ce5c002853e1415a..0f2f809da8028d57a8a23cfe75c1cfd55a6f71d5 100755 --- a/bin/reform-pavucontrol +++ b/bin/reform-pavucontrol @@ -2,23 +2,23 @@ set -eu -usage () { - echo "Kill any pavucontrol process and re-exec it." >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Kill any pavucontrol process and re-exec it." >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ]; then - if [ "$1" != "--help" ]; then - echo "E: too many arguments" >&2 - usage - exit 1 - fi - usage - exit 0 + if [ "$1" != "--help" ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + usage + exit 0 fi pkill 'pavucontrol$' diff --git a/debian/control b/debian/control index ad4a8207d9f8a06ee20d4e6bb59e4ef3b7d0d247..4bb3548aec0cb68cbbb56cf3f536f29ddf3b35f4 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Build-Depends: fontforge, help2man, python3-psutil, + shfmt <!nocheck>, Rules-Requires-Root: no Testsuite: autopkgtest-pkg-dkms diff --git a/debian/rules b/debian/rules index 507f39c249570718013ab7503dd11bd0c63c3728..87585071a4ef2fbce2801369ab7e8e6645cef797 100755 --- a/debian/rules +++ b/debian/rules @@ -39,6 +39,7 @@ execute_after_dh_auto_build: execute_after_dh_auto_test: clang-format lpc/reform2_lpc.c | diff -u - lpc/reform2_lpc.c + shfmt --posix --simplify --binary-next-line --case-indent --indent 2 --diff bin sbin kernel/* initramfs-tools/*/* flash-kernel/*/* override_dh_installsystemd: dh_installsystemd --package=reform-tools --name=reform-hw-setup diff --git a/initramfs-tools/hooks/reform b/initramfs-tools/hooks/reform index 0a93be0deecf116db9e5820e1f582f6c699b34da..dcbfcc802a53188dd7ff94eee2dbbca506555772 100755 --- a/initramfs-tools/hooks/reform +++ b/initramfs-tools/hooks/reform @@ -4,47 +4,51 @@ set -e PREREQ="" prereqs() { echo "$PREREQ"; } -case $1 in prereqs) prereqs; exit 0 ;; esac +case $1 in prereqs) + prereqs + exit 0 + ;; +esac . /usr/share/initramfs-tools/hook-functions MACHINE= if [ -e /etc/flash-kernel/machine ]; then - MACHINE=$(cat /etc/flash-kernel/machine) + MACHINE=$(cat /etc/flash-kernel/machine) elif [ -e /proc/device-tree/model ]; then - MACHINE=$(cat /proc/device-tree/model) + MACHINE=$(cat /proc/device-tree/model) fi copy_reform_font() { - copy_exec /usr/bin/setfont - copy_file Uni2-TerminusBold32x16 /usr/share/consolefonts/Uni2-TerminusBold32x16.psf.gz - } + copy_exec /usr/bin/setfont + copy_file Uni2-TerminusBold32x16 /usr/share/consolefonts/Uni2-TerminusBold32x16.psf.gz +} case $MACHINE in - "MNT Reform 2") : ;; - "MNT Reform 2 HDMI") : ;; - "MNT Reform 2 with BPI-CM4 Module") : ;; - "MNT Reform 2 with LS1028A Module") - [ "${verbose}" = "y" ] && echo "Adding firmware ls1028a-mhdpfw.bin" - copy_file firmware /boot/ls1028a-mhdpfw.bin /lib/firmware - [ "${verbose}" = "y" ] && echo "Adding /usr/bin/dmesg" - copy_exec /usr/bin/dmesg - ;; - "MNT Reform 2 with RCORE RK3588 Module") : ;; - "MNT Pocket Reform with i.MX8MP Module") - copy_reform_font - ;; - "MNT Pocket Reform with BPI-CM4 Module") - copy_reform_font - ;; - "MNT Pocket Reform with RCORE RK3588 Module") - copy_reform_font - ;; - "MNT Reform Next with RCORE RK3588 Module") : ;; - "") - echo "W: unable to deduce target machine for reform initramfs-hook" >&2 - ;; - *) - echo "W: unsupported machine: $MACHINE" >&2 - ;; + "MNT Reform 2") : ;; + "MNT Reform 2 HDMI") : ;; + "MNT Reform 2 with BPI-CM4 Module") : ;; + "MNT Reform 2 with LS1028A Module") + [ "${verbose}" = "y" ] && echo "Adding firmware ls1028a-mhdpfw.bin" + copy_file firmware /boot/ls1028a-mhdpfw.bin /lib/firmware + [ "${verbose}" = "y" ] && echo "Adding /usr/bin/dmesg" + copy_exec /usr/bin/dmesg + ;; + "MNT Reform 2 with RCORE RK3588 Module") : ;; + "MNT Pocket Reform with i.MX8MP Module") + copy_reform_font + ;; + "MNT Pocket Reform with BPI-CM4 Module") + copy_reform_font + ;; + "MNT Pocket Reform with RCORE RK3588 Module") + copy_reform_font + ;; + "MNT Reform Next with RCORE RK3588 Module") : ;; + "") + echo "W: unable to deduce target machine for reform initramfs-hook" >&2 + ;; + *) + echo "W: unsupported machine: $MACHINE" >&2 + ;; esac diff --git a/initramfs-tools/scripts/reform b/initramfs-tools/scripts/reform index 42ca3c41ee49f0ac386c63cc8ccc1b014b64cc40..c39fa298338dc5f69edae742ce12ec4d6496a499 100755 --- a/initramfs-tools/scripts/reform +++ b/initramfs-tools/scripts/reform @@ -1,24 +1,24 @@ #!/bin/sh -case $1 in prereqs) exit 0;; esac +case $1 in prereqs) exit 0 ;; esac . /scripts/functions MACHINE= if [ -e /etc/flash-kernel/machine ]; then - MACHINE=$(cat /etc/flash-kernel/machine) + MACHINE=$(cat /etc/flash-kernel/machine) elif [ -e /proc/device-tree/model ]; then - MACHINE=$(cat /proc/device-tree/model) + MACHINE=$(cat /proc/device-tree/model) fi case $MACHINE in - "MNT Reform 2 with LS1028A Module") - # https://source.mnt.re/reform/reform-debian-packages/-/issues/5 - dmesg -n 7 || echo "E: failed to set kernel loglevel" >&2 - ;; - "MNT Pocket Reform"*) - for c in 1 2 3 4 5 6 7 - do setfont -C /dev/tty$c Uni2-TerminusBold32x16 - done - ;; + "MNT Reform 2 with LS1028A Module") + # https://source.mnt.re/reform/reform-debian-packages/-/issues/5 + dmesg -n 7 || echo "E: failed to set kernel loglevel" >&2 + ;; + "MNT Pocket Reform"*) + for c in 1 2 3 4 5 6 7; do + setfont -C /dev/tty$c Uni2-TerminusBold32x16 + done + ;; esac diff --git a/kernel/zz-reform-tools b/kernel/zz-reform-tools index 992d1f6f322085a434c7c4dd175e934641605592..0fdde438e6e38d969fbd10c32c5aae749bff133a 100755 --- a/kernel/zz-reform-tools +++ b/kernel/zz-reform-tools @@ -20,40 +20,40 @@ action="${action%\'}" set -u install_dtbs() { - for CONF in /usr/share/reform-tools/machines/*.conf; do - . "$CONF" - if [ ! -d "/usr/lib/linux-image-$version" ]; then - echo "E: /usr/lib/linux-image-$version does not exist" >&2 - continue - fi - dtb=$(find "/usr/lib/linux-image-$version" -wholename "*/$DTBPATH" 2>/dev/null | head -n 1) - if [ -z "$dtb" ]; then - echo "E: no dtb for $DTBPATH in /usr/lib/linux-image-$version" >&2 - continue - elif [ ! -f "$dtb" ]; then - echo "E: $dtb does not exist" >&2 - continue - fi - if [ ! -e "/usr/lib/linux-image-$version/$DTBPATH" ]; then - echo "W: irregular dtb path: $dtb" >&2 - fi - mkdir -p "/boot/dtbs/$version/$(dirname "$DTBPATH")" - cp "$dtb" "/boot/dtbs/$version/$DTBPATH" - done + for CONF in /usr/share/reform-tools/machines/*.conf; do + . "$CONF" + if [ ! -d "/usr/lib/linux-image-$version" ]; then + echo "E: /usr/lib/linux-image-$version does not exist" >&2 + continue + fi + dtb=$(find "/usr/lib/linux-image-$version" -wholename "*/$DTBPATH" 2>/dev/null | head -n 1) + if [ -z "$dtb" ]; then + echo "E: no dtb for $DTBPATH in /usr/lib/linux-image-$version" >&2 + continue + elif [ ! -f "$dtb" ]; then + echo "E: $dtb does not exist" >&2 + continue + fi + if [ ! -e "/usr/lib/linux-image-$version/$DTBPATH" ]; then + echo "W: irregular dtb path: $dtb" >&2 + fi + mkdir -p "/boot/dtbs/$version/$(dirname "$DTBPATH")" + cp "$dtb" "/boot/dtbs/$version/$DTBPATH" + done } remove_dtbs() { - for CONF in /usr/share/reform-tools/machines/*.conf; do - . "$CONF" - rm -f "/boot/dtbs/$version/$DTBPATH" || : - done - rmdir --ignore-fail-on-non-empty "/boot/dtbs/$version" + for CONF in /usr/share/reform-tools/machines/*.conf; do + . "$CONF" + rm -f "/boot/dtbs/$version/$DTBPATH" || : + done + rmdir --ignore-fail-on-non-empty "/boot/dtbs/$version" } case "$self:$action" in - # Only run on postinst configure and postrm remove, to avoid wasting - # time by calling this script multiple times on upgrade and removal. - */postinst.d/*:configure) install_dtbs ;; - */postrm.d/*:remove) remove_dtbs ;; - *) exit 0 ;; + # Only run on postinst configure and postrm remove, to avoid wasting + # time by calling this script multiple times on upgrade and removal. + */postinst.d/*:configure) install_dtbs ;; + */postrm.d/*:remove) remove_dtbs ;; + *) exit 0 ;; esac diff --git a/sbin/reform-boot-config b/sbin/reform-boot-config index 8c4aca9e7ed445b294017ca30605d1a0429591c6..698e1cb78b576b454272af044f7e78f861e6556e 100755 --- a/sbin/reform-boot-config +++ b/sbin/reform-boot-config @@ -20,127 +20,131 @@ set -eu # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi usage_minimal() { - echo "Regenerate the initramfs and adjust /etc/fstab to boot the desired rootfs." >&2 - echo >&2 - echo "Usage: $0 [--help] [--help-full] [--emmc] DEVICE" >&2 - echo >&2 - echo "Options:" >&2 - echo " DEVICE Rootfs partition in /dev or one of sd, nvme, usb or emmc.">&2 - echo " --help Display this help and exit." >&2 - echo " --help-full Extended device-specific help output." >&2 - echo " --emmc Choose /boot partition on eMMC instead of SD-card." >&2 + echo "Regenerate the initramfs and adjust /etc/fstab to boot the desired rootfs." >&2 + echo >&2 + echo "Usage: $0 [--help] [--help-full] [--emmc] DEVICE" >&2 + echo >&2 + echo "Options:" >&2 + echo " DEVICE Rootfs partition in /dev or one of sd, nvme, usb or emmc." >&2 + echo " --help Display this help and exit." >&2 + echo " --help-full Extended device-specific help output." >&2 + echo " --emmc Choose /boot partition on eMMC instead of SD-card." >&2 } usage() { - echo "Usage: " >&2 - if [ "$EMMC_USE" = true ]; then - echo " reform-boot-config [--emmc] sd # rootfs on SD card (/dev/${DEV_SD}p2, default)." >&2 - echo " reform-boot-config [--emmc] nvme # rootfs on NVMe SSD (/dev/${DEV_SSD}p1)." >&2 - echo " reform-boot-config [--emmc] usb # rootfs on USB storage device (/dev/${DEV_USB}1)." >&2 - echo " reform-boot-config [--emmc] emmc # rootfs on eMMC (/dev/${DEV_MMC}p2)." >&2 - echo "" >&2 - echo " --emmc Record boot preference on eMMC instead of SD card." >&2 - case "$(cat /proc/device-tree/model)" in "MNT Reform 2"|"MNT Reform 2 HDMI") - echo " This is only useful with SoM dip switch turned off." >&2 ;; - esac - echo "" >&2 - echo "Choosing sd, nvme, usb or emmc will set the root partition to" >&2 - echo "/dev/${DEV_SD}p2, /dev/${DEV_SSD}p1, /dev/${DEV_USB}1 or /dev/${DEV_MMC}p2," >&2 - else - echo " reform-boot-config sd # rootfs on SD card (/dev/${DEV_SD}p2, default)." >&2 - echo " reform-boot-config nvme # rootfs on NVMe SSD (/dev/${DEV_SSD}p1)." >&2 - echo " reform-boot-config usb # rootfs on USB storage device (/dev/${DEV_USB}1)." >&2 - echo "" >&2 - echo "Choosing sd, nvme, or usb will set the root partition to" >&2 - echo "/dev/${DEV_SD}p2, /dev/${DEV_SSD}p1 or /dev/${DEV_USB}1," >&2 - fi - echo "respectively. You can choose another root partition by passing" >&2 - echo "the absolute device path starting with /dev/ explicitly." >&2 - echo "For example, to boot a rootfs on an LVM volume, run:" >&2 - echo "" >&2 - echo " reform-boot-config /dev/reformvg/root" >&2 + echo "Usage: " >&2 + if [ "$EMMC_USE" = true ]; then + echo " reform-boot-config [--emmc] sd # rootfs on SD card (/dev/${DEV_SD}p2, default)." >&2 + echo " reform-boot-config [--emmc] nvme # rootfs on NVMe SSD (/dev/${DEV_SSD}p1)." >&2 + echo " reform-boot-config [--emmc] usb # rootfs on USB storage device (/dev/${DEV_USB}1)." >&2 + echo " reform-boot-config [--emmc] emmc # rootfs on eMMC (/dev/${DEV_MMC}p2)." >&2 + echo "" >&2 + echo " --emmc Record boot preference on eMMC instead of SD card." >&2 + case "$(cat /proc/device-tree/model)" in "MNT Reform 2" | "MNT Reform 2 HDMI") + echo " This is only useful with SoM dip switch turned off." >&2 + ;; + esac + echo "" >&2 + echo "Choosing sd, nvme, usb or emmc will set the root partition to" >&2 + echo "/dev/${DEV_SD}p2, /dev/${DEV_SSD}p1, /dev/${DEV_USB}1 or /dev/${DEV_MMC}p2," >&2 + else + echo " reform-boot-config sd # rootfs on SD card (/dev/${DEV_SD}p2, default)." >&2 + echo " reform-boot-config nvme # rootfs on NVMe SSD (/dev/${DEV_SSD}p1)." >&2 + echo " reform-boot-config usb # rootfs on USB storage device (/dev/${DEV_USB}1)." >&2 + echo "" >&2 + echo "Choosing sd, nvme, or usb will set the root partition to" >&2 + echo "/dev/${DEV_SD}p2, /dev/${DEV_SSD}p1 or /dev/${DEV_USB}1," >&2 + fi + echo "respectively. You can choose another root partition by passing" >&2 + echo "the absolute device path starting with /dev/ explicitly." >&2 + echo "For example, to boot a rootfs on an LVM volume, run:" >&2 + echo "" >&2 + echo " reform-boot-config /dev/reformvg/root" >&2 } maybe_umount() { - what="$1" - printf "Should this script run 'umount %s' for you? [y/N] " "$what" - read -r response - if [ "$response" != "y" ]; then - echo "I: Not unmounting as requested." >&2 - return 1 - else - echo "I: Unmounting $what..." - ret=0 - umount "$what" || ret=$? - if [ "$ret" -eq 0 ]; then - echo "I: Unmounting $what successful." >&2 - return 0 - else - echo "E: Tried to unmount $what but failed." >&2 - return 1 - fi - fi + what="$1" + printf "Should this script run 'umount %s' for you? [y/N] " "$what" + read -r response + if [ "$response" != "y" ]; then + echo "I: Not unmounting as requested." >&2 + return 1 + else + echo "I: Unmounting $what..." + ret=0 + umount "$what" || ret=$? + if [ "$ret" -eq 0 ]; then + echo "I: Unmounting $what successful." >&2 + return 0 + else + echo "E: Tried to unmount $what but failed." >&2 + return 1 + fi + fi } if [ $# -ne 1 ] && [ $# -ne 2 ]; then - usage - exit 1 + usage + exit 1 fi if [ "$1" = "--help" ]; then - # minimal device-agnostic help output for use with help2man - usage_minimal - exit 0 + # minimal device-agnostic help output for use with help2man + usage_minimal + exit 0 elif [ "$1" = "--help-full" ]; then - usage - exit 0 + usage + exit 0 fi if [ "$(id -u)" -ne 0 ]; then - echo "reform-boot-config has to be run as root / using sudo." >&2 - exit 1 + echo "reform-boot-config has to be run as root / using sudo." >&2 + exit 1 fi BOOTPREF="$1" BOOTPART="${DEV_SD}p1" if [ "--emmc" = "$1" ]; then - if [ "$EMMC_USE" = false ]; then - echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 - exit 1 - fi - - BOOTPREF="$2" - BOOTPART="${DEV_MMC}p1" - - if [ ! -b "/dev/$BOOTPART" ]; then - echo "/dev/$BOOTPART doesn't exist -- run reform-flash-rescue" >&2 - exit 1 - fi + if [ "$EMMC_USE" = false ]; then + echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 + exit 1 + fi + + BOOTPREF="$2" + BOOTPART="${DEV_MMC}p1" + + if [ ! -b "/dev/$BOOTPART" ]; then + echo "/dev/$BOOTPART doesn't exist -- run reform-flash-rescue" >&2 + exit 1 + fi fi case $BOOTPREF in - sd) : "${ROOTPART:=${DEV_SD}p2}";; - nvme) : "${ROOTPART:=${DEV_SSD}p1}";; - usb) : "${ROOTPART:=${DEV_USB}1}";; - emmc) : "${ROOTPART:=${DEV_MMC}p2}";; - /dev/*) - if [ ! -b "$BOOTPREF" ]; then - echo "there is no block device called $BOOTPREF" >&2 - exit 1 - fi - : "${ROOTPART:=$BOOTPREF}" - ;; - *) usage; exit 1;; + sd) : "${ROOTPART:=${DEV_SD}p2}" ;; + nvme) : "${ROOTPART:=${DEV_SSD}p1}" ;; + usb) : "${ROOTPART:=${DEV_USB}1}" ;; + emmc) : "${ROOTPART:=${DEV_MMC}p2}" ;; + /dev/*) + if [ ! -b "$BOOTPREF" ]; then + echo "there is no block device called $BOOTPREF" >&2 + exit 1 + fi + : "${ROOTPART:=$BOOTPREF}" + ;; + *) + usage + exit 1 + ;; esac echo "This script selects your preferred boot medium. It writes your choice to the file /etc/fstab" @@ -155,35 +159,35 @@ ROOTPART="${ROOTPART#/dev/}" # We push each new entry to the beginning of the list so that we can use # shift to pop the first entry. cleanup() { - : "${TMPDIR:=/tmp}" - for dir; do - # $dir is either a device that has to be unmounted or an empty - # temporary directory that used to be a mountpoint - echo "cleaning up $dir" >&2 - ret=0 - if [ -d "$dir" ]; then - # special handling for /dev, /sys and /proc - case "$dir" in - */dev|*/sys|*/proc) umount "$dir" || ret=$?;; - *) rmdir "$dir" || ret=$?;; - esac - else - umount "$dir" || ret=$? - fi - if [ "$ret" != 0 ]; then - echo "cleaning up $dir failed" >&2 - fi - # remove this item from $@ - shift - done - if [ "${MOUNTROOT:-}" = "/" ]; then - ret=0 - mount /boot || ret=$? - if [ "$ret" != 0 ]; then - echo "mounting /boot failed" >&2 - fi - fi - echo reform-boot-config FAILED to run >&2 + : "${TMPDIR:=/tmp}" + for dir; do + # $dir is either a device that has to be unmounted or an empty + # temporary directory that used to be a mountpoint + echo "cleaning up $dir" >&2 + ret=0 + if [ -d "$dir" ]; then + # special handling for /dev, /sys and /proc + case "$dir" in + */dev | */sys | */proc) umount "$dir" || ret=$? ;; + *) rmdir "$dir" || ret=$? ;; + esac + else + umount "$dir" || ret=$? + fi + if [ "$ret" != 0 ]; then + echo "cleaning up $dir failed" >&2 + fi + # remove this item from $@ + shift + done + if [ "${MOUNTROOT-}" = "/" ]; then + ret=0 + mount /boot || ret=$? + if [ "$ret" != 0 ]; then + echo "mounting /boot failed" >&2 + fi + fi + echo reform-boot-config FAILED to run >&2 } set -- trap 'cleanup "$@"' EXIT INT TERM @@ -191,61 +195,61 @@ trap 'cleanup "$@"' EXIT INT TERM # check if rootfs is already mounted somewhere that is not / MOUNTROOT="$(lsblk --noheadings --output=MOUNTPOINT "/dev/$ROOTPART")" if [ "$MOUNTROOT" != "" ] && [ "$MOUNTROOT" != "/" ]; then - echo "/dev/$ROOTPART is still mounted on $MOUNTROOT." >&2 - if ! maybe_umount "/dev/$ROOTPART"; then - echo "Please unmount before running this script" >&2 - exit 1 - fi + echo "/dev/$ROOTPART is still mounted on $MOUNTROOT." >&2 + if ! maybe_umount "/dev/$ROOTPART"; then + echo "Please unmount before running this script" >&2 + exit 1 + fi fi # mount the desired root partition somewhere if it isn't mounted yet if [ "$MOUNTROOT" = "" ]; then - MOUNTROOT="$(mktemp --tmpdir --directory reform-boot-config.XXXXXXXXXX)" - set -- "/dev/$ROOTPART" "$MOUNTROOT" "$@" - mount "/dev/$ROOTPART" "$MOUNTROOT" + MOUNTROOT="$(mktemp --tmpdir --directory reform-boot-config.XXXXXXXXXX)" + set -- "/dev/$ROOTPART" "$MOUNTROOT" "$@" + mount "/dev/$ROOTPART" "$MOUNTROOT" fi if [ ! -d "$MOUNTROOT/boot" ]; then - echo "the rootfs does not contain a /boot directory" >&2 - exit 1 + echo "the rootfs does not contain a /boot directory" >&2 + exit 1 fi # find the device that was mounted as /boot according to the /etc/fstab in the # given rootfs OLDBOOTPART="$(LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --evaluate --mountpoint /boot --output SOURCE || :)" if [ -z "$OLDBOOTPART" ]; then - echo "cannot find /boot device referenced by /etc/fstab in rootfs at /dev/$ROOTPART" >&2 - exit 1 + echo "cannot find /boot device referenced by /etc/fstab in rootfs at /dev/$ROOTPART" >&2 + exit 1 fi if [ ! -e "$OLDBOOTPART" ]; then - echo "/boot device $OLDBOOTPART from /etc/fstab in /dev/$ROOTPART doesn't exist" >&2 - exit 1 + echo "/boot device $OLDBOOTPART from /etc/fstab in /dev/$ROOTPART doesn't exist" >&2 + exit 1 fi # check if the new boot is still mounted somewhere if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" ]; then - echo "/dev/$BOOTPART is still mounted somewhere, which means that it is" >&2 - echo "probably used by the currently running system and that replacing" >&2 - echo "its contents might make the currently running system unbootable." - - if [ "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" != "/boot" ]; then - echo "W: /dev/$BOOTPART was expected to be mounted at /boot, but was found be" >&2 - echo "W: mounted at $(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" >&2 - fi - - if ! maybe_umount "/dev/$BOOTPART"; then - echo "Please unmount before running this script" >&2 - exit 1 - fi + echo "/dev/$BOOTPART is still mounted somewhere, which means that it is" >&2 + echo "probably used by the currently running system and that replacing" >&2 + echo "its contents might make the currently running system unbootable." + + if [ "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" != "/boot" ]; then + echo "W: /dev/$BOOTPART was expected to be mounted at /boot, but was found be" >&2 + echo "W: mounted at $(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" >&2 + fi + + if ! maybe_umount "/dev/$BOOTPART"; then + echo "Please unmount before running this script" >&2 + exit 1 + fi fi # check that the new mountpoint for /boot is empty if mountpoint --quiet "$MOUNTROOT/boot"; then - echo "Something is still mounted on $MOUNTROOT/boot." >&2 - if ! maybe_umount "$MOUNTROOT/boot"; then - echo "Please unmount before running this script" >&2 - exit 1 - fi + echo "Something is still mounted on $MOUNTROOT/boot." >&2 + if ! maybe_umount "$MOUNTROOT/boot"; then + echo "Please unmount before running this script" >&2 + exit 1 + fi fi # mount the new boot partition @@ -253,58 +257,58 @@ set -- "/dev/$BOOTPART" "$@" mount "/dev/$BOOTPART" "$MOUNTROOT/boot" if [ "$OLDBOOTPART" = "/dev/$BOOTPART" ]; then - echo "the /boot partition /dev/$BOOTPART referenced by the rootfs at /dev/$ROOTPART remains the same" >&2 + echo "the /boot partition /dev/$BOOTPART referenced by the rootfs at /dev/$ROOTPART remains the same" >&2 else - # copy the contents of the old /boot to the new /boot - OLDMOUNTBOOT="$(lsblk --noheadings --output=MOUNTPOINT "$OLDBOOTPART")" - needumount="no" - if [ "$OLDMOUNTBOOT" = "" ]; then - OLDMOUNTBOOT="$(mktemp --tmpdir --directory reform-boot-config.XXXXXXXXXX)" - set -- "$OLDBOOTPART" "$OLDMOUNTBOOT" "$@" - mount "$OLDBOOTPART" "$OLDMOUNTBOOT" - needumount="yes" - fi - - rsync -axHAWXS --numeric-ids --quiet "$OLDMOUNTBOOT/" "$MOUNTROOT/boot" - if [ "$needumount" = "yes" ]; then - [ "$1" = "$OLDBOOTPART" ] && shift && umount "$OLDBOOTPART" - [ "$1" = "$OLDMOUNTBOOT" ] && shift && rmdir "$OLDMOUNTBOOT" - fi + # copy the contents of the old /boot to the new /boot + OLDMOUNTBOOT="$(lsblk --noheadings --output=MOUNTPOINT "$OLDBOOTPART")" + needumount="no" + if [ "$OLDMOUNTBOOT" = "" ]; then + OLDMOUNTBOOT="$(mktemp --tmpdir --directory reform-boot-config.XXXXXXXXXX)" + set -- "$OLDBOOTPART" "$OLDMOUNTBOOT" "$@" + mount "$OLDBOOTPART" "$OLDMOUNTBOOT" + needumount="yes" + fi + + rsync -axHAWXS --numeric-ids --quiet "$OLDMOUNTBOOT/" "$MOUNTROOT/boot" + if [ "$needumount" = "yes" ]; then + [ "$1" = "$OLDBOOTPART" ] && shift && umount "$OLDBOOTPART" + [ "$1" = "$OLDMOUNTBOOT" ] && shift && rmdir "$OLDMOUNTBOOT" + fi fi -if LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --source "/dev/$ROOTPART" --mountpoint "/" >/dev/null && \ - LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --source "/dev/$BOOTPART" --mountpoint "/boot" >/dev/null; then - echo "/etc/fstab already contains the correct entries" >&2 +if LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --source "/dev/$ROOTPART" --mountpoint "/" >/dev/null \ + && LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --noheadings --source "/dev/$BOOTPART" --mountpoint "/boot" >/dev/null; then + echo "/etc/fstab already contains the correct entries" >&2 else - echo "commenting original /etc/fstab contents" >&2 + echo "commenting original /etc/fstab contents" >&2 - SWAP= - if LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --types swap >/dev/null; then - SWAP="$(LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --noheadings --fstab --types swap --output SOURCE,TARGET,FSTYPE,OPTIONS,FREQ,PASSNO)" - fi + SWAP= + if LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --fstab --types swap >/dev/null; then + SWAP="$(LIBMOUNT_FSTAB="$MOUNTROOT/etc/fstab" findmnt --noheadings --fstab --types swap --output SOURCE,TARGET,FSTYPE,OPTIONS,FREQ,PASSNO)" + fi - sed -i -e 's/^/#/' "$MOUNTROOT/etc/fstab" - cat << END >> "$MOUNTROOT/etc/fstab" + sed -i -e 's/^/#/' "$MOUNTROOT/etc/fstab" + cat <<END >>"$MOUNTROOT/etc/fstab" /dev/$ROOTPART / auto errors=remount-ro 0 1 /dev/$BOOTPART /boot auto errors=remount-ro 0 1 END - if [ -n "$SWAP" ]; then - echo "$SWAP" >> "$MOUNTROOT/etc/fstab" - fi + if [ -n "$SWAP" ]; then + echo "$SWAP" >>"$MOUNTROOT/etc/fstab" + fi fi if [ "$MOUNTROOT" = "/" ]; then - update-initramfs -u + update-initramfs -u else - set -- "$MOUNTROOT/proc" "$MOUNTROOT/sys" "$MOUNTROOT/dev" "$@" - mount -o bind /dev "$MOUNTROOT/dev" - mount -t sysfs sys "$MOUNTROOT/sys" - mount -t proc proc "$MOUNTROOT/proc" - chroot "$MOUNTROOT" update-initramfs -u - [ "$1" = "$MOUNTROOT/proc" ] && shift && umount "$MOUNTROOT/proc" - [ "$1" = "$MOUNTROOT/sys" ] && shift && umount "$MOUNTROOT/sys" - [ "$1" = "$MOUNTROOT/dev" ] && shift && umount "$MOUNTROOT/dev" + set -- "$MOUNTROOT/proc" "$MOUNTROOT/sys" "$MOUNTROOT/dev" "$@" + mount -o bind /dev "$MOUNTROOT/dev" + mount -t sysfs sys "$MOUNTROOT/sys" + mount -t proc proc "$MOUNTROOT/proc" + chroot "$MOUNTROOT" update-initramfs -u + [ "$1" = "$MOUNTROOT/proc" ] && shift && umount "$MOUNTROOT/proc" + [ "$1" = "$MOUNTROOT/sys" ] && shift && umount "$MOUNTROOT/sys" + [ "$1" = "$MOUNTROOT/dev" ] && shift && umount "$MOUNTROOT/dev" fi # unmount /boot partition @@ -312,8 +316,8 @@ fi # unmount the root partition if necessary if [ "$MOUNTROOT" != "/" ]; then - [ "$1" = "/dev/$ROOTPART" ] && shift && umount "/dev/$ROOTPART" - [ "$1" = "$MOUNTROOT" ] && shift && rmdir "$MOUNTROOT" + [ "$1" = "/dev/$ROOTPART" ] && shift && umount "/dev/$ROOTPART" + [ "$1" = "$MOUNTROOT" ] && shift && rmdir "$MOUNTROOT" fi # make sure that the cleanup array is empty now @@ -325,32 +329,32 @@ trap - EXIT INT TERM # or reformemmcboot labels in case it used to be the /boot partition from a # rescue system on sd-card or emmc, respectively case "$BOOTPART" in - "${DEV_SD}p1") - if [ "$(lsblk --noheadings --output=LABEL "/dev/$BOOTPART")" = "reformsdboot" ]; then - e2label "/dev/$BOOTPART" "" - fi - ;; - "${DEV_MMC}p1") - if [ "$(lsblk --noheadings --output=LABEL "/dev/$BOOTPART")" = "reformemmcboot" ]; then - e2label "/dev/$BOOTPART" "" - fi - ;; + "${DEV_SD}p1") + if [ "$(lsblk --noheadings --output=LABEL "/dev/$BOOTPART")" = "reformsdboot" ]; then + e2label "/dev/$BOOTPART" "" + fi + ;; + "${DEV_MMC}p1") + if [ "$(lsblk --noheadings --output=LABEL "/dev/$BOOTPART")" = "reformemmcboot" ]; then + e2label "/dev/$BOOTPART" "" + fi + ;; esac # since /boot had to be unmounted before running this script, make sure to # mount it again if [ "$MOUNTROOT" = "/" ]; then - mount /boot + mount /boot fi if [ "$EMMC_USE" = true ]; then - if [ "$BOOTPART" = "${DEV_MMC}p1" ]; then - echo "Your /boot partition is on emmc (/dev/$BOOTPART)." >&2 - else - echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 - fi + if [ "$BOOTPART" = "${DEV_MMC}p1" ]; then + echo "Your /boot partition is on emmc (/dev/$BOOTPART)." >&2 + else + echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 + fi else - echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 + echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 fi echo "Restart MNT Reform (type: reboot) after saving your work to activate the changes." diff --git a/sbin/reform-config b/sbin/reform-config index f4b54bc9a6100d061fe9b285486aaa0e0fd58966..6747bdfa1c0056eb8f5469e3abd6394d9976aa16 100755 --- a/sbin/reform-config +++ b/sbin/reform-config @@ -2,24 +2,24 @@ set -eu -usage () { - echo "Run dpkg-reconfigure for keyboard-configuration and tzdata under sudo" >&2 - echo "to configure the keyboard layout and timezone." >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Run dpkg-reconfigure for keyboard-configuration and tzdata under sudo" >&2 + echo "to configure the keyboard layout and timezone." >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ]; then - if [ "$1" != "--help" ]; then - echo "E: too many arguments" >&2 - usage - exit 1 - fi - usage - exit 0 + if [ "$1" != "--help" ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + usage + exit 0 fi sudo dpkg-reconfigure keyboard-configuration diff --git a/sbin/reform-display-config b/sbin/reform-display-config index e58e0e3403692ebc3a0f6bed0672b98b9c5b5597..711e24696db2e3863db8c21920e707c0478f79b5 100755 --- a/sbin/reform-display-config +++ b/sbin/reform-display-config @@ -2,31 +2,34 @@ set -e -usage () { - echo "On the i.MX8MQ, choose whether to use the single or dual display device tree" >&2 - echo "by writing the correct value into /etc/flash-kernel/machine and re-generating" >&2 - echo "the initramfs and running flash-kernel." >&2 - echo >&2 - echo "Usage: $0 [--help] [--emmc] dual|single" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 - echo " --emmc Record choice on /boot on eMMC." >&2 +usage() { + echo "On the i.MX8MQ, choose whether to use the single or dual display device tree" >&2 + echo "by writing the correct value into /etc/flash-kernel/machine and re-generating" >&2 + echo "the initramfs and running flash-kernel." >&2 + echo >&2 + echo "Usage: $0 [--help] [--emmc] dual|single" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 + echo " --emmc Record choice on /boot on eMMC." >&2 } if [ "$#" -gt 0 ] && [ "$1" = "--help" ]; then - usage - exit 0 + usage + exit 0 fi -if [ "$(id -u)" -ne 0 ] - then echo "reform-display-config has to be run as root / using sudo." +if [ "$(id -u)" -ne 0 ]; then + echo "reform-display-config has to be run as root / using sudo." exit fi case "$(cat /proc/device-tree/model)" in - "MNT Reform 2"|"MNT Reform 2 HDMI") : ;; - *) echo "Sorry, reform-display-config is only supported on MNT Reform 2 with i.MX8MQ processor module."; exit 1;; + "MNT Reform 2" | "MNT Reform 2 HDMI") : ;; + *) + echo "Sorry, reform-display-config is only supported on MNT Reform 2 with i.MX8MQ processor module." + exit 1 + ;; esac CHOICE="$1" @@ -34,75 +37,75 @@ BOOTPART="mmcblk1p1" BOOTDISK="SD card" if [ "--emmc" = "$1" ]; then - CHOICE="$2" - BOOTPART="mmcblk0p1" - BOOTDISK="eMMC" - - if [ ! -b "/dev/mmcblk0p1" ]; then - echo "/dev/mmcblk0p1 doesn't exist -- run reform-flash-rescue" >&2 - exit 1 - fi + CHOICE="$2" + BOOTPART="mmcblk0p1" + BOOTDISK="eMMC" + + if [ ! -b "/dev/mmcblk0p1" ]; then + echo "/dev/mmcblk0p1 doesn't exist -- run reform-flash-rescue" >&2 + exit 1 + fi fi case "$CHOICE" in - dual) - echo "MNT Reform 2 HDMI" > /etc/flash-kernel/machine - if [ -d /etc/u-boot-menu/conf.d/ ]; then - cat << END > /etc/u-boot-menu/conf.d/reform.conf + dual) + echo "MNT Reform 2 HDMI" >/etc/flash-kernel/machine + if [ -d /etc/u-boot-menu/conf.d/ ]; then + cat <<END >/etc/u-boot-menu/conf.d/reform.conf # the content of this file is auto-generated by reform-display-config U_BOOT_FDT_DIR=/dtbs/ U_BOOT_FDT=/freescale/imx8mq-mnt-reform2-hdmi.dtb END - fi - ;; - single) - echo "MNT Reform 2" > /etc/flash-kernel/machine - if [ -d /etc/u-boot-menu/conf.d/ ]; then - cat << END > /etc/u-boot-menu/conf.d/reform.conf + fi + ;; + single) + echo "MNT Reform 2" >/etc/flash-kernel/machine + if [ -d /etc/u-boot-menu/conf.d/ ]; then + cat <<END >/etc/u-boot-menu/conf.d/reform.conf # the content of this file is auto-generated by reform-display-config U_BOOT_FDT_DIR=/dtbs/ U_BOOT_FDT=/freescale/imx8mq-mnt-reform2.dtb END - fi - ;; - *) - echo "Usage: " - echo " reform-display-config dual Select dual-display support (internal + HDMI)." - echo " reform-display-config single Select only internal display (turns off HDMI)." - echo " reform-display-config --emmc dual|single Record choice on eMMC." - exit - ;; + fi + ;; + *) + echo "Usage: " + echo " reform-display-config dual Select dual-display support (internal + HDMI)." + echo " reform-display-config single Select only internal display (turns off HDMI)." + echo " reform-display-config --emmc dual|single Record choice on eMMC." + exit + ;; esac if ! findmnt --noheadings --source /dev/$BOOTPART --mountpoint /boot >/dev/null; then - echo "Assuming boot files are on $BOOTDISK, but your system doesn't have it mounted." >&2 - echo "Mounting /dev/$BOOTPART on /boot." >&2 + echo "Assuming boot files are on $BOOTDISK, but your system doesn't have it mounted." >&2 + echo "Mounting /dev/$BOOTPART on /boot." >&2 - if mountpoint --quiet /boot; then - echo "/boot already has something mounted on it" >&2 - exit 1 - fi + if mountpoint --quiet /boot; then + echo "/boot already has something mounted on it" >&2 + exit 1 + fi - if [ -n "$(lsblk --noheadings --output=MOUNTPOINT /dev/$BOOTPART)" ]; then - echo "/dev/$BOOTPART is still in use" >&2 - exit 1 - fi + if [ -n "$(lsblk --noheadings --output=MOUNTPOINT /dev/$BOOTPART)" ]; then + echo "/dev/$BOOTPART is still in use" >&2 + exit 1 + fi - trap "umount /boot" EXIT INT TERM - mount /dev/$BOOTPART /boot + trap "umount /boot" EXIT INT TERM + mount /dev/$BOOTPART /boot fi if command -v flash-kernel >/dev/null; then - flash-kernel + flash-kernel fi if command -v u-boot-update >/dev/null; then - u-boot-update + u-boot-update fi if [ "--emmc" = "$1" ]; then - echo "Your /boot partition is on emmc (/dev/$BOOTPART)." >&2 + echo "Your /boot partition is on emmc (/dev/$BOOTPART)." >&2 else - echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 + echo "Your /boot partition is on your SD-Card (/dev/$BOOTPART)." >&2 fi echo "Restart MNT Reform (type: reboot) after saving your work to activate the changes." diff --git a/sbin/reform-flash-rescue b/sbin/reform-flash-rescue index f88d55f72e29e3259d78f1b84b82f7a6406f456e..af69054798cb34f1a4d3a4a2b4e2b746bd334d4a 100755 --- a/sbin/reform-flash-rescue +++ b/sbin/reform-flash-rescue @@ -2,77 +2,77 @@ set -eu -usage () { - echo "Download and flash the latest sysimage-v4 to eMMC." >&2 - echo "Calls reform-flash-uboot to install u-boot on eMMC, grows the root" >&2 - echo "filesystem and adjusts filesystem labels." >&2 - echo "Calls reform-boot-config to set up /boot on eMMC to load the rootfs from eMMC." >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Download and flash the latest sysimage-v4 to eMMC." >&2 + echo "Calls reform-flash-uboot to install u-boot on eMMC, grows the root" >&2 + echo "filesystem and adjusts filesystem labels." >&2 + echo "Calls reform-boot-config to set up /boot on eMMC to load the rootfs from eMMC." >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ] && [ "$1" = "--help" ]; then - usage - exit 0 + usage + exit 0 fi # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi if [ "$EMMC_USE" = false ]; then - echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 + exit 1 fi if [ "$EMMC_BOOT" = true ]; then - if [ ! -e "/sys/class/block/${DEV_MMC}boot0/force_ro" ]; then - echo "/sys/class/block/${DEV_MMC}boot0/force_ro doesn't exist" >&2 - exit 1 - fi - - if [ ! -w "/sys/class/block/${DEV_MMC}boot0/force_ro" ]; then - echo "/sys/class/block/${DEV_MMC}boot0/force_ro is not writable" >&2 - exit 1 - fi - - if [ ! -e /boot/flash.bin ]; then - echo "/boot/flash.bin doesn't exist" >&2 - exit 1 - fi - - for p in $(lsblk --list --noheadings --output=NAME "/dev/$DEV_MMC") "${DEV_MMC}boot0" "${DEV_MMC}boot1"; do - [ -b "/dev/$p" ] || continue - if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$p")" ]; then - echo "/dev/$p is still in use" >&2 - exit 1 - fi - done - - echo "WARNING: This overwrites the bootloader on the eMMC rescue disk with the" >&2 - echo "backup stored as /boot/flash.bin!" >&2 - - printf "Are you sure you want to proceed? [y/N] " - read -r response - - if [ "$response" != "y" ]; then - echo "Exiting." - exit - fi - - reform-flash-uboot --offline emmc - - echo "Bootloader was successfully written to /dev/${DEV_MMC}boot0." >&2 - echo "" >&2 + if [ ! -e "/sys/class/block/${DEV_MMC}boot0/force_ro" ]; then + echo "/sys/class/block/${DEV_MMC}boot0/force_ro doesn't exist" >&2 + exit 1 + fi + + if [ ! -w "/sys/class/block/${DEV_MMC}boot0/force_ro" ]; then + echo "/sys/class/block/${DEV_MMC}boot0/force_ro is not writable" >&2 + exit 1 + fi + + if [ ! -e /boot/flash.bin ]; then + echo "/boot/flash.bin doesn't exist" >&2 + exit 1 + fi + + for p in $(lsblk --list --noheadings --output=NAME "/dev/$DEV_MMC") "${DEV_MMC}boot0" "${DEV_MMC}boot1"; do + [ -b "/dev/$p" ] || continue + if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$p")" ]; then + echo "/dev/$p is still in use" >&2 + exit 1 + fi + done + + echo "WARNING: This overwrites the bootloader on the eMMC rescue disk with the" >&2 + echo "backup stored as /boot/flash.bin!" >&2 + + printf "Are you sure you want to proceed? [y/N] " + read -r response + + if [ "$response" != "y" ]; then + echo "Exiting." + exit + fi + + reform-flash-uboot --offline emmc + + echo "Bootloader was successfully written to /dev/${DEV_MMC}boot0." >&2 + echo "" >&2 fi echo "Do you want to download and install the latest sysimage-v4 to eMMC as well?" >&2 @@ -84,54 +84,55 @@ printf "Are you sure you want to proceed? [y/N] " read -r response if [ "$response" != "y" ]; then - echo "Exiting." - exit + echo "Exiting." + exit fi URL="https://source.mnt.re/reform/reform-system-image/-/jobs/artifacts/main/raw/${SYSIMAGE}.img.gz?job=build" DECOMPRESSOR=gzip if grep --silent '^URIs: https://reform.debian.net/debian/\?$' /etc/apt/sources.list.d/reform*.sources 2>/dev/null; then - echo "The current system image is configured to use the Debian stable mirror from" >&2 - echo "reform.debian.net. Do you want to flash the system image from reform.debian.net" >&2 - echo "to your eMMC? If you answer anything but \"y\", the official MNT system image will" >&2 - echo "be downloaded and written to eMMC instead." >&2 - printf "Do you want to download and use the rescue system image from reform.debian.net? [y/N] " - - read -r response - if [ "$response" = "y" ]; then - # no need to use the backports kernel because a311d is not - # allowed to write to emmc anyways - URL="https://reform.debian.net/images/${SYSIMAGE}.img.xz" - DECOMPRESSOR=xz - fi + echo "The current system image is configured to use the Debian stable mirror from" >&2 + echo "reform.debian.net. Do you want to flash the system image from reform.debian.net" >&2 + echo 'to your eMMC? If you answer anything but "y", the official MNT system image will' >&2 + echo "be downloaded and written to eMMC instead." >&2 + printf "Do you want to download and use the rescue system image from reform.debian.net? [y/N] " + + read -r response + if [ "$response" = "y" ]; then + # no need to use the backports kernel because a311d is not + # allowed to write to emmc anyways + URL="https://reform.debian.net/images/${SYSIMAGE}.img.xz" + DECOMPRESSOR=xz + fi fi echo "Downloading $URL..." # flash with bmaptool if available and use dd otherwise if command -v bmaptool >/dev/null 2>&1; then - # force gpg signature verification when downloading from reform.d.n - case $URL in - https://reform.debian.net/images/*) - # FIXME: use --keyring and --fingerprint options from - # https://github.com/yoctoproject/bmaptool/pull/32 - bmaptool copy "$URL" "/dev/$DEV_MMC" ;; - *) bmaptool copy "$URL" "/dev/$DEV_MMC" ;; - esac + # force gpg signature verification when downloading from reform.d.n + case $URL in + https://reform.debian.net/images/*) + # FIXME: use --keyring and --fingerprint options from + # https://github.com/yoctoproject/bmaptool/pull/32 + bmaptool copy "$URL" "/dev/$DEV_MMC" + ;; + *) bmaptool copy "$URL" "/dev/$DEV_MMC" ;; + esac else - { - if curl --version >/dev/null; then - curl --silent --location "$URL" - elif wget --version >/dev/null; then - wget --quiet --output-document=- "$URL" - else - echo "need curl or wget" >&2 - exit 1 - fi; } | "$DECOMPRESSOR" --decompress --to-stdout | dd of="/dev/$DEV_MMC" status=progress + { + if curl --version >/dev/null; then + curl --silent --location "$URL" + elif wget --version >/dev/null; then + wget --quiet --output-document=- "$URL" + else + echo "need curl or wget" >&2 + exit 1 + fi + } | "$DECOMPRESSOR" --decompress --to-stdout | dd of="/dev/$DEV_MMC" status=progress fi - partprobe "/dev/$DEV_MMC" # resize the second partition to fill the emmc @@ -154,10 +155,10 @@ e2label "/dev/${DEV_MMC}p2" reformemmcroot # reform-boot-config to update the /etc/fstab and initramfs to use the eMMC reform-boot-config --emmc emmc -case "$(cat /proc/device-tree/model)" in "MNT Reform 2"|"MNT Reform 2 HDMI") - echo "If the SoM dip switch is turned off and no SD-Card is present, your" >&2 - echo "system will now boot from eMMC and load the rootfs from there as well." >&2 - echo "If you want to boot from eMMC but load the rootfs from elsewhere, run" >&2 - echo "reform-boot-config with the --emmc switch." >&2 - ;; +case "$(cat /proc/device-tree/model)" in "MNT Reform 2" | "MNT Reform 2 HDMI") + echo "If the SoM dip switch is turned off and no SD-Card is present, your" >&2 + echo "system will now boot from eMMC and load the rootfs from there as well." >&2 + echo "If you want to boot from eMMC but load the rootfs from elsewhere, run" >&2 + echo "reform-boot-config with the --emmc switch." >&2 + ;; esac diff --git a/sbin/reform-flash-uboot b/sbin/reform-flash-uboot index 822db003803ce24fb7433389ad9481dca18154fd..ffa9289c2062bfb8e71b9dc1bdd3365a94ca1dcb 100755 --- a/sbin/reform-flash-uboot +++ b/sbin/reform-flash-uboot @@ -2,201 +2,203 @@ set -eu -usage () { - echo "Download latest u-boot for the current platform and update /boot/flash.bin">&2 - echo "Then flash u-boot to DEVICE which can be one of the short-hands sd or emmc.">&2 - echo >&2 - echo "Usage: $0 [--help] [--offline] DEVICE" >&2 - echo >&2 - echo "Options:" >&2 - echo " DEVICE Either a device path in /dev or shorthands sd and emmc" >&2 - echo " --help Display this help and exit." >&2 - echo " --offline Instead of download u-boot use /boot/flash.bin." >&2 +usage() { + echo "Download latest u-boot for the current platform and update /boot/flash.bin" >&2 + echo "Then flash u-boot to DEVICE which can be one of the short-hands sd or emmc." >&2 + echo >&2 + echo "Usage: $0 [--help] [--offline] DEVICE" >&2 + echo >&2 + echo "Options:" >&2 + echo " DEVICE Either a device path in /dev or shorthands sd and emmc" >&2 + echo " --help Display this help and exit." >&2 + echo " --offline Instead of download u-boot use /boot/flash.bin." >&2 } if [ "$#" -gt 0 ] && [ "$1" = "--help" ]; then - usage - exit 0 + usage + exit 0 fi # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi if [ "$EMMC_BOOT" = false ]; then - for dev in "$@"; do - case $dev in emmc|"/dev/${DEV_MMC}"*) - echo "E: writing uboot to eMMC not supported on $(cat /proc/device-tree/model)" >&2 - exit 1 - ;; - esac - done + for dev in "$@"; do + case $dev in emmc | "/dev/${DEV_MMC}"*) + echo "E: writing uboot to eMMC not supported on $(cat /proc/device-tree/model)" >&2 + exit 1 + ;; + esac + done fi if [ "$SD_BOOT" = false ]; then - for dev in "$@"; do - case $dev in sd|"/dev/${DEV_SD}"*) - echo "E: writing uboot to SD-Card not supported on $(cat /proc/device-tree/model)" >&2 - exit 1 - ;; - esac - done + for dev in "$@"; do + case $dev in sd | "/dev/${DEV_SD}"*) + echo "E: writing uboot to SD-Card not supported on $(cat /proc/device-tree/model)" >&2 + exit 1 + ;; + esac + done fi usage() { - echo "Usage: " >&2 - echo " reform-flash-uboot [--offline] [device...]" >&2 - echo "" >&2 - if [ "$EMMC_BOOT" = true ] && [ "$SD_BOOT" = true ]; then - echo "Download and write recent uboot to eMMC or SD-Card." >&2 - elif [ "$SD_BOOT" = true ]; then - echo "Download and write recent uboot to SD-Card." >&2 - elif [ "$EMMC_BOOT" = true ]; then - echo "Download and write recent uboot to eMMC." >&2 - else - echo "Download and write recent uboot to chosen device." >&2 - fi - echo "Without arguments only /boot/flash.bin will be updated unless --offline is given." >&2 - echo "Otherwise, the arguments are the devices onto which to install uboot." >&2 - if [ "$EMMC_BOOT" = true ] && [ "$SD_BOOT" = true ]; then - echo "Two device shortcuts are provided:" >&2 - echo "" >&2 - echo " emmc -> /dev/${DEV_MMC}boot0" >&2 - echo " sd -> /dev/${DEV_SD}" >&2 - echo "" >&2 - elif [ "$SD_BOOT" = true ]; then - echo "A device shortcut is provided:" >&2 - echo "" >&2 - echo " sd -> /dev/${DEV_SD}" >&2 - echo "" >&2 - elif [ "$EMMC_BOOT" = true ]; then - echo "A device shortcut is provided:" >&2 - echo "" >&2 - echo " emmc -> /dev/${DEV_MMC}boot0" >&2 - echo "" >&2 - fi + echo "Usage: " >&2 + echo " reform-flash-uboot [--offline] [device...]" >&2 + echo "" >&2 + if [ "$EMMC_BOOT" = true ] && [ "$SD_BOOT" = true ]; then + echo "Download and write recent uboot to eMMC or SD-Card." >&2 + elif [ "$SD_BOOT" = true ]; then + echo "Download and write recent uboot to SD-Card." >&2 + elif [ "$EMMC_BOOT" = true ]; then + echo "Download and write recent uboot to eMMC." >&2 + else + echo "Download and write recent uboot to chosen device." >&2 + fi + echo "Without arguments only /boot/flash.bin will be updated unless --offline is given." >&2 + echo "Otherwise, the arguments are the devices onto which to install uboot." >&2 + if [ "$EMMC_BOOT" = true ] && [ "$SD_BOOT" = true ]; then + echo "Two device shortcuts are provided:" >&2 + echo "" >&2 + echo " emmc -> /dev/${DEV_MMC}boot0" >&2 + echo " sd -> /dev/${DEV_SD}" >&2 + echo "" >&2 + elif [ "$SD_BOOT" = true ]; then + echo "A device shortcut is provided:" >&2 + echo "" >&2 + echo " sd -> /dev/${DEV_SD}" >&2 + echo "" >&2 + elif [ "$EMMC_BOOT" = true ]; then + echo "A device shortcut is provided:" >&2 + echo "" >&2 + echo " emmc -> /dev/${DEV_MMC}boot0" >&2 + echo "" >&2 + fi } if [ "$#" -gt 0 ] && [ "$1" = "--help" ] || [ "$#" -gt 0 ] && [ "$1" = "-h" ]; then - usage - exit 0 + usage + exit 0 fi if [ "$(id -u)" -ne 0 ]; then - echo "reform-flash-uboot has to be run as root / using sudo." - exit 1 + echo "reform-flash-uboot has to be run as root / using sudo." + exit 1 fi if [ "$#" -eq 0 ] || [ "$1" != "--offline" ]; then - echo "Downloading uboot to /boot/flash.bin and comparing checksum" >&2 - - ubooturl="https://source.mnt.re/reform/${UBOOT_PROJECT}/-/jobs/artifacts/${UBOOT_TAG}/raw/$(basename "$DTBPATH" .dtb)-flash.bin?job=build" - /usr/lib/apt/apt-helper -oAPT::Sandbox::User=root download-file "$ubooturl" "/boot/flash.bin" "SHA1:$UBOOT_SHA1" - # download mhdpfw.bin on ls1028a - case "$(cat /proc/device-tree/model)" in "MNT Reform 2 with LS1028A Module") - /usr/lib/apt/apt-helper -oAPT::Sandbox::User=root download-file \ - "https://source.mnt.re/reform/reform-ls1028a-uboot/-/raw/main/ls1028a-mhdpfw.bin" \ - "/boot/ls1028a-mhdpfw.bin" \ - "SHA1:fa96b9aa59d7c1e9e6ee1c0375d0bcc8f8e5b78c" - ;; - esac + echo "Downloading uboot to /boot/flash.bin and comparing checksum" >&2 + + ubooturl="https://source.mnt.re/reform/${UBOOT_PROJECT}/-/jobs/artifacts/${UBOOT_TAG}/raw/$(basename "$DTBPATH" .dtb)-flash.bin?job=build" + /usr/lib/apt/apt-helper -oAPT::Sandbox::User=root download-file "$ubooturl" "/boot/flash.bin" "SHA1:$UBOOT_SHA1" + # download mhdpfw.bin on ls1028a + case "$(cat /proc/device-tree/model)" in "MNT Reform 2 with LS1028A Module") + /usr/lib/apt/apt-helper -oAPT::Sandbox::User=root download-file \ + "https://source.mnt.re/reform/reform-ls1028a-uboot/-/raw/main/ls1028a-mhdpfw.bin" \ + "/boot/ls1028a-mhdpfw.bin" \ + "SHA1:fa96b9aa59d7c1e9e6ee1c0375d0bcc8f8e5b78c" + ;; + esac elif [ "$#" -gt 0 ] && [ "$1" = "--offline" ]; then - echo "Not downloading uboot but using /boot/flash.bin without updating it." >&2 - shift - if ! echo "$UBOOT_SHA1 /boot/flash.bin" | sha1sum --strict --check >/dev/null 2>&1; then - echo "Incorrect checksum for /boot/flash.bin" >&2 - echo "Either flash manually, or run without --offline to download the latest uboot version" >&2 - exit 1 - fi + echo "Not downloading uboot but using /boot/flash.bin without updating it." >&2 + shift + if ! echo "$UBOOT_SHA1 /boot/flash.bin" | sha1sum --strict --check >/dev/null 2>&1; then + echo "Incorrect checksum for /boot/flash.bin" >&2 + echo "Either flash manually, or run without --offline to download the latest uboot version" >&2 + exit 1 + fi fi if [ "$#" -eq 0 ]; then - echo "No device unto which to flash uboot provided. Exiting." >&2 - exit 0 + echo "No device unto which to flash uboot provided. Exiting." >&2 + exit 0 fi ubootsize=$(stat --format=%s "/boot/flash.bin") # check if there is enough free space at the beginning of the disk for dev in "$@"; do - case $dev in - emmc) dev=/dev/${DEV_MMC}boot0;; - sd) dev=/dev/${DEV_SD};; - esac - - if [ "$dev" = "/dev/${DEV_MMC}boot0" ]; then - continue - fi - - # no further tests for disks without a partition table - if [ "$(parted --script --machine "$dev" unit B print 2>/dev/null | grep "^$dev:" | cut -d: -f 6)" = unknown ]; then - continue - fi - - freeuntil=$(parted --script --machine "$dev" unit B print free | grep --max-count=1 '^1:1024B:.*:free;') - freeuntil=${freeuntil##1:1024B:} - freeuntil=${freeuntil%B:*:free;} - # The following checks whether the parsed output is a valid integer. - # We cannot use [0-9] because that matches on any character (or - # possibly multi-character collation element) that sorts in between 0 - # and 9. - # https://lists.gnu.org/archive/html/bug-bash/2021-02/msg00054.html - case "$freeuntil" in *[!0123456789]*|0?*|"") - echo "Unexpected parted output"; - exit 1 - esac - - if [ "$((UBOOT_OFFSET-FLASHBIN_OFFSET+ubootsize))" -ge "$freeuntil" ]; then - echo "the first partition on $dev starts at $freeuntil and would be overwritten by uboot" >&2 - echo "make sure that the first $((UBOOT_OFFSET-FLASHBIN_OFFSET+ubootsize)) bytes are free on $dev" >&2 - exit 1 - fi + case $dev in + emmc) dev=/dev/${DEV_MMC}boot0 ;; + sd) dev=/dev/${DEV_SD} ;; + esac + + if [ "$dev" = "/dev/${DEV_MMC}boot0" ]; then + continue + fi + + # no further tests for disks without a partition table + if [ "$(parted --script --machine "$dev" unit B print 2>/dev/null | grep "^$dev:" | cut -d: -f 6)" = unknown ]; then + continue + fi + + freeuntil=$(parted --script --machine "$dev" unit B print free | grep --max-count=1 '^1:1024B:.*:free;') + freeuntil=${freeuntil##1:1024B:} + freeuntil=${freeuntil%B:*:free;} + # The following checks whether the parsed output is a valid integer. + # We cannot use [0-9] because that matches on any character (or + # possibly multi-character collation element) that sorts in between 0 + # and 9. + # https://lists.gnu.org/archive/html/bug-bash/2021-02/msg00054.html + case "$freeuntil" in *[!0123456789]* | 0?* | "") + echo "Unexpected parted output" + exit 1 + ;; + esac + + if [ "$((UBOOT_OFFSET - FLASHBIN_OFFSET + ubootsize))" -ge "$freeuntil" ]; then + echo "the first partition on $dev starts at $freeuntil and would be overwritten by uboot" >&2 + echo "make sure that the first $((UBOOT_OFFSET - FLASHBIN_OFFSET + ubootsize)) bytes are free on $dev" >&2 + exit 1 + fi done # do the flashing for dev in "$@"; do - case $dev in - emmc) dev=/dev/${DEV_MMC}boot0;; - sd) dev=/dev/${DEV_SD};; - esac + case $dev in + emmc) dev=/dev/${DEV_MMC}boot0 ;; + sd) dev=/dev/${DEV_SD} ;; + esac - echo "Writing /boot/flash.bin to $dev" >&2 + echo "Writing /boot/flash.bin to $dev" >&2 - if [ "$dev" = "/dev/${DEV_MMC}boot0" ]; then - echo 0 > "/sys/class/block/${DEV_MMC}boot0/force_ro" - dd if=/boot/flash.bin of="/dev/${DEV_MMC}boot0" bs=512 seek="$((UBOOT_OFFSET/512))" skip="$((FLASHBIN_OFFSET/512))" - echo 1 > "/sys/class/block/${DEV_MMC}boot0/force_ro" - continue - fi + if [ "$dev" = "/dev/${DEV_MMC}boot0" ]; then + echo 0 >"/sys/class/block/${DEV_MMC}boot0/force_ro" + dd if=/boot/flash.bin of="/dev/${DEV_MMC}boot0" bs=512 seek="$((UBOOT_OFFSET / 512))" skip="$((FLASHBIN_OFFSET / 512))" + echo 1 >"/sys/class/block/${DEV_MMC}boot0/force_ro" + continue + fi - dd if=/boot/flash.bin of="$dev" bs=512 seek="$((UBOOT_OFFSET/512))" skip="$((FLASHBIN_OFFSET/512))" + dd if=/boot/flash.bin of="$dev" bs=512 seek="$((UBOOT_OFFSET / 512))" skip="$((FLASHBIN_OFFSET / 512))" done # inform about the DIP switch position only on imx8mq -case "$(cat /proc/device-tree/model)" in "MNT Reform 2"|"MNT Reform 2 HDMI") - DOMMC=0 - DOSD=0 - for dev in "$@"; do - case $dev in - emmc) dev=/dev/${DEV_MMC}boot0;; - sd) dev=/dev/${DEV_SD};; - esac - case $dev in - "/dev/${DEV_MMC}"*) DOMMC=1;; - "/dev/${DEV_SD}"*) DOSD=1;; - esac - done - if [ "$DOMMC" != "0" ]; then - echo "For the i.MX8MQ to load u-boot from MMC, make sure" >&2 - echo "that your DIP switch is set to OFF." >&2 - fi - if [ "$DOSD" != "0" ]; then - echo "For the i.MX8MQ to load u-boot from SD-Card, make sure" >&2 - echo "that your DIP switch is set to ON." >&2 - fi +case "$(cat /proc/device-tree/model)" in "MNT Reform 2" | "MNT Reform 2 HDMI") + DOMMC=0 + DOSD=0 + for dev in "$@"; do + case $dev in + emmc) dev=/dev/${DEV_MMC}boot0 ;; + sd) dev=/dev/${DEV_SD} ;; + esac + case $dev in + "/dev/${DEV_MMC}"*) DOMMC=1 ;; + "/dev/${DEV_SD}"*) DOSD=1 ;; + esac + done + if [ "$DOMMC" != "0" ]; then + echo "For the i.MX8MQ to load u-boot from MMC, make sure" >&2 + echo "that your DIP switch is set to OFF." >&2 + fi + if [ "$DOSD" != "0" ]; then + echo "For the i.MX8MQ to load u-boot from SD-Card, make sure" >&2 + echo "that your DIP switch is set to ON." >&2 + fi + ;; esac diff --git a/sbin/reform-hw-setup b/sbin/reform-hw-setup index d85f0001c23c2d20441139df9b090aafd1410418..6074852eda985192dc4d44466abc1cc600bfffd9 100755 --- a/sbin/reform-hw-setup +++ b/sbin/reform-hw-setup @@ -2,125 +2,125 @@ set -eu -usage () { - echo "Hardware setup specific to your MNT Reform platform." >&2 - echo "Usually run by /lib/systemd/system/reform-hw-setup.service" >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Hardware setup specific to your MNT Reform platform." >&2 + echo "Usually run by /lib/systemd/system/reform-hw-setup.service" >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ]; then - if [ "$1" != "--help" ]; then - echo "E: too many arguments" >&2 - usage - exit 1 - fi - usage - exit 0 + if [ "$1" != "--help" ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + usage + exit 0 fi init_a311d() { - # A311D sound controls - # without setting these, there is no UCM profile and messages like this are produced: - # no backend DAIs enabled for fe.dai-link-0, possibly missing ALSA mixer-based routing or UCM profile - amixer -c 0 sset 'FRDDR_A SINK 1 SEL' 'OUT 1' - amixer -c 0 sset 'FRDDR_A SRC 1 EN' 'on' - amixer -c 0 sset 'TDMOUT_B SRC SEL' 'IN 0' - amixer -c 0 sset 'TDMIN_B SRC SEL' 'IN 1' - amixer -c 0 sset 'TODDR_A SRC SEL' 'IN 1' - - # Workaround for ethernet PHY reset problem - for m in dwmac_meson8b dwmac_generic stmmac_platform stmmac mdio_mux_meson_g12a mdio_mux pcs_xpcs mdio_devres of_mdio; do - grep --quiet "^$m " /proc/modules || continue; - rmmod "$m" - done - sleep 0.5 - modprobe mdio_mux_meson_g12a - modprobe dwmac_meson8b - - # Workaround for SDIO wifi not loading - echo ffe03000.mmc > /sys/class/mmc_host/mmc2/device/driver/unbind - echo ffe03000.mmc > /sys/bus/platform/drivers/meson-gx-mmc/bind + # A311D sound controls + # without setting these, there is no UCM profile and messages like this are produced: + # no backend DAIs enabled for fe.dai-link-0, possibly missing ALSA mixer-based routing or UCM profile + amixer -c 0 sset 'FRDDR_A SINK 1 SEL' 'OUT 1' + amixer -c 0 sset 'FRDDR_A SRC 1 EN' 'on' + amixer -c 0 sset 'TDMOUT_B SRC SEL' 'IN 0' + amixer -c 0 sset 'TDMIN_B SRC SEL' 'IN 1' + amixer -c 0 sset 'TODDR_A SRC SEL' 'IN 1' + + # Workaround for ethernet PHY reset problem + for m in dwmac_meson8b dwmac_generic stmmac_platform stmmac mdio_mux_meson_g12a mdio_mux pcs_xpcs mdio_devres of_mdio; do + grep --quiet "^$m " /proc/modules || continue + rmmod "$m" + done + sleep 0.5 + modprobe mdio_mux_meson_g12a + modprobe dwmac_meson8b + + # Workaround for SDIO wifi not loading + echo ffe03000.mmc >/sys/class/mmc_host/mmc2/device/driver/unbind + echo ffe03000.mmc >/sys/bus/platform/drivers/meson-gx-mmc/bind } init_wm8960() { - # Fix WM8960 being too quiet - amixer -c 0 sset Playback 255 - amixer -c 0 sset 'Left Output Mixer PCM' on - amixer -c 0 sset 'Right Output Mixer PCM' on - # This switch in WM8960 needs to be on for the headset mic input to work - amixer -c 0 sset 'Left Input Mixer Boost' on + # Fix WM8960 being too quiet + amixer -c 0 sset Playback 255 + amixer -c 0 sset 'Left Output Mixer PCM' on + amixer -c 0 sset 'Right Output Mixer PCM' on + # This switch in WM8960 needs to be on for the headset mic input to work + amixer -c 0 sset 'Left Input Mixer Boost' on } init_tlv320aic3100() { - # Set up speaker on MNT Pocket Reform - amixer -c 0 sset 'Speaker Driver' on - amixer -c 0 sset 'Output Left From Left DAC' on - amixer -c 0 sset 'Output Right From Right DAC' on - amixer -c 0 sset 'Speaker Analog' 127 - amixer -c 0 sset 'DAC' 127 - amixer -c 0 sset 'HP Analog' 127 - amixer -c 0 sset 'HP Driver' on - amixer -c 0 sset 'HP Left' on - amixer -c 0 sset 'HP Right' on + # Set up speaker on MNT Pocket Reform + amixer -c 0 sset 'Speaker Driver' on + amixer -c 0 sset 'Output Left From Left DAC' on + amixer -c 0 sset 'Output Right From Right DAC' on + amixer -c 0 sset 'Speaker Analog' 127 + amixer -c 0 sset 'DAC' 127 + amixer -c 0 sset 'HP Analog' 127 + amixer -c 0 sset 'HP Driver' on + amixer -c 0 sset 'HP Left' on + amixer -c 0 sset 'HP Right' on } init_pocket_display() { - # Increase console font size (MNT Pocket Reform has a Hi-DPI display) - for c in 1 2 3 4 5 6 7 - do setfont -C /dev/tty$c /usr/share/consolefonts/Uni2-TerminusBold32x16.psf.gz - done + # Increase console font size (MNT Pocket Reform has a Hi-DPI display) + for c in 1 2 3 4 5 6 7; do + setfont -C /dev/tty$c /usr/share/consolefonts/Uni2-TerminusBold32x16.psf.gz + done } init_qca9377_wifi() { - if test -e /proc/modules && grep --quiet '^qcacld2 ' /proc/modules; then - echo "I: Module qcacld2 is already loaded" >&2 - return 0 + if test -e /proc/modules && grep --quiet '^qcacld2 ' /proc/modules; then + echo "I: Module qcacld2 is already loaded" >&2 + return 0 + fi + + # load out-of-tree Wi-Fi driver + KERNVER_EXACT=$(dpkg-query --show --showformat '${Version}' "linux-image-$(uname -r)") + modprobe cfg80211 + + # without "-f", insmod will fail with "Invalid module format" even though + # the kernel version matches + echo "I: Try to load exact match wifi driver: ${KERNVER_EXACT}" >&2 + if [ -f "/opt/reform-qcacld2/qcacld2-${KERNVER_EXACT}.ko" ]; then + echo "I: Found exact match for kernel ${KERNVER_EXACT}" >&2 + if insmod -f "/opt/reform-qcacld2/qcacld2-${KERNVER_EXACT}.ko"; then + echo "I: Successfully loaded exact match driver" >&2 + return 0 + else + echo "W: Failed to load exact match driver. Try other available driver" >&2 fi - - # load out-of-tree Wi-Fi driver - KERNVER_EXACT=$(dpkg-query --show --showformat '${Version}' "linux-image-$(uname -r)") - modprobe cfg80211 - - # without "-f", insmod will fail with "Invalid module format" even though - # the kernel version matches - echo "I: Try to load exact match wifi driver: ${KERNVER_EXACT}" >&2 - if [ -f "/opt/reform-qcacld2/qcacld2-${KERNVER_EXACT}.ko" ]; then - echo "I: Found exact match for kernel ${KERNVER_EXACT}" >&2 - if insmod -f "/opt/reform-qcacld2/qcacld2-${KERNVER_EXACT}.ko"; then - echo "I: Successfully loaded exact match driver" >&2 - return 0 - else - echo "W: Failed to load exact match driver. Try other available driver" >&2 - fi + fi + + # Find other potential qcacld2 drivers + potential_drivers=$(find /opt/reform-qcacld2/qcacld2-*.ko -maxdepth 1 -type f -print0 | sort -Vzr) + + # Try to load available drivers, starting with the highest version number, until one works + for driver in $potential_drivers; do + echo "I: Attempting to load wifi driver: $driver" >&2 + if insmod -f "$driver"; then + echo "I: Successfully loaded driver: $driver" >&2 + return 0 + else + echo "W: Failed to load driver: $driver, trying next" >&2 fi + done - # Find other potential qcacld2 drivers - potential_drivers=$(find /opt/reform-qcacld2/qcacld2-*.ko -maxdepth 1 -type f -print0 | sort -Vzr) - - # Try to load available drivers, starting with the highest version number, until one works - for driver in $potential_drivers; do - echo "I: Attempting to load wifi driver: $driver" >&2 - if insmod -f "$driver"; then - echo "I: Successfully loaded driver: $driver" >&2 - return 0 - else - echo "W: Failed to load driver: $driver, trying next" >&2 - fi - done - - echo "E: Failed to load any compatible qcacld2 driver" >&2 - return 1 + echo "E: Failed to load any compatible qcacld2 driver" >&2 + return 1 } case "$(cat /proc/device-tree/model)" in -"MNT Reform 2"|"MNT Reform 2 HDMI") + "MNT Reform 2" | "MNT Reform 2 HDMI") # Workaround for WM8960 sometimes not coming out of reset if [ ! -e /sys/bus/i2c/drivers/wm8960/2-001a ]; then - echo 2-001a > /sys/bus/i2c/drivers/wm8960/bind + echo 2-001a >/sys/bus/i2c/drivers/wm8960/bind fi test -e /sys/bus/i2c/drivers/wm8960/2-001a @@ -133,22 +133,22 @@ case "$(cat /proc/device-tree/model)" in # /sys/devices/platform/soc@0/30800000.bus/308?0000.serial/308?0000.serial:0/308?0000.serial:0.0/tty/ttymxc?/power/wakeup # use `find` to acquire either path find /sys/devices/platform/soc@0/30800000.bus/308?0000.serial/ -wholename '*/tty/ttymxc?/power/wakeup' \ - | while read -r f; do - [ -e "$f" ] || continue - echo enabled > "$f" - done + | while read -r f; do + [ -e "$f" ] || continue + echo enabled >"$f" + done ;; -"MNT Reform 2 with BPI-CM4 Module") + "MNT Reform 2 with BPI-CM4 Module") # Workaround for WM8960 sometimes not coming out of reset if [ ! -e /sys/bus/i2c/drivers/wm8960/1-001a ]; then - echo 1-001a > /sys/bus/i2c/drivers/wm8960/bind + echo 1-001a >/sys/bus/i2c/drivers/wm8960/bind fi test -e /sys/bus/i2c/drivers/wm8960/1-001a init_a311d init_wm8960 ;; -"MNT Reform 2 with LS1028A Module") + "MNT Reform 2 with LS1028A Module") # Workaround for a DWC3 USB Controller regression # Assert USB hub reset @@ -160,7 +160,7 @@ case "$(cat /proc/device-tree/model)" in gpioset 2 13=1 # Select "ondemand" CPU frequency scaling governor - echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo ondemand >/sys/devices/system/cpu/cpufreq/policy0/scaling_governor # the functionality of the dwc3 module depends on the loglevel # loglevel=3 makes usb not work @@ -168,29 +168,29 @@ case "$(cat /proc/device-tree/model)" in # https://community.mnt.re/t/no-keyboard-input-with-ls1028-board-and-latest-image/1994/13 dmesg -n 7 ;; -"MNT Pocket Reform with i.MX8MP Module") + "MNT Pocket Reform with i.MX8MP Module") init_pocket_display init_qca9377_wifi || echo "W: init_qca9377_wifi failed" >&2 init_tlv320aic3100 ;; -"MNT Pocket Reform with BPI-CM4 Module") + "MNT Pocket Reform with BPI-CM4 Module") init_pocket_display init_a311d init_tlv320aic3100 ;; -"MNT Reform 2 with i.MX8MP Module") + "MNT Reform 2 with i.MX8MP Module") init_wm8960 init_qca9377_wifi || echo "W: init_qca9377_wifi failed" >&2 ;; -"MNT Reform 2 with RCORE RK3588 Module") + "MNT Reform 2 with RCORE RK3588 Module") init_wm8960 ;; -"MNT Pocket Reform with RCORE RK3588 Module") + "MNT Pocket Reform with RCORE RK3588 Module") init_pocket_display ;; -"MNT Reform Next with RCORE RK3588 Module") - ;; -*) + "MNT Reform Next with RCORE RK3588 Module") ;; + *) echo "E: Your platform $(cat /proc/device-tree/model) is not supported by reform-tools" >&2 exit 1 + ;; esac diff --git a/sbin/reform-migrate b/sbin/reform-migrate index 1bd952f2d3c5e414b602f25bafcd0cba54a03ba7..636193d45b1c59432d853627cb48b976ccf4625b 100755 --- a/sbin/reform-migrate +++ b/sbin/reform-migrate @@ -4,79 +4,80 @@ set -eu # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi usage_minimal() { - echo "Copies the currently running system onto TARGET and run reform-boot-config" >&2 - echo "to set up /boot on SD-card or eMMC (selected by the --emmc option) to boot" >&2 - echo "into the newly copied system. TARGET is a partition block device and will" >&2 - echo "temporarily get mounted by this script." >&2 - echo >&2 - echo "Usage: $0 [--help] [--help-full] [--emmc] DEVICE" >&2 - echo >&2 - echo "Options:" >&2 - echo " DEVICE Rootfs partition in /dev.">&2 - echo " --help Display this help and exit." >&2 - echo " --help-full Extended device-specific help output." >&2 - echo " --emmc Choose /boot partition on eMMC instead of SD-card." >&2 + echo "Copies the currently running system onto TARGET and run reform-boot-config" >&2 + echo "to set up /boot on SD-card or eMMC (selected by the --emmc option) to boot" >&2 + echo "into the newly copied system. TARGET is a partition block device and will" >&2 + echo "temporarily get mounted by this script." >&2 + echo >&2 + echo "Usage: $0 [--help] [--help-full] [--emmc] DEVICE" >&2 + echo >&2 + echo "Options:" >&2 + echo " DEVICE Rootfs partition in /dev." >&2 + echo " --help Display this help and exit." >&2 + echo " --help-full Extended device-specific help output." >&2 + echo " --emmc Choose /boot partition on eMMC instead of SD-card." >&2 } usage() { - echo "Usage:" - if [ "$EMMC_USE" = true ]; then - echo " reform-migrate [--emmc] TARGET" - else - echo " reform-migrate TARGET" - fi - echo "" - echo "Mounts TARGET and copies the currently running system to it using rsync. This will" - echo "overwrite all existing files in TARGET. At the end, reform-boot-config is run and" - if [ "$EMMC_USE" = true ]; then - echo "will set up the first partition of the SD-card or eMMC (depending on the --emmc" - echo "option) to load your newly copied rootfs and adjust /etc/fstab of TARGET accordingly." - echo "" - echo "Options:" - echo "" - echo " --emmc Record boot preference on eMMC instead of SD card." - case "$(cat /proc/device-tree/model)" in "MNT Reform 2"|"MNT Reform 2 HDMI") - echo " This is only useful with SoM dip switch turned off." ;; - esac - else - echo "will set up the first partition of the SD-card to load your newly copied rootfs" - echo "and adjust /etc/fstab of TARGET accordingly." - fi - echo "" - echo "Examples:" - echo "" - if [ "$EMMC_USE" = true ]; then - echo " reform-migrate --emmc /dev/nvme0n1p1" - echo " Mounts the first partition of an NVMe disk and mirrors your system to it." - echo " Configures booting from the first partition on eMMC." - fi - echo " reform-migrate /dev/mapper/crypt" - echo " Mounts encrypted disk 'crypt' and mirrors your system to it." - echo " The disk has to be unlocked first with: cryptsetup luksOpen /dev/nvme0n1p1 crypt" - echo " Configures booting from the first partition on the SD-card as --emmc option is missing." + echo "Usage:" + if [ "$EMMC_USE" = true ]; then + echo " reform-migrate [--emmc] TARGET" + else + echo " reform-migrate TARGET" + fi + echo "" + echo "Mounts TARGET and copies the currently running system to it using rsync. This will" + echo "overwrite all existing files in TARGET. At the end, reform-boot-config is run and" + if [ "$EMMC_USE" = true ]; then + echo "will set up the first partition of the SD-card or eMMC (depending on the --emmc" + echo "option) to load your newly copied rootfs and adjust /etc/fstab of TARGET accordingly." + echo "" + echo "Options:" + echo "" + echo " --emmc Record boot preference on eMMC instead of SD card." + case "$(cat /proc/device-tree/model)" in "MNT Reform 2" | "MNT Reform 2 HDMI") + echo " This is only useful with SoM dip switch turned off." + ;; + esac + else + echo "will set up the first partition of the SD-card to load your newly copied rootfs" + echo "and adjust /etc/fstab of TARGET accordingly." + fi + echo "" + echo "Examples:" + echo "" + if [ "$EMMC_USE" = true ]; then + echo " reform-migrate --emmc /dev/nvme0n1p1" + echo " Mounts the first partition of an NVMe disk and mirrors your system to it." + echo " Configures booting from the first partition on eMMC." + fi + echo " reform-migrate /dev/mapper/crypt" + echo " Mounts encrypted disk 'crypt' and mirrors your system to it." + echo " The disk has to be unlocked first with: cryptsetup luksOpen /dev/nvme0n1p1 crypt" + echo " Configures booting from the first partition on the SD-card as --emmc option is missing." } if [ $# -ne 1 ] && [ $# -ne 2 ]; then - usage - exit 1 + usage + exit 1 fi if [ "$1" = "--help" ]; then - # minimal device-agnostic help output for use with help2man - usage_minimal - exit 0 + # minimal device-agnostic help output for use with help2man + usage_minimal + exit 0 elif [ "$1" = "--help-full" ]; then - usage - exit 0 + usage + exit 0 fi EMMC="" @@ -84,41 +85,40 @@ TARGET="$1" BOOTPART="${DEV_SD}p1" if [ "--emmc" = "$1" ]; then - if [ "$EMMC_USE" = false ]; then - echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 - exit 1 - fi - EMMC="--emmc" - TARGET="$2" - BOOTPART="${DEV_MMC}p1" + if [ "$EMMC_USE" = false ]; then + echo "E: writing to eMMC not supported on $(cat /proc/device-tree/model)" >&2 + exit 1 + fi + EMMC="--emmc" + TARGET="$2" + BOOTPART="${DEV_MMC}p1" fi if [ -z "$TARGET" ]; then - usage - exit 1 + usage + exit 1 fi -if [ ! -e "$TARGET" ] -then - echo "Error: The partition $TARGET does not exist." - exit +if [ ! -e "$TARGET" ]; then + echo "Error: The partition $TARGET does not exist." + exit fi if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "$TARGET")" ]; then - echo "$TARGET is still in use" >&2 - exit 1 + echo "$TARGET is still in use" >&2 + exit 1 fi # check if the new boot is still mounted somewhere if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$BOOTPART")" ]; then - echo "/dev/$BOOTPART is still mounted somewhere." >&2 - echo "Please unmount before running this script" >&2 - exit 1 + echo "/dev/$BOOTPART is still mounted somewhere." >&2 + echo "Please unmount before running this script" >&2 + exit 1 fi if [ "$(id -u)" -ne 0 ]; then - echo "reform-boot-config has to be run as root / using sudo." >&2 - exit 1 + echo "reform-boot-config has to be run as root / using sudo." >&2 + exit 1 fi echo "" @@ -130,8 +130,8 @@ echo "Before using this script, your target partition has to be formatted. You c echo "gnome-disks can also help you set up an encrypted disk. You can also run the following commands for one single" echo "partition on NVMe:" echo "" -echo " parted /dev/nvme0n1 \"mklabel msdos\"" -echo " parted /dev/nvme0n1 \"mkpart primary ext4 4MiB -1\"" +echo ' parted /dev/nvme0n1 "mklabel msdos"' +echo ' parted /dev/nvme0n1 "mkpart primary ext4 4MiB -1"' echo " mkfs.ext4 /dev/nvme0n1p1" echo "" echo "You can also setup an encrypted NVMe SSD by running reform-setup-encrypted-nvme" @@ -139,7 +139,10 @@ echo "" # FIXME: mkimage.sh in reform-system-image could write out the exact values into a known location echo "Running rsync to copy approximately 3G of data in about 210k files..." >&2 -command -v "rsync" >/dev/null 2>&1 || { echo >&2 "Please install \"rsync\" using: apt install rsync"; exit 1; } +command -v "rsync" >/dev/null 2>&1 || { + echo >&2 'Please install "rsync" using: apt install rsync' + exit 1 +} echo "Trying to mount $TARGET... (if this fails, format the disk/partition as explained above)" @@ -156,10 +159,10 @@ printf "Are you sure you want to proceed? [y/N] " read -r response if [ "$response" != "y" ]; then - echo "Exiting." - umount "$MOUNTPOINT" - trap - EXIT INT TERM - exit + echo "Exiting." + umount "$MOUNTPOINT" + trap - EXIT INT TERM + exit fi echo "Starting the copy. This can take a while." diff --git a/sbin/reform-setup-encrypted-nvme b/sbin/reform-setup-encrypted-nvme index 8f0778c8d206d25b5af338346acc3fe6a19619de..60f1a43b1e3efe28ca0e40a98f5cf0b755742200 100755 --- a/sbin/reform-setup-encrypted-nvme +++ b/sbin/reform-setup-encrypted-nvme @@ -2,51 +2,60 @@ set -eu -usage () { - echo "Set up the SSD with LUKS encryption containing LVM2 volumes for" >&2 - echo "swap and the rootfs. Offers to run reform-migrate and " >&2 - echo "reform-boot-config to set up the initramfs in /boot to load the" >&2 - echo "rootfs from the encrypted SSD." >&2 - echo >&2 - echo "Usage: $0 [--help]" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "Set up the SSD with LUKS encryption containing LVM2 volumes for" >&2 + echo "swap and the rootfs. Offers to run reform-migrate and " >&2 + echo "reform-boot-config to set up the initramfs in /boot to load the" >&2 + echo "rootfs from the encrypted SSD." >&2 + echo >&2 + echo "Usage: $0 [--help]" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ]; then - if [ "$1" != "--help" ]; then - echo "E: too many arguments" >&2 - usage - exit 1 - fi - usage - exit 0 + if [ "$1" != "--help" ]; then + echo "E: too many arguments" >&2 + usage + exit 1 + fi + usage + exit 0 fi if [ "$(id -u)" -ne 0 ]; then - echo "reform-setup-encrypted-nvme has to be run as root / using sudo." - exit + echo "reform-setup-encrypted-nvme has to be run as root / using sudo." + exit fi -command -v "cryptsetup" >/dev/null 2>&1 || { echo >&2 "Please install \"cryptsetup\" using: apt install cryptsetup"; exit 1; } -command -v "lvchange" >/dev/null 2>&1 || { echo >&2 "Please install \"lvm2\" using: apt install lvm2"; exit 1; } -command -v "mkfs.ext4" >/dev/null 2>&1 || { echo >&2 "Please install \"e2fsprogs\" using: apt install e2fsprogs"; exit 1; } +command -v "cryptsetup" >/dev/null 2>&1 || { + echo >&2 'Please install "cryptsetup" using: apt install cryptsetup' + exit 1 +} +command -v "lvchange" >/dev/null 2>&1 || { + echo >&2 'Please install "lvm2" using: apt install lvm2' + exit 1 +} +command -v "mkfs.ext4" >/dev/null 2>&1 || { + echo >&2 'Please install "e2fsprogs" using: apt install e2fsprogs' + exit 1 +} # shellcheck source=/dev/null if [ -e "./machines/$(cat /proc/device-tree/model).conf" ]; then - . "./machines/$(cat /proc/device-tree/model).conf" + . "./machines/$(cat /proc/device-tree/model).conf" elif [ -e "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" ]; then - . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" + . "/usr/share/reform-tools/machines/$(cat /proc/device-tree/model).conf" else - echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 - exit 1 + echo "E: unable to find config for $(cat /proc/device-tree/model)" >&2 + exit 1 fi if [ "$DEV_SSD" = "sda" ]; then - HUMAN="SATA" + HUMAN="SATA" else - HUMAN="NVMe" + HUMAN="NVMe" fi echo "This will ERASE ALL DATA from your $HUMAN SSD." @@ -57,8 +66,8 @@ printf "Are you sure you want to proceed? [y/N] " read -r response if [ "$response" != "y" ]; then - echo "Exiting." - exit + echo "Exiting." + exit fi cleanupvg() { vgchange -an reformvg; } @@ -68,39 +77,41 @@ error() { echo "$0 FAILED to run" >&2; } trap error EXIT INT TERM if [ -n "$(lsblk --noheadings --output=MOUNTPOINT "/dev/$DEV_SSD")" ]; then - echo "/dev/$DEV_SSD is still in use" >&2 - exit 1 + echo "/dev/$DEV_SSD is still in use" >&2 + exit 1 fi # /proc/meminfo contains the sizes in kibibytes mem="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)" -case "$mem" in *[!0123456789]*|0?*|"") - echo "E: unable to acquire total memory from /proc/meminfo" >&2 - exit 1 +case "$mem" in *[!0123456789]* | 0?* | "") + echo "E: unable to acquire total memory from /proc/meminfo" >&2 + exit 1 + ;; esac # convert memory size to gigabytes, rounding up mem="$(awk 'BEGIN {printf("%.f",'"$mem"'/1024/1024+0.5)}')" # minimum swap size is 4G if [ "$mem" -lt 4 ]; then - mem=4 + mem=4 fi disksize=$(lsblk -bno SIZE "/dev/$DEV_SSD" | head -1) -case "$disksize" in *[!0123456789]*|0?*|"") - echo "E: unable to acquire disk size of /dev/$DEV_SSD" >&2 - exit 1 +case "$disksize" in *[!0123456789]* | 0?* | "") + echo "E: unable to acquire disk size of /dev/$DEV_SSD" >&2 + exit 1 + ;; esac # convert disk size to gigabytes, rounding down -disksize="$((disksize/1024/1024/1024))" +disksize="$((disksize / 1024 / 1024 / 1024))" # maximum swap size is 5% of disk size -if [ "$mem" -gt "$((disksize*5/100))" ]; then - mem="$((disksize*5/100))" +if [ "$mem" -gt "$((disksize * 5 / 100))" ]; then + mem="$((disksize * 5 / 100))" fi if [ "$mem" -le 1 ]; then - echo "E: your disk is too small for swap" >&2 - exit 1 + echo "E: your disk is too small for swap" >&2 + exit 1 fi cryptsetup luksFormat "/dev/$DEV_SSD" @@ -121,49 +132,49 @@ printf "The encrypted %s is now set up. Do you want me to run reform-migrate now read -r response if [ "$response" != "y" ]; then - echo "If you want to migrate this system to $HUMAN SSD you can now run:" - echo "" - echo "echo RESUME=UUID=$SWAPUUID > /etc/initramfs-tools/conf.d/resume" - echo "echo reform_crypt UUID=$CRYPTUUID none luks,discard > /etc/crypttab" - echo "echo UUID=$SWAPUUID none swap sw 0 0 >> /etc/fstab" - echo "cryptsetup luksOpen /dev/$DEV_SSD reform_crypt" - echo "vgchange -ay reformvg" - echo "reform-migrate /dev/reformvg/root" - echo "vgchange -an reformvg" - echo "cryptsetup luksClose reform_crypt" + echo "If you want to migrate this system to $HUMAN SSD you can now run:" + echo "" + echo "echo RESUME=UUID=$SWAPUUID > /etc/initramfs-tools/conf.d/resume" + echo "echo reform_crypt UUID=$CRYPTUUID none luks,discard > /etc/crypttab" + echo "echo UUID=$SWAPUUID none swap sw 0 0 >> /etc/fstab" + echo "cryptsetup luksOpen /dev/$DEV_SSD reform_crypt" + echo "vgchange -ay reformvg" + echo "reform-migrate /dev/reformvg/root" + echo "vgchange -an reformvg" + echo "cryptsetup luksClose reform_crypt" else - # we are not really running reform-migrate but imitate what it does - # instead because we want to write out some files after the rsync but - # before running reform-boot-config - ROOTMNT="$(mktemp --tmpdir --directory reform-setup-encrypted-nvme.XXXXXXXXXX)" - trap 'umount $ROOTMNT; cleanupvg; cleanupluks; error' EXIT INT TERM - mount /dev/reformvg/root "$ROOTMNT" - rsync -axHAWXS --numeric-ids --info=progress2 / "$ROOTMNT" - echo "RESUME=UUID=$SWAPUUID" > "$ROOTMNT/etc/initramfs-tools/conf.d/resume" - echo "reform_crypt UUID=$CRYPTUUID none luks,discard" > "$ROOTMNT/etc/crypttab" - echo "UUID=$SWAPUUID none swap sw 0 0" >> "$ROOTMNT/etc/fstab" - trap "cleanupvg; cleanupluks; error" EXIT INT TERM - umount "$ROOTMNT" - - emmc_flag= - if [ "$EMMC_USE" = true ]; then - printf "Your /boot partition will be on eMMC by default. Do you want it on the SD-Card instead? [y/N] " - read -r response - if [ "$response" != "y" ]; then - emmc_flag="--emmc" - fi - fi - ret=0 - reform-boot-config $emmc_flag /dev/reformvg/root || ret=$? - if [ "$ret" -ne 0 ]; then - echo "reform-boot-config failed. To re-run it manually, perform the following steps:" >&2 - echo " $ cryptsetup luksOpen \"/dev/$DEV_SSD\" reform_crypt" >&2 - echo " $ vgchange -ay reformvg" >&2 - echo " $ reform-boot-config $emmc_flag /dev/reformvg/root >&2" - echo " $ vgchange -an reformvg" >&2 - echo " $ cryptsetup luksClose reform_crypt" >&2 - exit "$ret" - fi + # we are not really running reform-migrate but imitate what it does + # instead because we want to write out some files after the rsync but + # before running reform-boot-config + ROOTMNT="$(mktemp --tmpdir --directory reform-setup-encrypted-nvme.XXXXXXXXXX)" + trap 'umount $ROOTMNT; cleanupvg; cleanupluks; error' EXIT INT TERM + mount /dev/reformvg/root "$ROOTMNT" + rsync -axHAWXS --numeric-ids --info=progress2 / "$ROOTMNT" + echo "RESUME=UUID=$SWAPUUID" >"$ROOTMNT/etc/initramfs-tools/conf.d/resume" + echo "reform_crypt UUID=$CRYPTUUID none luks,discard" >"$ROOTMNT/etc/crypttab" + echo "UUID=$SWAPUUID none swap sw 0 0" >>"$ROOTMNT/etc/fstab" + trap "cleanupvg; cleanupluks; error" EXIT INT TERM + umount "$ROOTMNT" + + emmc_flag= + if [ "$EMMC_USE" = true ]; then + printf "Your /boot partition will be on eMMC by default. Do you want it on the SD-Card instead? [y/N] " + read -r response + if [ "$response" != "y" ]; then + emmc_flag="--emmc" + fi + fi + ret=0 + reform-boot-config $emmc_flag /dev/reformvg/root || ret=$? + if [ "$ret" -ne 0 ]; then + echo "reform-boot-config failed. To re-run it manually, perform the following steps:" >&2 + echo " $ cryptsetup luksOpen \"/dev/$DEV_SSD\" reform_crypt" >&2 + echo " $ vgchange -ay reformvg" >&2 + echo " $ reform-boot-config $emmc_flag /dev/reformvg/root >&2" + echo " $ vgchange -an reformvg" >&2 + echo " $ cryptsetup luksClose reform_crypt" >&2 + exit "$ret" + fi fi trap "cleanupluks; error" EXIT INT TERM diff --git a/sbin/reform-standby b/sbin/reform-standby index 24167d244b08f8709fe18ea1f03a65c49477f271..297a363624947d69f4ab9b7eb21a42b4ff1e2d90 100755 --- a/sbin/reform-standby +++ b/sbin/reform-standby @@ -9,46 +9,49 @@ set -eu -usage () { - echo "i.MX8MQ specific setup before suspend and after wakeup." >&2 - echo "This script is called by the reform-sleep.service systemd service." >&2 - echo "Do not call this script manually from the terminal but use" >&2 - echo "systemctl suspend instead." >&2 - echo >&2 - echo "Usage: $0 [--help] suspend|resume" >&2 - echo >&2 - echo "Options:" >&2 - echo " --help Display this help and exit." >&2 +usage() { + echo "i.MX8MQ specific setup before suspend and after wakeup." >&2 + echo "This script is called by the reform-sleep.service systemd service." >&2 + echo "Do not call this script manually from the terminal but use" >&2 + echo "systemctl suspend instead." >&2 + echo >&2 + echo "Usage: $0 [--help] suspend|resume" >&2 + echo >&2 + echo "Options:" >&2 + echo " --help Display this help and exit." >&2 } if [ "$#" -gt 0 ] && [ "$1" = "--help" ]; then - usage - exit 0 + usage + exit 0 fi if [ "$(id -u)" -ne 0 ]; then - echo "reform-standby has to be run as root / using sudo." - exit + echo "reform-standby has to be run as root / using sudo." + exit fi case "$(cat /proc/device-tree/model)" in - "MNT Reform 2"|"MNT Reform 2 HDMI") : ;; - *) echo "Sorry, reform-standby is only supported on MNT Reform 2 with i.MX8MQ processor module."; exit;; + "MNT Reform 2" | "MNT Reform 2 HDMI") : ;; + *) + echo "Sorry, reform-standby is only supported on MNT Reform 2 with i.MX8MQ processor module." + exit + ;; esac setup_wake() { # configure UARTs as wakeup sources - echo enabled > /sys/devices/platform/soc@0/30800000.bus/30860000.serial/tty/ttymxc0/power/wakeup - echo enabled > /sys/devices/platform/soc@0/30800000.bus/30890000.serial/tty/ttymxc1/power/wakeup - echo enabled > /sys/devices/platform/soc@0/30800000.bus/30880000.serial/tty/ttymxc2/power/wakeup + echo enabled >/sys/devices/platform/soc@0/30800000.bus/30860000.serial/tty/ttymxc0/power/wakeup + echo enabled >/sys/devices/platform/soc@0/30800000.bus/30890000.serial/tty/ttymxc1/power/wakeup + echo enabled >/sys/devices/platform/soc@0/30800000.bus/30880000.serial/tty/ttymxc2/power/wakeup } wifi_off() { - echo 1 > /sys/class/pci_bus/0000:01/device/remove + echo 1 >/sys/class/pci_bus/0000:01/device/remove } wifi_on() { - echo 1 > /sys/class/pci_bus/0000:00/rescan + echo 1 >/sys/class/pci_bus/0000:00/rescan sleep 1 } @@ -62,42 +65,43 @@ hantro_on() { } kbd_backlight_off() { - for d in /dev/hidraw* - do printf "xLITE0" > "$d" + for d in /dev/hidraw*; do + printf "xLITE0" >"$d" done } kbd_backlight_on() { - for d in /dev/hidraw* - do printf "xLITE6" > "$d" + for d in /dev/hidraw*; do + printf "xLITE6" >"$d" done } hid_bind() { - echo 0003:03EB:2041.0002 > /sys/bus/hid/drivers/hid-generic/bind || : - echo 0003:03EB:2042.0001 > /sys/bus/hid/drivers/hid-generic/bind || : + echo 0003:03EB:2041.0002 >/sys/bus/hid/drivers/hid-generic/bind || : + echo 0003:03EB:2042.0001 >/sys/bus/hid/drivers/hid-generic/bind || : } hid_unbind() { - echo 0003:03EB:2041.0002 > /sys/bus/hid/drivers/hid-generic/unbind || : - echo 0003:03EB:2042.0001 > /sys/bus/hid/drivers/hid-generic/unbind || : + echo 0003:03EB:2041.0002 >/sys/bus/hid/drivers/hid-generic/unbind || : + echo 0003:03EB:2042.0001 >/sys/bus/hid/drivers/hid-generic/unbind || : } case $1 in - suspend) - setup_wake - wifi_off - hantro_off - kbd_backlight_off - hid_unbind - ;; - resume) - kbd_backlight_on - wifi_on - hantro_on - hid_bind - ;; - *) - usage - exit 1 + suspend) + setup_wake + wifi_off + hantro_off + kbd_backlight_off + hid_unbind + ;; + resume) + kbd_backlight_on + wifi_on + hantro_on + hid_bind + ;; + *) + usage + exit 1 + ;; esac