Skip to content

Instantly share code, notes, and snippets.

@Flummi
Created October 7, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flummi/79c9138c483a7bdb192c79ec78454dc1 to your computer and use it in GitHub Desktop.
Save Flummi/79c9138c483a7bdb192c79ec78454dc1 to your computer and use it in GitHub Desktop.
#!/bin/bash
mode="default"
height=20
width=40
choice_height=19
function sel_mode {
backtitle="Select if default or failsafe"
title="muh"
menu="Choose one of the following options:"
options=(1 "default"
2 "failsafe")
choice=$(dialog --clear --backtitle "$backtitle" --title "$title" --menu "$menu" $height $width $choice_height "${options[@]}" 2>&1 >/dev/tty)
clear
case $choice in
1) mode="default" ;;
2) mode="failsafe" ;;
*) exit ;;
esac
}
function sel_kernel {
act=`find /boot/conf.d/system.${mode} -type l -ls | grep -o 'linux\-.*'`
actint=0
backtitle="Select Kernel for ${mode}"
title="Actual ${mode}: ${act}"
menu="Choose one of the following options:"
options=()
kernels=("dummy")
j=1
for i in $(ls /boot/kernel.d); do
if [[ $i == "linux-"* ]]; then
if [[ $i == $act ]]; then
options+=("${j//'"'/}" "${i//'"'/} [*]")
actint=$j
else
options+=("${j//'"'/}" "${i//'"'/}")
fi
kernels+=($i)
j=`expr $j + 1`
fi
done
choice=$(dialog --clear --backtitle "$backtitle" --title "$title" --menu "$menu" $height $width $choice_height "${options[@]}" 2>&1 >/dev/tty)
clear
if [[ $choice == $actint ]]; then
echo "no changes; abort"
else
if (( choice > 0 )); then
echo "changing kernel to ${kernels[$choice]}"
rm /boot/conf.d/system.${mode}/kernel
cd /boot/conf.d/system.${mode}
ln -s ../../kernel.d/${kernels[$choice]} kernel
echo "symlink: `find /boot/conf.d/system.${mode} -type l -ls | grep -o 'linux\-.*'`"
else
echo "nothing choosed; abort"
fi
fi
}
function check_updates {
versions=("dummy" "aarch64-rc" "aarch64" "odroid-c2")
backtitle="check for updates"
title="check for updates"
echo "0" | dialog --title "$title" --backtitle "$backtitle" --gauge "update repo" 0 0
pacman -Sy 2>&1 >/dev/null
echo "33" | dialog --title "$title" --backtitle "$backtitle" --gauge "linux-aarch64-rc" 0 0
cu_main=`pacman -Si linux-aarch64-rc | grep 'Version.*' | sed -r 's/.*\: (.*?)\-1/linux-\\1/g'`
echo "66" | dialog --title "$title" --backtitle "$backtitle" --gauge "linux-aarch64" 0 0
cu_rc=`pacman -Si linux-aarch64 | grep 'Version.*' | sed -r 's/.*\: (.*?)\-1/linux-\\1/g'`
echo "100" | dialog --title "$title" --backtitle "$backtitle" --gauge "linux-odroid-c2" 0 0
cu_c2=`pacman -Si linux-odroid-c2 | grep 'Version.*' | sed -r 's/.*\: (.*?)/linux-\\1/g'`
clear
options=(1 "$cu_main"
2 "$cu_rc"
3 "$cu_c2")
backtitle="choose version to install"
title="choose version to install"
menu="CHOOSE"
choice=$(dialog --clear --backtitle "$backtitle" --title "$title" --menu "$menu" $height $width $choice_height "${options[@]}" 2>&1 >/dev/tty)
clear
if [[ $choice ]]; then
pacman -S linux-"${versions[$choice]}"
sel_mode
sel_kernel
else
echo "abort"
fi
}
function convert_kernel {
kver=`pacman -Qo /boot/Image | grep -o 'by.*' | sed -r 's/by .* (.*?)/\\1/g'`
if [ -f "/boot/Image" ]; then
rm /boot/kernel.d/linux-${kver} -Rf
mkdir -p /boot/kernel.d/linux-${kver}
mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -d /boot/initramfs-linux.img -n ${kver} /boot/kernel.d/linux-${kver}/uInitrd
mkimage -A arm64 -O linux -T kernel -C none -a 0x1080000 -e 0x1080000 -n ${kver} -d /boot/Image /boot/kernel.d/linux-${kver}/uImage
if [[ -f "/boot/dtbs/meson64_odroidc2.dtb" ]]; then # linux-odroid-c2
mv /boot/dtbs/meson64_odroidc2.dtb /boot/kernel.d/linux-${kver}/meson-gxbb-odroidc2.dtb
else # linux-aarch64(-rc)
mv /boot/dtbs/amlogic/meson-gxbb-odroidc2.dtb /boot/kernel.d/linux-${kver}/meson-gxbb-odroidc2.dtb
fi
mv /boot/Image /boot/kernel.d/linux-${kver}/Image
rm /boot/Image.gz /boot/dtbs /boot/initramfs-linux* -Rf
else
echo "No new Image found"
if ! [[ $noreturn ]]; then
main_menu
fi
fi
}
function main_menu {
backtitle="muh"
title="mode: ${mode}"
menu="Choose one of the following options:"
case $mode in
"default") switchto="failsafe" ;;
"failsafe") switchto="default" ;;
esac
options=(1 "switch to ${switchto}"
2 "change Kernelsymlink"
3 "convert Kernel in /boot"
4 "check for Kernelupdate")
choice=$(dialog --clear --backtitle "$backtitle" --title "$title" --menu "$menu" $height $width $choice_height "${options[@]}" 2>&1 >/dev/tty)
clear
case $choice in
1)
#sel_mode
case $mode in
"default") mode="failsafe" ;;
"failsafe") mode="default" ;;
esac
main_menu
;;
2)
sel_kernel
;;
3)
convert_kernel
;;
4)
check_updates
;;
*)
exit
;;
esac
}
if [[ $1 == "ck" ]]; then
noreturn=true
convert_kernel
else
main_menu
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment