diff --git a/util/functions.sh b/util/functions.sh index c593833..526465d 100755 --- a/util/functions.sh +++ b/util/functions.sh @@ -6,11 +6,20 @@ GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' +FLASHROM=$(whereis -b flashrom | cut -d ' ' -f 2) +DMIDECODE=$(whereis -b dmidecode | cut -d ' ' -f 2) + force_x230_and_root() { - command -v dmidecode >/dev/null 2>&1 || { echo -e >&2 "${RED}Please install dmidecode and run as root.${NC}"; exit 1; } + if [ "$EUID" -ne 0 ] ; then + echo -e "${RED}Please run this as root.${NC} And make sure you have the following programs:" + echo "dmidecode" + echo "flashrom" + + exit 1 + fi - local LAPTOP=$(dmidecode | grep -i x230 | sort -u) + local LAPTOP=$(${DMIDECODE} | grep -i x230 | sort -u) if [ -z "$LAPTOP" ] ; then echo "This is no Thinkpad X230. This script is useless then." exit 0 diff --git a/x230/x230_heads.sh b/x230/x230_heads.sh index 9cc6213..29ef6af 100755 --- a/x230/x230_heads.sh +++ b/x230/x230_heads.sh @@ -115,7 +115,7 @@ check_battery while true; do read -r -p "Flash the BIOS now? y/N: " yn case $yn in - [Yy]* ) cd ${OUTPUT_PATH} && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;; + [Yy]* ) cd ${OUTPUT_PATH} && ${FLASHROM} -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;; [Nn]* ) exit;; * ) exit;; esac diff --git a/x230/x230_skulls.sh b/x230/x230_skulls.sh index 5035a3e..a0a0a4f 100755 --- a/x230/x230_skulls.sh +++ b/x230/x230_skulls.sh @@ -118,9 +118,9 @@ fi force_x230_and_root -BIOS_VENDOR=$(dmidecode -t bios | grep Vendor | cut -d':' -f2) +BIOS_VENDOR=$(${DMIDECODE} -t bios | grep Vendor | cut -d':' -f2) if [[ $BIOS_VENDOR != *"coreboot"* ]] ; then - BIOS_VERSION=$(dmidecode -s bios-version | grep -o '[1-2].[0-7][0-9]') + BIOS_VERSION=$(${DMIDECODE} -s bios-version | grep -o '[1-2].[0-7][0-9]') bios_major=$(echo "$BIOS_VERSION" | cut -d. -f1) bios_minor=$(echo "$BIOS_VERSION" | cut -d. -f2) @@ -203,7 +203,7 @@ check_battery while true; do read -r -p "Flash the BIOS now? y/N: " yn case $yn in - [Yy]* ) cd ${OUTPUT_PATH} && flashrom -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;; + [Yy]* ) cd ${OUTPUT_PATH} && ${FLASHROM} -p internal --layout ${LAYOUT_FILENAME} --image bios -w "${OUTPUT_IMAGE_NAME}"; break;; [Nn]* ) exit;; * ) exit;; esac