#!/bin/sh
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
#
# This file is part of "Hackware boot" and licensed under the terms of the
# Hacktivista General Public License version 0.1 or (at your option) any later
# version. You should have received a copy of this license along with the
# software. If not, see <https://hacktivista.org/licenses/>.
echo '> Upgrade and patch EC firmware'
echo 'Installing dependencies'
sudo apt-get install -qy git wget build-essential mtools libssl-dev
echo 'Cloning thinkpad-ec patcher repo'
git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/hamishcoleman/thinkpad-ec.git
cd thinkpad-ec
echo 'Patching EC firmware ISO'
make really_clean
make patch_disable_keyboard clean
make patch_enable_battery clean
make patched.x230t.img
echo 'Making original ISO bootable'
./scripts/geteltorito -o gcuj32us.bootable.img gcuj32us.iso.orig
select_storage_path () {
# scan removable storages and request if not inserted
while
STORAGE_DEVICES=$(lsblk -dno PATH,VENDOR,MODEL,SIZE,RM | sed -nEe '/.*1$/{ s/[[:space:]]+/ /g; s/(.*)1/\1/p }' | nl -s ') ' -w 1)
[ -z "$STORAGE_DEVICES" ]
do
echo 'Please insert a removable storage device. Then press <Enter> to continue.'
read -r _CHOICE
done
# select a storage media
STORAGE_DEVICES_COUNT=$(echo "$STORAGE_DEVICES" | wc -l)
while
cat <<- EOF
Select a removable storage device:
$STORAGE_DEVICES
Type a device number from 1 to $STORAGE_DEVICES_COUNT and press <Enter>.
If the device is mounted please unmount it before proceeding.
WARNING: ALL ITS PARTITIONS AND CONTENTS WILL BE WIPED!
EOF
read -r CHOICE
! expr "$CHOICE" : "[1-$STORAGE_DEVICES_COUNT]" 1> /dev/null
do true; done
STORAGE_PATH=$(echo "$STORAGE_DEVICES" | sed -nEe "/$CHOICE/ { s/$CHOICE\) ([^ ]+).*/\1/p }")
}
# select removable storage
select_storage_path
# write original EC firmware update into it
sudo dd if=gcuj32us.bootable.img of="$STORAGE_PATH" bs=4M status=progress conv=fsync
echo 'Done! Please remove the storage device and press <Enter>.'
read -r _CHOICE
cat << EOF
==================================================================
NOW WE WILL UPDATE THE ORIGINAL BIOS AND EC FIRMWARE IN THE LAPTOP
==================================================================
Previous to flashing the firmware please verify the battery is propertly charged and both the battery and the AC power are connected to the laptop.
1. Connect the storage device with the EC Firmware update.
2. Turn it on and press F12 repeatedly to show the boot menu.
3. Select the removable storage. The firmware update software will boot.
4. Select option 2 "Update system program".
5. Read instructions carefully and proceed with the EC firmware update.
When you are done with that press <Enter> here to continue.
EOF
read -r _CHOICE
# select removable storage
select_storage_path
# write patched EC firmware update into it
sudo dd if=patched.x230t.img of="$STORAGE_PATH" bs=4M status=progress conv=fsync
echo 'Done! Please remove the storage device and press <Enter>.'
read -r _CHOICE
cd - 1>/dev/null
cat << EOF
=========================================================
NOW WE WILL FLASH THE PATCHED EC FIRMWARE INTO THE LAPTOP
=========================================================
Previous to flashing the firmware please verify the battery is propertly charged and both the battery and the AC power are connected to the laptop.
1. Connect the storage device with the EC Firmware update.
2. Turn it on and press F12 repeatedly to show the boot menu.
3. Select the removable storage. The firmware update software will boot.
4. Proceed with the EC firmware update.
When you are done with that press <Enter> here to continue.
EOF
read -r _CHOICE