OH MY GOD I ERASED THE SCRIPTS ON ACCIDENT

This commit is contained in:
kxtzownsu 2024-03-05 23:40:58 -05:00
parent e6c7db3091
commit 78c0d5a7b4
2 changed files with 248 additions and 0 deletions

View File

@ -0,0 +1,94 @@
#!/bin/bash
# KVS: Kernel Version Switcher
# Written by kxtzownsu / kxtz#8161
# https://kxtz.dev
# Licensed under GNU Affero GPL v3
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "$0 $(printf '\033[1;31mMUST\033[0m') be ran as root/sudo!"
exit
fi
# source the file multiple times because it wasn't working :3
. ./functions.sh
. ./tpmutil.sh
source ./functions.sh
source ./tpmutil.sh
version=1
GITHUB_URL="https://github.com/kxtzownsu/KVS"
tpmver=$(tpmc tpmver)
if [ "$tpmver" == "2.0" ]; then
tpmdaemon="trunksd"
else
tpmdaemon="tscd"
fi
echo $tpmdaemon
# give me thy kernver NOW
case "$(crossystem tpm_kernver)" in
"0x00000000")
kernver="0"
;;
"0x00010001")
kernver="1"
;;
"0x00010002")
kernver="2"
;;
"0x00010003")
kernver="3"
;;
*)
panic "invalid-kernver"
;;
esac
# detect if booted from usb boot or from recovery boot
if [ "$(crossystem mainfw_type)" == "recovery" ]; then
source tpmutil.sh
mkdir /mnt/state &2> /dev/zero
mount /dev/disk/by-label/KVS /mnt/state
elif [ "$(crossystem mainfw_type)" == "developer" ]; then
# panic "non-reco"
echo ""
clear
fi
credits(){
echo "KVS: Kernel Version Switcher"
echo "V$version"
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "kxtzownsu - Writing KVS, Providing kernver 0 & kernver 1 files."
echo "??? - Providing kernver 2 files."
echo "TBD - Providing kernver 3 files."
echo "Google - Writing the `tpmc` command :3"
}
endkvs(){
# reboot now
stopwatch
}
main(){
echo "KVS: Kernel Version Switcher v$version"
echo "Current kernver: $kernver"
echo "=-=-=-=-=-=-=-=-=-=-"
echo "1) Set New kernver"
echo "2) Backup kernver (WIP, Kinda Broken)"
echo "3) Credits"
echo "4) Exit"
read -rep "> " sel
selection $sel
}
#while true; do
# main
#done
panic "tpmd-not-killed"

View File

@ -0,0 +1,154 @@
#!/bin/bash
style_text() {
printf "\033[31m\033[1m\033[5m$1\033[0m\n"
}
panic(){
case "$1" in
"invalid-kernver")
style_text "KVS PANIC"
printf "\033[31mERR\033[0m"
printf ": Invalid Kernel Version. Please make a GitHub issue at \033[3;34m$GITHUB_URL\033[0m with a picture of this information.\n"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo "tpm_kernver: $(crossystem tpm_kernver)"
echo "fwid: $(dmidecode -s bios-version) (compiled: $(dmidecode -s bios-release-date))"
echo "date: $(date +"%m-%d-%Y %I:%M:%S %p")"
echo "model: $(cat /sys/class/dmi/id/product_name) $(cat /sys/class/dmi/id/product_version)"
echo "Please shutdown your device now using REFRESH+PWR"
sleep infinity
;;
"mount-error")
style_text "KVS PANIC"
printf "\033[31mERR\033[0m"
printf ": Unable to mount stateful. Please make a GitHub issue at \033[3;34m$GITHUB_URL\033[0m with a picture of this information.\n"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo "tpm_kernver: $(crossystem tpm_kernver)"
echo "fwid: $(dmidecode -s bios-version) (compiled: $(dmidecode -s bios-release-date))"
echo "state mounted: $([ -d /mnt/state/ ] && grep -qs '/mnt/state ' /proc/mounts && echo true || echo false)"
echo "date: $(date +"%m-%d-%Y %I:%M:%S %p")"
echo "model: $(cat /sys/class/dmi/id/product_name) $(cat /sys/class/dmi/id/product_version)"
echo "Please shutdown your device now using REFRESH+PWR"
sleep infinity
;;
"non-reco")
style_text "KVS PANIC"
printf "\033[31mERR\033[0m"
printf ": Wrong Boot Method. To fix: boot the shim using the recovery method. (ESC+REFRESH+PWR) and \033[31mNOT\033[0m USB Boot.\n"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo "tpm_kernver: $(crossystem tpm_kernver)"
echo "fwid: $(dmidecode -s bios-version) (compiled: $(dmidecode -s bios-release-date))"
echo "fw mode: $(crossystem mainfw_type)"
echo "date: $(date +"%m-%d-%Y %I:%M:%S %p")"
echo "model: $(cat /sys/class/dmi/id/product_name) $(cat /sys/class/dmi/id/product_version)"
echo "Please shutdown your device now using REFRESH+PWR"
sleep infinity
;;
"tpmd-not-killed")
style_text "KVS PANIC"
printf "\033[31mERR\033[0m"
printf ": $tpmdaemon unable to be killed. Please make a GitHub issue at \033[3;34m$GITHUB_URL\033[0m with a picture of this information.\n"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo "tpm_kernver: $(crossystem tpm_kernver)"
echo "fwid: $(dmidecode -s bios-version) (compiled: $(dmidecode -s bios-release-date))"
echo "tpmd ($tpmdaemon) running: $(status $tpmdaemon | grep stopped && echo true || echo false)"
echo "date: $(date +"%m-%d-%Y %I:%M:%S %p")"
echo "model: $(cat /sys/class/dmi/id/product_name) $(cat /sys/class/dmi/id/product_version)"
echo "Please shutdown your device now using REFRESH+PWR"
sleep infinity
;;
"*")
echo "Panic ID unable to be found: $1"
echo "Exiting script to prevent crash, please make an issue at \033[3;34m$GITHUB_URL\033[0m."
esac
}
stopwatch() {
display_timer() {
printf "[%02d:%02d:%02d]\n" $hh $mm $ss
}
hh=0 #hours
mm=0 #minutes
ss=0 #seconds
while true; do
clear
echo "Initiated reboot, if this doesn't reboot please manually reboot with REFRESH+PWR"
echo "Time since reboot initiated:"
display_timer
ss=$((ss + 1))
# if seconds reach 60, increment the minutes
if [ $ss -eq 60 ]; then
ss=0
mm=$((mm + 1))
fi
# if minutes reach 60, increment the hours
if [ $mm -eq 60 ]; then
mm=0
hh=$((hh + 1))
fi
sleep 1
done
}
selection(){
case $1 in
"1")
echo "Please Enter Target kernver (0-3)"
read -rep "> " kernver
case $kernver in
"0")
echo "Setting kernver 0"
write_tpm 0x1008 $(cat /mnt/realstate/kvs/kernver0)
;;
"1")
echo "Setting kernver 1"
write_tpm 0x1008 $(cat /mnt/realstate/kvs/kernver1)
;;
"2")
echo "Setting kernver 2"
write_tpm 0x1008 $(cat /mnt/realstate/kvs/kernver2)
;;
"3")
echo "Setting kernver 3"
write_tpm 0x1008 $(cat /mnt/realstate/kvs/kernver3)
;;
*)
echo "Invalid kernver. Please check your input."
main
;;
esac ;;
"2")
case $currentkernver in
"0x00000000")
echo "Current kernver: 0"
echo "Outputting to stateful/kernver-out"
cp /mnt/realstate/kvs/kernver0 /mnt/state/kernver-out
;;
"0x00010001")
echo "Current kernver: 1"
echo "Outputting to stateful/kernver-out"
cp /mnt/realstate/kvs/kernver1 /mnt/state/kernver-out
;;
"0x00010002")
echo "Current kernver: 2"
echo "Outputting to stateful/kernver-out"
cp /mnt/realstate/kvs/kernver2 /mnt/state/kernver-out
;;
"0x00010003")
echo "Current kernver: 3"
echo "Outputting to stateful/kernver-out"
cp /mnt/realstate/kvs/kernver3 /mnt/state/kernver-out
;;
*)
panic "invalid-kernver"
;;
esac ;;
"3")
credits
;;
"4")
endkvs
;;
esac
}