From b6bfcdbd4551257f924a7e84d60c93a063dd5d0a Mon Sep 17 00:00:00 2001 From: Vincent Brillault Date: Tue, 9 Jan 2018 13:04:49 +0100 Subject: Move configuration at the beginning of the script --- spectre-meltdown-checker.sh | 191 ++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 95 deletions(-) diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index 820c10c..a6cb99f 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -10,93 +10,7 @@ # VERSION=0.19 -# print status function -pstatus() -{ - if [ "$opt_no_color" = 1 ]; then - _echo_nol "$2" - else - case "$1" in - red) col="\033[101m\033[30m";; - green) col="\033[102m\033[30m";; - yellow) col="\033[103m\033[30m";; - blue) col="\033[104m\033[30m";; - *) col="";; - esac - _echo_nol "$col $2 \033[0m" - fi - [ -n "$3" ] && _echo_nol " ($3)" - _echo -} - -# The 3 below functions are taken from the extract-linux script, available here: -# https://github.com/torvalds/linux/blob/master/scripts/extract-vmlinux -# The functions have been modified for better integration to this script -# The original header of the file has been retained below - -# ---------------------------------------------------------------------- -# extract-vmlinux - Extract uncompressed vmlinux from a kernel image -# -# Inspired from extract-ikconfig -# (c) 2009,2010 Dick Streefland -# -# (c) 2011 Corentin Chary -# -# Licensed under the GNU General Public License, version 2 (GPLv2). -# ---------------------------------------------------------------------- - -vmlinux='' -vmlinux_err='' -check_vmlinux() -{ - readelf -h $1 > /dev/null 2>&1 || return 1 - return 0 -} - -try_decompress() -{ - # The obscure use of the "tr" filter is to work around older versions of - # "grep" that report the byte offset of the line instead of the pattern. - - # Try to find the header ($1) and decompress from here - for pos in `tr "$1\n$2" "\n$2=" < "$5" | grep -abo "^$2"` - do - if ! which $3 >/dev/null 2>&1; then - vmlinux_err="missing '$3' tool, please install it, usually it's in the '$4' package" - return 0 - fi - pos=${pos%%:*} - tail -c+$pos "$5" | $3 > $vmlinuxtmp 2> /dev/null - check_vmlinux "$vmlinuxtmp" && vmlinux=$vmlinuxtmp && return 0 - done - return 1 -} - -extract_vmlinux() -{ - [ -n "$1" ] || return 1 - # Prepare temp files: - vmlinuxtmp="$(mktemp /tmp/vmlinux-XXXXXX)" - trap "rm -f $vmlinuxtmp" EXIT - - # Initial attempt for uncompressed images or objects: - if check_vmlinux "$1"; then - cat "$1" > "$vmlinuxtmp" - vmlinux=$vmlinuxtmp - return 0 - fi - - # That didn't work, so retry after decompression. - try_decompress '\037\213\010' xy gunzip gunzip "$1" && return 0 - try_decompress '\3757zXZ\000' abcde unxz xz-utils "$1" && return 0 - try_decompress 'BZh' xy bunzip2 bzip2 "$1" && return 0 - try_decompress '\135\0\0\0' xxx unlzma xz-utils "$1" && return 0 - try_decompress '\211\114\132' xy 'lzop -d' lzop "$1" && return 0 - return 1 -} - -# end of extract-vmlinux functions - +# Script configuration show_usage() { cat < +# +# (c) 2011 Corentin Chary +# +# Licensed under the GNU General Public License, version 2 (GPLv2). +# ---------------------------------------------------------------------- + +vmlinux='' +vmlinux_err='' +check_vmlinux() +{ + readelf -h $1 > /dev/null 2>&1 || return 1 + return 0 +} + +try_decompress() +{ + # The obscure use of the "tr" filter is to work around older versions of + # "grep" that report the byte offset of the line instead of the pattern. + + # Try to find the header ($1) and decompress from here + for pos in `tr "$1\n$2" "\n$2=" < "$5" | grep -abo "^$2"` + do + if ! which $3 >/dev/null 2>&1; then + vmlinux_err="missing '$3' tool, please install it, usually it's in the '$4' package" + return 0 + fi + pos=${pos%%:*} + tail -c+$pos "$5" | $3 > $vmlinuxtmp 2> /dev/null + check_vmlinux "$vmlinuxtmp" && vmlinux=$vmlinuxtmp && return 0 + done + return 1 +} + +extract_vmlinux() +{ + [ -n "$1" ] || return 1 + # Prepare temp files: + vmlinuxtmp="$(mktemp /tmp/vmlinux-XXXXXX)" + trap "rm -f $vmlinuxtmp" EXIT + + # Initial attempt for uncompressed images or objects: + if check_vmlinux "$1"; then + cat "$1" > "$vmlinuxtmp" + vmlinux=$vmlinuxtmp + return 0 + fi + + # That didn't work, so retry after decompression. + try_decompress '\037\213\010' xy gunzip gunzip "$1" && return 0 + try_decompress '\3757zXZ\000' abcde unxz xz-utils "$1" && return 0 + try_decompress 'BZh' xy bunzip2 bzip2 "$1" && return 0 + try_decompress '\135\0\0\0' xxx unlzma xz-utils "$1" && return 0 + try_decompress '\211\114\132' xy 'lzop -d' lzop "$1" && return 0 + return 1 +} + +# end of extract-vmlinux functions + # check for mode selection inconsistency if [ "$opt_live_explicit" = 1 ]; then if [ -n "$opt_kernel" -o -n "$opt_config" -o -n "$opt_map" ]; then -- cgit v1.2.3