diff --git a/firmware-util.sh b/firmware-util.sh index b2bdfc0..d2f18c6 100644 --- a/firmware-util.sh +++ b/firmware-util.sh @@ -12,7 +12,10 @@ # #where the stuff is -script_url="https://raw.githubusercontent.com/Dasharo/scripts/add-support-for-custom-image/" +script_url="https://raw.githubusercontent.com/MrChromebox/scripts/master/" +# usage: sudo DEV_MODE=true bash firmware-util.sh +# it will use local version of scripts +dev_mode=${DEV_MODE:-false} #ensure output of system tools in en-us for parsing export LC_ALL=C @@ -23,7 +26,7 @@ if grep -q "Chrom" /etc/lsb-release ; then mkdir -p /usr/local/bin cd /usr/local/bin else - cd /tmp + [[ "$dev_mode" == false ]] && cd /tmp fi #check for cmd line param, expired CrOS certs @@ -33,20 +36,22 @@ else export CURL="curl" fi -#get support scripts -echo -e "\nDownloading supporting files..." -rm -rf firmware.sh >/dev/null 2>&1 -rm -rf functions.sh >/dev/null 2>&1 -rm -rf sources.sh >/dev/null 2>&1 -$CURL -sLO ${script_url}firmware.sh -rc0=$? -$CURL -sLO ${script_url}functions.sh -rc1=$? -$CURL -sLO ${script_url}sources.sh -rc2=$? -if [[ $rc0 -ne 0 || $rc1 -ne 0 || $rc2 -ne 0 ]]; then - echo -e "Error downloading one or more required files; cannot continue" - exit 1 +if [[ "$dev_mode" == false ]]; then + #get support scripts + echo -e "\nDownloading supporting files..." + rm -rf firmware.sh >/dev/null 2>&1 + rm -rf functions.sh >/dev/null 2>&1 + rm -rf sources.sh >/dev/null 2>&1 + $CURL -sLO ${script_url}firmware.sh + rc0=$? + $CURL -sLO ${script_url}functions.sh + rc1=$? + $CURL -sLO ${script_url}sources.sh + rc2=$? + if [[ $rc0 -ne 0 || $rc1 -ne 0 || $rc2 -ne 0 ]]; then + echo -e "Error downloading one or more required files; cannot continue" + exit 1 + fi fi source ./sources.sh diff --git a/firmware.sh b/firmware.sh index 32c6c5c..35c3c8f 100644 --- a/firmware.sh +++ b/firmware.sh @@ -189,7 +189,8 @@ echo -e "" if [[ "$hasLocalPath" = true ]]; then read -ep "Please provide local path for Full ROM Firmware: " - [[ ! -f "$REPLY" ]] || echo_red "->$REPLY<- file does note exist" && return + [[ -f "$REPLY" ]] || { exit_red "->$REPLY<- file does note exist"; return 1; } + coreboot_file=$REPLY fi # ensure hardware write protect disabled @@ -258,16 +259,18 @@ OS; ${currOS} will no longer be bootable. See https://mrchromebox.tech/#faq" [[ "$REPLY" = "y" || "$REPLY" = "Y" ]] || return fi -#determine correct file / URL -firmware_source=${fullrom_source} -if [[ "$hasUEFIoption" = true || "$hasLegacyOption" = true ]]; then - if [ "$useUEFI" = true ]; then - eval coreboot_file=$`echo "coreboot_uefi_${device}"` - else - eval coreboot_file=$`echo "coreboot_${device}"` - fi -else - exit_red "Unknown or unsupported device (${device^^}); cannot continue."; return 1 +if [[ "hasLocalPath" == false ]];then + #determine correct file / URL + firmware_source=${fullrom_source} + if [[ "$hasUEFIoption" = true || "$hasLegacyOption" = true ]]; then + if [ "$useUEFI" = true ]; then + eval coreboot_file=$`echo "coreboot_uefi_${device}"` + else + eval coreboot_file=$`echo "coreboot_${device}"` + fi + else + exit_red "Unknown or unsupported device (${device^^}); cannot continue."; return 1 + fi fi #auron special case (upgrade from coolstar legacy rom) @@ -386,13 +389,17 @@ fi #download firmware file cd /tmp -echo_yellow "\nDownloading Full ROM firmware\n(${coreboot_file})" -$CURL -sLO "${firmware_source}${coreboot_file}" -$CURL -sLO "${firmware_source}${coreboot_file}.sha1" -#verify checksum on downloaded file -sha1sum -c ${coreboot_file}.sha1 --quiet > /dev/null 2>&1 -[[ $? -ne 0 ]] && { exit_red "Firmware download checksum fail; download corrupted, cannot flash."; return 1; } +if [[ "$hasLocalPath" = false ]]; then + echo_yellow "\nDownloading Full ROM firmware\n(${coreboot_file})" + + $CURL -sLO "${firmware_source}${coreboot_file}" + $CURL -sLO "${firmware_source}${coreboot_file}.sha1" + + #verify checksum on downloaded file + sha1sum -c ${coreboot_file}.sha1 --quiet > /dev/null 2>&1 + [[ $? -ne 0 ]] && { exit_red "Firmware download checksum fail; download corrupted, cannot flash."; return 1; } +fi #preferUSB? if [[ "$preferUSB" = true && $useUEFI = false ]]; then @@ -1417,14 +1424,14 @@ function uefi_menu() { echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 1)${GRAY_TEXT} Install/Update UEFI (Full ROM) Firmware${NORMAL}" fi if [[ "$hasUEFIoption" = true ]]; then - echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 1)${MENU} Install/Update Custom UEFI (Full ROM) Firmware from local path ${NORMAL}" + echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 2)${MENU} Install/Update Custom UEFI (Full ROM) Firmware from local path ${NORMAL}" else - echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 1)${GRAY_TEXT} Install/Update Custom UEFI (Full ROM) Firmware from local path${NORMAL}" + echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 2)${GRAY_TEXT} Install/Update Custom UEFI (Full ROM) Firmware from local path${NORMAL}" fi if [[ "$isChromeOS" = false && "$isFullRom" = true ]]; then - echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 2)${MENU} Restore Stock Firmware ${NORMAL}" + echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} 3)${MENU} Restore Stock Firmware ${NORMAL}" else - echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 2)${GRAY_TEXT} Restore Stock ChromeOS Firmware ${NORMAL}" + echo -e "${GRAY_TEXT}** ${GRAY_TEXT} 3)${GRAY_TEXT} Restore Stock ChromeOS Firmware ${NORMAL}" fi if [[ "${device^^}" = "EVE" ]]; then echo -e "${MENU}**${WP_TEXT} [WP]${NUMBER} D)${MENU} Downgrade Touchpad Firmware ${NORMAL}" @@ -1446,7 +1453,7 @@ function uefi_menu() { ;; 2) if [[ "$hasUEFIoption" = true ]]; then - hasLocalPath = true + hasLocalPath=true flash_coreboot fi uefi_menu diff --git a/functions.sh b/functions.sh index 6f301e7..edefbfa 100644 --- a/functions.sh +++ b/functions.sh @@ -54,6 +54,7 @@ hasCR50=false kbl_use_rwl18=false useAltfwStd=false runsWindows=false +hasLocalPath=false hsw_boxes=('mccloud' 'panther' 'tricky' 'zako') hsw_books=('falco' 'leon' 'monroe' 'peppy' 'wolf')