mirror of
https://github.com/RasppleII/a2server.git
synced 2024-12-26 11:30:30 +00:00
115 lines
5.0 KiB
Plaintext
115 lines
5.0 KiB
Plaintext
|
#!/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
|