From 813b11dcab38876cdfafd7ae319e1c6a0c890af7 Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Sun, 29 Dec 2024 01:35:45 +0900 Subject: [PATCH] Global Function Tweak and Final Check --- install-scripts/02-Final-Check.sh | 58 ++++++++++++++++++++--------- install-scripts/Global_functions.sh | 4 +- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/install-scripts/02-Final-Check.sh b/install-scripts/02-Final-Check.sh index 993cf2f..dc3a354 100755 --- a/install-scripts/02-Final-Check.sh +++ b/install-scripts/02-Final-Check.sh @@ -4,7 +4,6 @@ # NOTE: These package check are only the essentials packages=( - aylurs-gtk-shell cliphist kvantum rofi-wayland @@ -22,45 +21,70 @@ packages=( pyprland ) +# Local packages that should be in /usr/local/bin/ +local_pkgs_installed=( + ags +) + ## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ## # Determine the directory where the script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Change the working directory to the parent directory of the script PARENT_DIR="$SCRIPT_DIR/.." -cd "$PARENT_DIR" || exit 1 +cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; } +# Source the global functions script source "$(dirname "$(readlink -f "$0")")/Global_functions.sh" # Set the name of the log file to include the current date and time LOG="Install-Logs/00_CHECK-$(date +%d-%H%M%S)_installed.log" - -printf "\n%s - Final Check if essential packages where installed \n" "${NOTE}" +printf "\n%s - Final Check if Essential packages were installed \n" "${NOTE}" # Initialize an empty array to hold missing packages missing=() +local_missing=() + +# Function to check if a package is installed using pacman +is_installed_pacman() { + pacman -Qi "$1" &>/dev/null +} # Loop through each package for pkg in "${packages[@]}"; do - # Check if the package is installed - if ! pacman -Qi "$pkg" > /dev/null 2>&1; then + # Check if the package is installed via pacman + if ! is_installed_pacman "$pkg"; then missing+=("$pkg") fi done -# Check if the missing array is empty or not -if [ ${#missing[@]} -eq 0 ]; then +# Check for local packages +for pkg1 in "${local_pkgs_installed[@]}"; do + if ! [ -f "/usr/local/bin/$pkg1" ]; then + local_missing+=("$pkg1") + fi +done + +# Log missing packages +if [ ${#missing[@]} -eq 0 ] && [ ${#local_missing[@]} -eq 0 ]; then echo "${OK} All essential packages are installed." | tee -a "$LOG" else - # Message to user on missing packages - echo "${WARN} The following packages are missing and will be logged:" - - # Log only the missing packages and inform the user - for pkg in "${missing[@]}"; do - echo "$pkg" - echo "$pkg" >> "$LOG" # Log the missing package to the file - done - + if [ ${#missing[@]} -ne 0 ]; then + echo "${WARN} The following packages are not installed and will be logged:" + for pkg in "${missing[@]}"; do + echo "$pkg" + echo "$pkg" >> "$LOG" # Log the missing package to the file + done + fi + + if [ ${#local_missing[@]} -ne 0 ]; then + echo "${WARN} The following local packages are missing from /usr/local/bin/ and will be logged:" + for pkg1 in "${local_missing[@]}"; do + echo "$pkg1 is not installed. Can't find it in /usr/local/bin/" + echo "$pkg1" >> "$LOG" # Log the missing local package to the file + done + fi + # Add a timestamp when the missing packages were logged echo "${NOTE} Missing packages logged at $(date)" >> "$LOG" fi diff --git a/install-scripts/Global_functions.sh b/install-scripts/Global_functions.sh index 0cb1639..3393fae 100755 --- a/install-scripts/Global_functions.sh +++ b/install-scripts/Global_functions.sh @@ -31,7 +31,7 @@ install_package_pacman() { sudo pacman -S --noconfirm "$1" 2>&1 | tee -a "$LOG" # Making sure package is installed if pacman -Q "$1" &>/dev/null ; then - echo -e "${OK} Package ${!YELLOW}$1${RESET} has been successfully installed!" + echo -e "\e[1A\e[K${OK} Package ${YELLOW}$1${RESET} has been successfully installed!" else # Something is missing, exiting to review log echo -e "${ERROR} $1 failed to install. Please check the $LOG. You may need to install manually." @@ -54,7 +54,7 @@ install_package() { $ISAUR -S --noconfirm "$1" 2>&1 | tee -a "$LOG" # Making sure package is installed if $ISAUR -Q "$1" &>> /dev/null ; then - echo -e "\e[1A\e[K${OK} $1 was installed." + echo -e "\e[1A\e[K${OK} Package ${YELLOW}$1${RESET} has been successfully installed!" else # Something is missing, exiting to review log echo -e "\e[1A\e[K${ERROR} $1 failed to install :( , please check the install.log. You may need to install manually! Sorry I have tried :("