From 93df1541a98706f7780b126a237516bf588d3a8e Mon Sep 17 00:00:00 2001 From: Steffen Moeller Date: Sun, 8 Oct 2023 15:17:44 +0200 Subject: [PATCH] Satisfied shellcheck, early check for dependencies to simplify. --- install.sh | 101 +++++++++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/install.sh b/install.sh index d461f7cf..8326cafb 100755 --- a/install.sh +++ b/install.sh @@ -1,78 +1,87 @@ #!/bin/bash +set -e + +# Ensuring we have all the tools we require + +missing="" +for tool in git curl apt wget make +do + if command -v "$tool" > /dev/null ; then + missing="$missing $tool" + fi +done +if [ -n "$missing" ]; then + echo "E: This script lacks the following tool(s) to be executed successfully: $missing" + echo "I: To update your current installation and install all build deps run" + echo " sudo apt update + echo " sudo apt upgrade -y + echo " sudo apt install -y git curl wget make" + exit 1 +fi + +# Loading helping routines + source lib/source + +# Main + RED="\e[0;31m" GRN="\e[0;32m" PNK="\e[0;35m" TXT="\033[0m" YLW="\e[0;33m" FIN="\e[0m" -GIT_BRANCH=`git branch` -echo "" +GIT_BRANCH=$(git branch) + +echo echo -en "${TXT}Raspberry Pi Image Builder:${FIN}" echo -e " ${PNK}[${FIN}${GRN}${GIT_BRANCH}${FIN}${PNK}]${FIN}" -if [[ `command -v curl` ]]; then - :; -else - echo "" - echo -e "Missing dependency: curl" - sudo apt install -y curl wget -fi echo -en "${TXT}Checking Internet Connection:${FIN} " -if [[ `curl -I https://github.com 2>&1 | grep 'HTTP/2 200'` ]]; then +if curl -I https://github.com 2>&1 | grep -q 'HTTP/2 200' ; then echo -en "${PNK}[${FIN}${GRN}OK${FIN}${PNK}]${FIN}" - echo "" + echo else echo -en "${PNK}[${FIN}${RED}failed${FIN}${PNK}]${FIN}" - echo "" + echo echo -e "${TXT}Please check your internet connection and try again${FIN}." - exit 0 + exit 1 fi echo -en "${TXT}Checking Host Machine:${FIN} " sleep .50 if [[ "$HOST_CODENAME" == "jammy" ]]; then echo -en "${PNK}[${FIN}${GRN}Ubuntu Jammy Jellyfish${FIN}${PNK}]${FIN}" - echo "" + echo else if [[ "$HOST_CODENAME" == "bullseye" ]]; then echo -en "${PNK}[${FIN}${GRN}Debian Bullseye${FIN}${PNK}]${FIN}" - echo "" + echo else if [[ "$HOST_CODENAME" == "bookworm" ]]; then echo -en "${PNK}[${FIN}${GRN}Debian Bookworm${FIN}${PNK}]${FIN}" - echo "" + echo else echo -ne "${PNK}[${FIN}${RED}failed${FIN}${PNK}]${FIN}" - echo "" + echo echo -e "${TXT}The OS you are running is not supported${FIN}." - exit 0 + exit 1 fi fi fi -echo "" +echo if [[ "$HOST_ARCH" == "x86_64" || "$HOST_ARCH" == "aarch64" ]]; then :; else echo -e "ARCH: $HOST_ARCH is not supported by this script." - exit 0 + exit 1 fi if [[ "$HOST_ARCH" == "x86_64" ]]; then echo -e "${TXT}Starting install ...${FIN}" sleep .50 - if [[ `command -v make` ]]; then - sudo apt update - sudo apt upgrade -y - make ccompile - else - sleep 1s - sudo apt update - sudo apt upgrade -y - sudo apt install -y make - make ccompile - fi + make ccompile fi if [[ "$HOST_ARCH" == "aarch64" ]]; then @@ -83,41 +92,11 @@ if [[ "$HOST_ARCH" == "aarch64" ]]; then do case $opt in "Cross Compiling") - if [[ `command -v make` ]]; then - echo "" - echo -e "${TXT}Starting install ...${FIN}" - sleep 1s - sudo apt update - sudo apt upgrade -y make ccompile64 - else - echo "" - echo -e "${TXT}Starting install ...${FIN}" - sleep 1s - sudo apt update - sudo apt upgrade -y - sudo apt install -y make - make ccompile64 - fi break ;; "Native Compiling") - if [[ `command -v make` ]]; then - echo "" - echo -e "${TXT}Starting install ...${FIN}" - sleep 1s - sudo apt update - sudo apt upgrade -y - make ncompile - else - echo "" - echo -e "${TXT}Starting install ...${FIN}" - sleep 1s - sudo apt update - sudo apt upgrade -y - sudo apt install -y make make ncompile - fi break ;; "Quit")