Script problem

hi i am making install scipt and i want to have that if gpu=nvidia install "nvidia-utils if gpu=amd install radeontop else intel_gpu_top

full installation code:

#!/bin/bash

# Function to check if a command exists
command_exists() {
    command -v "$1" &> /dev/null
}

# Function to install packages based on distribution
install_packages() {
    local distribution=$1
    shift
    local packages=("$@")

    case $distribution in
        debian|ubuntu)
            sudo apt update
            sudo apt install -y "${packages[@]}"
            ;;
        fedora)
            sudo dnf install -y "${packages[@]}"
            ;;
        arch|endeavouros|manjaro)
            sudo pacman -Syu --needed --noconfirm "${packages[@]}"
            ;;
        *)
            echo "Unsupported distribution: $distribution"
            exit 1
            ;;
    esac
}

# Determine the Linux distribution
get_distribution() {
    if command_exists lsb_release; then
        lsb_release -si | tr '[:upper:]' '[:lower:]'
    elif [ -e /etc/os-release ]; then
        source /etc/os-release
        echo "$ID" | tr '[:upper:]' '[:lower:]'
    else
        echo "unknown"
    fi
}

# Function to install Nerd Fonts
install_nerdfonts() {
    echo "Installing Nerd Fonts..."
    local distribution=$1
    case $distribution in
        debian|ubuntu)
            sudo apt install -y fonts-firacode
            ;;
        fedora)
            sudo dnf install -y fira-code-fonts
            ;;
        arch|endeavouros|manjaro)
            sudo pacman -S --noconfirm --needed ttf-fira-code
            ;;
        *)
            echo "Unsupported distribution: $distribution"
            exit 1
            ;;
    esac
}

# Check dependencies
dependencies=("lm_sensors" "nvidia-utils" "radeontop" "intel_gpu_top")
missing_deps=()

for dep in "${dependencies[@]}"; do
    if ! command_exists "$dep"; then
        missing_deps+=("$dep")
    fi
done

# Install missing dependencies
if [[ ${#missing_deps[@]} -gt 0 ]]; then
    echo "Installing missing dependencies: ${missing_deps[*]}"
    distribution=$(get_distribution)

    case $distribution in
        debian|ubuntu|arch|endeavouros|manjaro)
            install_packages "$distribution" "${missing_deps[@]}"
            ;;
        *)
            echo "Unsupported distribution: $distribution"
            exit 1
            ;;
    esac
fi

# Check for and install Nerd Fonts
echo "Checking for Nerd Fonts..."
if ! fc-list : file family | grep -q "Nerd Font"; then
    distribution=$(get_distribution)
    install_nerdfonts "$distribution"
else
    echo "Nerd Fonts are already installed."
fi

# Install SYSI script
echo "Installing SYSI script..."
sudo cp sysi /usr/local/bin/sysi
sudo chmod +x /usr/local/bin/sysi

echo "SYSI installation completed."
echo "You can now run 'sysi' to display system information."

hi zdislav,
is this an option?

#!/bin/bash

# get gpu & make lower case
GPU=$(lspci | grep -iE "vga")
GPU=$(echo $GPU | tr '[:upper:]' '[:lower:]')

# [TEST] output to check
echo "lspci output for vga device is: $GPU"
echo 
echo loop the device 

for indices in $GPU
    do
        # check gpu
        case $indices in

            [radeon)
                echo "string Radeon found."
                g="AMD Radeon"
                break
                ;;
            [amd/ati])
                echo "string AMD/ATI found."
                g="AMD ATI"
                break
                ;;
            intel)
                echo "i dont have a intel gpu, so please check the output from lspci"
                g="INTEL?"
                break
                ;;
            nvidia)
                echo "i dont have a nvidia gpu, so please check the output from lspci"
                g="NVIDIA?"
                break
                ;;
        esac
    done

echo "VGA Device: $g"

First get the vga-Device from the lspci-command and make all lowercase.
Then split the output into individual strings and use ‘case’ in the for loop to determine the individual string. On hit set an return and exit the loop.

so something like this

#!/bin/bash

# Function to check if a command exists
command_exists() {
    command -v "$1" &> /dev/null
}

# Function to install packages based on distribution
install_packages() {
    local distribution=$1
    shift
    local packages=("$@")

    case $distribution in
        debian|ubuntu)
            sudo apt update
            sudo apt install -y "${packages[@]}"
            ;;
        fedora)
            sudo dnf install -y "${packages[@]}"
            ;;
        arch|endeavouros|manjaro)
            sudo pacman -Syu --needed --noconfirm "${packages[@]}"
            ;;
        *)
            echo "Unsupported distribution: $distribution"
            exit 1
            ;;
    esac
}

# Determine the Linux distribution
get_distribution() {
    if command_exists lsb_release; then
        lsb_release -si | tr '[:upper:]' '[:lower:]'
    elif [ -e /etc/os-release ]; then
        source /etc/os-release
        echo "$ID" | tr '[:upper:]' '[:lower:]'
    else
        echo "unknown"
    fi
}

# Get GPU info and convert to lower case
GPU=$(lspci | grep -iE "vga")
GPU=$(echo $GPU | tr '[:upper:]' '[:lower:]')

# Output to check
echo "lspci output for VGA device is: $GPU"
echo 
echo "Looping through the device information"

# Loop through the GPU info to identify the GPU
for indices in $GPU; do
    case $indices in
        *radeon*)
            echo "String Radeon found."
            g="AMD Radeon"
            packages_to_install=("radeontop")
            break
            ;;
        *amd/ati*)
            echo "String AMD/ATI found."
            g="AMD ATI"
            packages_to_install=("radeontop")
            break
            ;;
        *intel*)
            echo "String Intel found."
            g="INTEL"
            packages_to_install=("intel-gpu-tools")
            break
            ;;
        *nvidia*)
            echo "String NVIDIA found."
            g="NVIDIA"
            packages_to_install=("nvidia-utils")
            break
            ;;
    esac
done

echo "VGA Device: $g"

# Check and install the required packages for the identified GPU
if [[ ${#packages_to_install[@]} -gt 0 ]]; then
    echo "Installing packages for $g: ${packages_to_install[*]}"
    distribution=$(get_distribution)
    install_packages "$distribution" "${packages_to_install[@]}"
else
    echo "No specific GPU packages to install."
fi

# Install Nerd Fonts
install_nerdfonts() {
    echo "Installing Nerd Fonts..."
    local distribution=$1
    case $distribution in
        debian|ubuntu)
            sudo apt install -y fonts-firacode
            ;;
        fedora)
            sudo dnf install -y fira-code-fonts
            ;;
        arch|endeavouros|manjaro)
            sudo pacman -S --noconfirm --needed ttf-fira-code
            ;;
        *)
            echo "Unsupported distribution: $distribution"
            exit 1
            ;;
    esac
}

# Check for and install Nerd Fonts
echo "Checking for Nerd Fonts..."
if ! fc-list : file family | grep -q "Nerd Font"; then
    distribution=$(get_distribution)
    install_nerdfonts "$distribution"
else
    echo "Nerd Fonts are already installed."
fi

# Install SYSI script
echo "Installing SYSI script..."
sudo cp sysi /usr/local/bin/sysi
sudo chmod +x /usr/local/bin/sysi

echo "SYSI installation completed."
echo "You can now run 'sysi' to display system information."

1 Like

my program is a “fetch script” you can check it out https://github.com/stuffbymax/sysi also thanks for the coments also if you check it pls give me feedback

Your program? Really?

sysi Script Overview made by AI

Shame on you.
Not only you offend humans, but you also make fun of them by asking help to improve a robot-made script, which already has stolen other humans’ code/effort and Licenses/Copyright etc.

If you continue this road, you will soon know only one language, the one to communicate with robots, until they see how weak you have become and blow you out in space!

Next time you ask for help, you have to clearly state that you are a robot slave and you act in the name of your Masters.

1 Like

Overview made by AI means that md file is made by ai

If you don’t mind the suggestion, you could make this distinction a little more obvious because I believe I noticed other folks confused by this same point on another thread.

If you break the comment about AI out of the actual title of the README, that should make it more clear. For example:

sysi Script

README written by AI

Description

The sysi is designed to provide blah blah blah…

3 Likes

besicaly you make the work

1 Like

should i add that is made by you

1 Like

No, I am happy for you to adopt that suggestion in any form you like without receiving any credit at all. :grinning:

It was only meant to be a small note, not a contribution to the project or anything. Although, it is admirable you are taking the matter of giving proper credit so seriously.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.