#!/bin/bash # #misc globals usb_devs="" num_usb_devs=0 usb_device="" isChromeOS=true isChromiumOS=false flashromcmd="" cbfstoolcmd="" gbbutilitycmd="" preferUSB=false useHeadless=false addPXE=false pxeDefault=false isHswBox=false isBdwBox=false isHswBook=false isBdwBook=false isBaytrail=false isBraswell=false isSkylake=false isUnsupported=false bayTrailHasFullROM=false firmwareType="" isStock=true isFullRom=false isBootStub=false hasRwLegacy=false unlockMenu=false hasShellball=false hsw_boxes=('' '' '' '' ''); hsw_books=('' '' '' ''); bdw_boxes=('' '' ''); bdw_books=('' '' '' '' ''); baytrail=('' '' '' '' '' '' '' '' '' '' '' '' '' '' ''); baytrail_full_rom=('' '' '' '' '' ''); braswell=('' '' '' '' '' ''); skylake=(''); shellballs=($(printf "%s %s %s %s %s " "${hsw_boxes[@]}" "${hsw_books[@]}" "${bdw_boxes[@]}" "${bdw_books[@]}" "${baytrail[@]}")); #menu text output NORMAL=$(echo "\033[m") MENU=$(echo "\033[36m") #Blue NUMBER=$(echo "\033[33m") #yellow FGRED=$(echo "\033[41m") RED_TEXT=$(echo "\033[31m") GRAY_TEXT=$(echo "\033[1;30m") ENTER_LINE=$(echo "\033[33m") function echo_red() { echo -e "\E[0;31m$1" echo -e '\e[0m' } function echo_green() { echo -e "\E[0;32m$1" echo -e '\e[0m' } function echo_yellow() { echo -e "\E[1;33m$1" echo -e '\e[0m' } function exit_red() { echo_red "$@" read -p "Press [Enter] to return to the main menu." } function die() { echo_red "$@" exit 1 } #################### # list USB devices # #################### function list_usb_devices() { #list available drives, excluding internal HDD and root device rootdev="/dev/sda" if [ "$(which rootdev)" ]; then rootdev=$(rootdev -d -s) fi eval usb_devs="($(fdisk -l 2> /dev/null | grep -v 'Disk /dev/sda' | grep -v "Disk $rootdev" | grep 'Disk /dev/sd' | awk -F"/dev/sd|:" '{print $2}'))" #ensure at least 1 drive available [ "$usb_devs" != "" ] || return 1 echo -e "\nDevices available:\n" num_usb_devs=0 for dev in "${usb_devs[@]}" do let "num_usb_devs+=1" vendor=$(udevadm info --query=all --name=sd${dev} | grep -E "ID_VENDOR=" | awk -F"=" '{print $2}') model=$(udevadm info --query=all --name=sd${dev} | grep -E "ID_MODEL=" | awk -F"=" '{print $2}') sz=$(fdisk -l 2> /dev/null | grep "Disk /dev/sd${dev}" | awk '{print $3}') echo -n "$num_usb_devs)" if [ -n "${vendor}" ]; then echo -n " ${vendor}" fi if [ -n "${model}" ]; then echo -n " ${model}" fi echo -e " (${sz} GB)" done echo -e "" return 0 } ################ # Get cbfstool # ################ function get_cbfstool() { if [ ! -f ${cbfstoolcmd} ]; then working_dir=$(pwd) if [[ "$isChromeOS" = false && "$isChromiumOS" = false ]]; then cd /tmp else #have to use /dev/sdx12 due to noexec restrictions rootdev=$(rootdev -d -s) part_num="12" if [[ "${rootdev}" =~ "mmcblk" ]]; then part_num="p12" fi boot_mounted=$(mount | grep "${rootdev}""${part_num}") if [ "${boot_mounted}" = "" ]; then #mount boot mkdir /tmp/boot >/dev/null 2>&1 mount "$(rootdev -d -s)""${part_num}" /tmp/boot if [ $? -ne 0 ]; then echo_red "Error mounting boot partition; cannot proceed." return 1 fi fi #create util dir mkdir /tmp/boot/util 2>/dev/null cd /tmp/boot/util fi #echo_yellow "Downloading cbfstool utility" curl -s -L -O "${util_source}"/cbfstool.tar.gz if [ $? -ne 0 ]; then echo_red "Error downloading cbfstool; cannot proceed." #restore working dir cd ${working_dir} return 1 fi tar -zxf cbfstool.tar.gz --no-same-owner if [ $? -ne 0 ]; then echo_red "Error extracting cbfstool; cannot proceed." #restore working dir cd ${working_dir} return 1 fi #set +x chmod +x cbfstool #restore working dir cd ${working_dir} fi return 0 } ################ # Get flashrom # ################ function get_flashrom() { if [ ! -f ${flashromcmd} ]; then working_dir=`pwd` cd /tmp curl -s -L -O "${util_source}"/flashrom.tar.gz if [ $? -ne 0 ]; then echo_red "Error downloading flashrom; cannot proceed." #restore working dir cd ${working_dir} return 1 fi tar -zxf flashrom.tar.gz if [ $? -ne 0 ]; then echo_red "Error extracting flashrom; cannot proceed." #restore working dir cd ${working_dir} return 1 fi #set +x chmod +x flashrom #restore working dir cd ${working_dir} fi return 0 } ################### # Get gbb_utility # ################### function get_gbb_utility() { if [ ! -f ${gbbutilitycmd} ]; then working_dir=`pwd` cd /tmp curl -s -L -O "${util_source}"/gbb_utility.tar.gz if [ $? -ne 0 ]; then echo_red "Error downloading gbb_utility; cannot proceed." #restore working dir cd ${working_dir} return 1 fi tar -zxf gbb_utility.tar.gz if [ $? -ne 0 ]; then echo_red "Error extracting gbb_utility; cannot proceed." #restore working dir cd ${working_dir} return 1 fi #set +x chmod +x gbb_utility #restore working dir cd ${working_dir} fi return 0 } ################ # Prelim Setup # ################ function prelim_setup() { # Must run as root [ "$(whoami)" = "root" ] || die "You need to run this script as root; use 'sudo bash