Files

149 lines
4.9 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
#upgrading script apple linux T2 Kernel
2022-11-06 16:20:35 +05:30
if [[ ($USER != root) && ($1 != -c) && ($1 != --check-version) ]]
then
sudo chmod 755 $0
2022-09-29 22:28:55 +01:00
sudo $0 $1
exit 0
fi
wget -q --spider http://github.com
if [ $? -eq 0 ]; then
true
else
echo "Please connect to the internet"
exit 1
fi
set -e
cd /tmp
use_lts=false
2024-01-08 19:28:34 +05:30
lts_version=6.6
2022-11-27 20:22:23 +05:30
CODENAME=$(lsb_release -c | cut -d ":" -f 2 | xargs)
2023-02-02 07:59:27 +05:30
# Linux Mint
2022-11-27 20:22:23 +05:30
if [[ (${CODENAME} = ulyana) || (${CODENAME} = ulyssa) || (${CODENAME} = uma) || (${CODENAME} = una) ]]
then
EFFECTIVE_CODENAME=focal
2024-01-23 22:50:15 +05:30
elif [[ (${CODENAME} = vanessa) || (${CODENAME} = vera) || (${CODENAME} = victoria) || (${CODENAME} = virginia) ]]
2022-11-27 20:22:23 +05:30
then
EFFECTIVE_CODENAME=jammy
2023-02-02 07:59:27 +05:30
# Elementary OS
elif [[ (${CODENAME} = horus) ]]
then
EFFECTIVE_CODENAME=jammy
# Default
2022-11-27 20:22:23 +05:30
else
EFFECTIVE_CODENAME=${CODENAME}
fi
if [[ $use_lts != true ]]
then
latest=$(curl -sL https://github.com/t2linux/T2-Ubuntu-Kernel/releases/latest/ | grep "<title>Release" | awk -F " " '{print $2}' )
else
getkernelver=$(curl -sL https://github.com/t2linux/T2-Ubuntu-Kernel/releases | grep "{{ urlEncodedRefName }}" | grep -v "generic" | grep v${lts_version} | cut -d "{" -f 3 | cut -c 25- | head -1)
latest=${getkernelver::-76}
fi
2022-10-05 10:56:54 +05:30
if [[ (${#latest} = 6) || (${#latest} = 7) ]]
then
2022-12-22 17:26:40 +05:30
pkgrel=$(echo $latest | cut -d "-" -f 2)
latestkver=$(echo $latest | cut -d "v" -f 2 | cut -d "-" -f 1 | awk '{print $1".0"}')-${pkgrel}
2022-11-27 20:22:23 +05:30
latestk=$(echo $latest | cut -c 2- | cut -d "-" -f 1 | awk '{print $1".0-t2"}')-${EFFECTIVE_CODENAME}
else
latestkver=$(echo $latest | cut -d "v" -f 2)
2022-11-27 20:22:23 +05:30
latestk=$(echo $latest | cut -c 2- | cut -d "-" -f 1 | awk '{print $1"-t2"}')-${EFFECTIVE_CODENAME}
fi
2024-01-18 15:03:40 +05:30
if [[ (${EFFECTIVE_CODENAME} = focal) ]]
2024-01-18 14:52:23 +05:30
then
cat <<EOF
You seem to be using Ubuntu 20.04 Focal Fossa or its derived distro.
These distros are no longer supported
2024-01-18 14:58:41 +05:30
The latest LTS version 6.1.71 shall be installed and no further kernel upgrades shall be available.
EOF
2024-01-18 14:52:23 +05:30
latest=v6.1.71-1
2024-01-18 15:09:19 +05:30
latestk=6.1.71-t2-focal
2024-01-18 14:52:23 +05:30
latestkver=6.1.71-1
fi
currentk=$(uname -r)
currentkver=$(apt show linux-image-${currentk} 2>/dev/null | grep Version | cut -d ":" -f 2 | xargs)
2022-09-29 20:34:18 +01:00
existingK=($(dpkg --list | grep linux-image- | grep 't2\|mbp' | cut -d ' ' -f 2-3 ))
if [[ ( $latestkver != $currentkver ) && (( $(echo ${latestk} | cut -d "." -f 1,2) != $lts_version ) || ( ${use_lts} = true )) ]]; then
2022-11-06 16:20:35 +05:30
if [[ ($1 = -c) || ($1 = --check-version) ]]; then
echo "New kernel $latest is available."
[ -n "$DISPLAY" ] && [ -x "$(command -v notify-send)" ] && notify-send --icon=info -t 12000 \
"New kernel $latest is available." \
"Run \'update_t2_kernel\' to upgrade your kernel or visit https://github.com/t2linux/T2-Ubuntu-Kernel/releases/tag/${latest}"
exit 0
fi
echo "Downloading new kernel $latest"
2022-10-13 14:52:57 +05:30
echo -e "\nDownloading linux-headers-${latestk}"
2022-10-13 14:46:32 +05:30
echo
curl -#L https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/${latest}/linux-headers-${latestk}_${latestkver}_amd64.deb > headers.deb
2022-10-13 14:52:57 +05:30
echo -e "\nDownloading linux-image-${latestk}"
2022-10-13 14:46:32 +05:30
echo
curl -#L https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/${latest}/linux-image-${latestk}_${latestkver}_amd64.deb > image.deb
2022-12-22 17:10:25 +05:30
echo -e "\nVerifying checksums"
curl -sL https://github.com/t2linux/T2-Ubuntu-Kernel/releases/download/${latest}/sha256-${EFFECTIVE_CODENAME} > sha
actual_headers_chksum=$(cat ./sha | grep linux-headers-${latestk}_${latestkver}_amd64.deb | cut -d " " -f 1)
actual_image_chksum=$(cat ./sha | grep linux-image-${latestk}_${latestkver}_amd64.deb | cut -d " " -f 1)
downloaded_headers_chksum=$(sha256sum ./headers.deb | cut -d " " -f 1)
downloaded_image_chksum=$(sha256sum ./image.deb | cut -d " " -f 1)
if [[ ${actual_headers_chksum} != ${downloaded_headers_chksum} ]]
then
echo -e "\nError: Failed to verify checksum of linux-headers-${latestk}"
fi
if [[ ${actual_image_chksum} != ${downloaded_image_chksum} ]]
then
echo -e "\nError: Failed to verify checksum of linux-image-${latestk}"
fi
if [[ (${actual_headers_chksum} = ${downloaded_headers_chksum}) && (${actual_image_chksum} = ${downloaded_image_chksum}) ]]; then
2022-09-29 20:34:18 +01:00
#install
2022-12-22 17:10:25 +05:30
echo -e "\nChecksums successfully verified"
2022-10-13 14:46:32 +05:30
echo -e "\nInstalling new kernel $latest"
echo
2022-11-25 13:36:08 +05:30
apt install ./headers.deb ./image.deb
2022-09-29 20:34:18 +01:00
#shutdown -r 02:00 "reboot scheduled for the next 2am to update runnning kernel"
rm -f headers.deb image.deb
2022-09-29 20:34:18 +01:00
#uninstall old t2 kernels but preserve current version as a backup
if [[ ( $latestk != $currentk ) ]]; then
for kernel in "${existingK[@]}"
do
if [ \( $kernel != linux-image-$currentk \) ]; then
echo -e "\n$kernel needs to be removed"
version=${kernel/#linux-image-}
#purge old t2 kernel
echo
dpkg -P linux-headers-$version linux-image-$version
fi
done
fi
if [[ ($1 = --remove-current) ]]; then
2022-10-13 14:46:32 +05:30
echo -e "\nCurrent kernel linux-image-$currentk shall also be removed"
echo
2022-11-25 13:36:08 +05:30
dpkg -P linux-headers-$currentk linux-image-$currentk
fi
2022-12-22 17:10:25 +05:30
else
exit 1
fi
else
echo "Kernel is up to date"
fi