From d8e6f99642b91ed34695ab6bd9f814418614321d Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Fri, 23 Oct 2015 05:12:55 -0700 Subject: [PATCH] Add fix tool --- docs/ivanx/fix/index.txt | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 docs/ivanx/fix/index.txt diff --git a/docs/ivanx/fix/index.txt b/docs/ivanx/fix/index.txt new file mode 100644 index 0000000..ec8f000 --- /dev/null +++ b/docs/ivanx/fix/index.txt @@ -0,0 +1,114 @@ +#!/bin/bash + +echo +echo "A2SERVER fix: This utility will make a Raspberry Pi SD card boot if it" +echo "kernel panics (crashes) on startup after updating its operating system" +echo "while A2SERVER is installed." +echo +echo -n "Continue? " +read +doFix= +if [[ ${REPLY:0:1} == "y" || ${REPLY:0:1} == "Y" ]]; then + while true; do + echo + echo "If attached, remove the Raspberry Pi's SD card from this computer." + echo -n "Press return to continue..."; read; echo + + ls -1 /dev/sd? > /tmp/sd1 2> /dev/null + + echo "Insert the Raspberry Pi's SD card into this computer, using a USB" + echo "reader if you don't have an SD slot. If this is a virtual machine," + echo "make sure you select the reader or SD slot from its USB menu." + echo -n "Press return to continue..."; read; echo + + ls -1 /dev/sd? > /tmp/sd2 2> /dev/null + + # if exactly one drive has been inserted, exit loop + if { ! diff /tmp/sd1 /tmp/sd2 &> /dev/null; }; then + # files are different, get dev name + if [[ $(wc -c /tmp/sd1 | cut -f 1 -d ' ') -eq 0 ]]; then + if [[ $(wc -l /tmp/sd2 | cut -f 1 -d ' ') -eq 1 ]]; then + devName=$(cat /tmp/sd2) + break + else + echo "More than one volume seems to have appeared. Trying again..." + echo + fi + else + devName=$(grep -v "$(cat /tmp/sd1)" /tmp/sd2) + if [[ $(wc -l <<< $devName) -eq 1 ]]; then + break + else + echo "More than one volume seems to have appeared. Trying again..." + echo + fi + fi + else + echo "No SD card found. Trying again..." + echo + fi + + done + + mkdir -p /tmp/sd + sudo mount ${devName}6 /tmp/sd + + raspbianDate=$(date -d "$(zcat /tmp/sd/usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | grep -m 1 ' --' | rev | cut -f 1-6 -d ' ' | rev)" +%s) + doFix= + if [[ $raspbianDate -lt 1403204265 ]]; then + echo "This doesn't appear to be a version of Raspbian that requires fixing." + echo -n "Are you sure you want to continue? " + read + if [[ ${REPLY:0:1} == "y" || ${REPLY:0:1} == "Y" ]]; then + doFix=1 + fi + else + doFix=1 + fi + + if [[ $doFix ]]; then + while read kernelRelease; do + kernelReplaced= + kernelMajorRelease=$(cut -d '.' -f 1 <<< $kernelRelease) + kernelMinorRelease=$(cut -d '.' -f 2 <<< $kernelRelease | sed 's/\(^[0-9]*\)[^0-9].*$/\1/') + kernelPatchRelease=$(cut -d '.' -f 3- <<< $kernelRelease | sed 's/\(^[0-9]*\)[^0-9].*$/\1/') + # if kernel 3.12 below 3.12.25+, delete defective AppleTalk kernel + if [[ $kernelMajorRelease -eq 3 && $kernelMinorRelease -eq 12 && $kernelPatchRelease -lt 25 ]]; then + if [[ -f /tmp/sd/lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko ]]; then + if [[ $(sha1sum /tmp/sd/lib/modules/$kernelRelease/kernel/net/appletalk/appletalk.ko | cut -f 1 -d ' ') != "ecb239fc084c36de93f6926e7749b80f6024f269" ]]; then + echo "Removing defective AppleTalk module from kernel $kernelRelease..." + sudo rm -rf /tmp/sd/lib/modules/$kernelRelease/kernel/net/appletalk 2> /dev/null + wget -qO /tmp/appletalk.ko.gz appleii.ivanx.com/a2server/files/appletalk-$kernelRelease.ko.gz + if [[ $? -eq 0 ]]; then + # if we found a prebuilt one on a2server site, so install it + gunzip -f /tmp/appletalk.ko.gz + sudo mkdir -p /tmp/sd/lib/modules/$kernelRelease/kernel/net/appletalk + sudo mv /tmp/appletalk.ko /tmp/sd/lib/modules/$kernelRelease/kernel/net/appletalk + echo "Installed fixed AppleTalk module for kernel $kernelRelease." + kernelReplaced=1 + fi + fi + fi + fi + done <<< "$(ls -1 /tmp/sd/lib/modules | sort -V)" + sudo umount /tmp/sd + + echo kern:$kernelReplaced + if [[ $kernelReplaced ]]; then + echo + echo "All set. Remove your SD card, put it back in your Pi, and boot it." + echo + echo "You should be able to connect from your Apple II, but if you can't," + echo "log in to your Pi and type 'a2server-setup' to complete the fix." + else + echo + echo "Okey doke. Half done. Remove your SD card, and put it back in your Pi." + echo "After it boots, log in and type 'a2server-setup' to complete the fix." + fi + echo "See the A2SERVER web site at http://ivanx.com/a2server for more help." + echo "(You can type 'sudo shutdown -h now' if you're done on this machine.)" + echo + fi +fi + +rm fix &> /dev/null