From 676451d4324332a732b6d35f45da0ceb8efd56e0 Mon Sep 17 00:00:00 2001 From: Alexander David Frick Date: Sat, 21 May 2022 04:24:50 -0500 Subject: [PATCH] Add check script --- check_avx.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 check_avx.sh diff --git a/check_avx.sh b/check_avx.sh new file mode 100644 index 00000000..f8bf974e --- /dev/null +++ b/check_avx.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# Copyright (c) 2022 Alex313031. + +program="Thorium Browser." # The program we are checking for. + +YEL='\033[1;33m' # Yellow +RED='\033[1;31m' # Red +GRE='\033[1;32m' # Green + +script_name=${0##*/} + +check_result() { # Message calls + local ret="$1" + local msg="$2" + [ "$ret" -ne 0 ] && { printf "${RED}FAIL:" && tput sgr0 && echo " $msg"; exit 1; } + printf "${GRE}SUCCESS:" && tput sgr0 && echo " $msg" +} + +get_cpuinfo() { # return details of the first CPU only + cat /proc/cpuinfo | awk 'BEGIN { RS = "" ; } { printf ("%s\n", $0); exit(0); }' +} + +have_cpu_feature() { + local feature="$1" + get_cpuinfo | egrep -q "^flags.*\<$feature\>" +} + +have_sse42_cpu_feature () { + local feature="sse4_2" + local desc="Streaming SIMD Extensions v4.2" + local need="$desc ($feature)" + have_cpu_feature "$feature" + check_result "$?" "$need" +} + +have_avx_cpu_feature () { + local feature="avx" + local desc="Advanced Vector Extensions" + local need="$desc ($feature)" + have_cpu_feature "$feature" + check_result "$?" "$need" +} + +have_aes_cpu_feature () { + local feature="aes" + local desc="Advanced Encryption Standard Extensions" + local need="$desc ($feature)" + have_cpu_feature "$feature" + check_result "$?" "$need" +} + +have_64bit_cpu() { + local feature="lm" # "Long mode" + local desc="64-bit x86 CPU" + local need="$desc ($feature)" + have_cpu_feature "$feature" + check_result "$?" "$need" +} + +common_checks() { + have_64bit_cpu && \ + have_sse42_cpu_feature && have_aes_cpu_feature && have_avx_cpu_feature +} + +check_host() { + printf "\n" && + printf "${YEL}Checking if host is capable of building/running $program\n" && tput sgr0; echo + common_checks +} + +main() { + case "$1" in + host) check_host ;; + *) printf "${RED}ERROR: Invalid type specified: '$1'\n" 2>&1 && tput sgr0; exit 1 ;; + esac +} + +main "host" && printf "\n" && exit 0