echo "No memory split information due to running a 64-bit kernel. Continuing..."
else
echo "No memory split information and not running a 64-bit kernel. Strange."
sleep 2
echo "Continuing..."
fi
elif echo "$vmsplit_output" | grep -q "^CONFIG_VMSPLIT_2G=y" || echo "$vmsplit_output" | grep -q "^# CONFIG_VMSPLIT_3G is not set" ;then
#ensure hardware is pi3 for kernel compiling to work
if [ "$hardware" != 'pi3' ];then
error "This script is not capable of handling your $hardware board with a 2G/2G memory split.\nWhatever you did to get yourself into this situation, undo it and try installing Wine again."
fi
#continue asking until valid answer
while true;do
echo -e "You are using a kernel with a 2G/2G memory split.\nWine will not work on such systems. What would you like to do?
1. Switch to the 64-bit kernel (about 2 minutes)
2. Compile a 3G/1G kernel (several hours)
3. Exit"
read -n1 answer
echo ''
if [ "$answer" == 1 ];then
#switch to 64bit kernel
echo "arm_64bit=1" | sudo tee --append /boot/config.txt >/dev/null
echo -e "The 64-bit kernel has been enabled by adding 'arm_64bit=1' to /boot/config.txt\nPlease reboot and install the Wine app again."
sleep infinity
elif [ "$answer" == 2 ];then
#compile 3g/1g kernel
#backup ~/linux if it exists
rm -rf ~/linux.bak
[ -e ~/linux ] && (echo "$HOME/linux already exists, moving it to $HOME/linux.bak" ; mv -f ~/linux ~/linux.bak)
#download kernel source code
git clone --depth=1 https://github.com/raspberrypi/linux || error "Failed to git clone the raspberry pi kernel repo!"
#build for pi3
cd linux
KERNEL=kernel7
make -j8 bcm2709_defconfig
#change memory split config
echo "Setting memory split to 3G/1G"
sed -i 's/CONFIG_VMSPLIT_2G=y/# CONFIG_VMSPLIT_2G is not set/g' ~/linux/.config || error "sed failed to edit $HOME/linux/.config file!"
sed -i 's/# CONFIG_VMSPLIT_3G is not set/CONFIG_VMSPLIT_3G=1/g' ~/linux/.config
echo '' | make -j8 zImage modules dtbs || error "Failed to make bcm2709_defconfig zImage modules dtbs!"
#install
sudo make modules_install || error "sudo make modules_install failed!"
sudo cp arch/arm/boot/dts/*.dtb /boot/ || error "Failed to copy dtb files to /boot!"
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/ || error "Failed to copy overlays to /boot/overlays!"