Build a Check script for PRE package install

I am once again using openSUSE. I have been using other distros over the years, but I digress.

I have installed openSUSE on a dell computer - all is fine. I went to install Davinci Resolve - all is good I have it up and running.

BUT with all of the dependency’s I would like to build a precheck script to help others install Davinci resolve.

My question: How / Where do I start to build a script to check on install issues - Pre-install stuff that Davinci Resolve wants to see?
I am just looking for pointers of where to start.

or am I on to the correct way by using this script, or is there a better way?

#!/bin/bash

# Function to check if a specific package is installed
check_package() {
    local package_name=$1
    if zypper se -i "$package_name" &>/dev/null; then
        echo "Package '$package_name' is installed."
    else
        echo "Package '$package_name' is NOT installed."
    fi
}

# List all installed packages
list_installed_packages() {
    echo "Listing all installed packages:"
    zypper se -i
}

# Main script logic
echo "OpenSUSE Package Checker"

if [[ $1 == "list" ]]; then
    list_installed_packages
elif [[ $1 == "check" ]]; then
    if [[ -z $2 ]]; then
        echo "Usage: $0 check <package_name>"
    else
        check_package "$2"
    fi
else
    echo "Usage:"
    echo "  $0 list                  - List all installed packages"
    echo "  $0 check <package_name>  - Check if a specific package is installed"
fi

Thank You

You can also use zypper in -f package1 package2 ..........

-f will reinstall a package if installed…

Did you ever try this out?

boven:~ # zypper se -i repo
Loading repository data...
Reading installed packages...

S  | Name                          | Summary                                           | Type
---+-------------------------------+---------------------------------------------------+--------
i  | girepository-1_0              | Base GObject Introspection Bindings               | package
i  | libgirepository-1_0-1         | GObject Introspection Library                     | package
i  | libpcreposix0                 | A library for Perl-compatible regular expressions | package
i  | librepository                 | Hierarchical repository abstraction layer         | package
i  | pentaho-reporting-flow-engine | Pentaho Flow Reporting Engine                     | package
i  | python3-reportlab             | The Reportlab Toolkit                             | package

    Note: For an extended search including not yet activated remote resources please use 'zypper
    search-packages'.
boven:~ # 

Thus many installed packages may be found, but not the package with name repo .

Thanks for the Replies:
Looking to build a script that when run will check/install packages that are required by Davinci Resolve. Pre Check - I guess?

looking at doing something I have have never completed before. I think I have it, just not sure if there is a better way.


# Predefined list of packages to check
PREDEFINED_PACKAGES=("libapr1" "libOpenCL" "libpango-1.0")

# Function to check openSUSE version
check_opensuse_version() {
    if [[ -f /etc/os-release ]]; then
        local version_info
        version_info=$(grep -E '^PRETTY_NAME=' /etc/os-release | cut -d= -f2 | tr -d '"')
        echo "🖥️ Running on: $version_info"
    else
        echo "⚠️ Unable to determine the openSUSE version. File '/etc/os-release' is missing."
    fi
}

# Function to check if a specific package is installed
check_package() {
    local package_name=$1
    local package_info

    # Search for the package in the installed list
    package_info=$(zypper se -i "$package_name" 2>/dev/null | grep "^i" | awk '{print $3}')
    if [[ -n $package_info ]]; then
        echo "✅ Package '$package_name' is installed (version: $package_info)."
    else
        # Check if the package is available in the repository
        if zypper se "$package_name" &>/dev/null; then
            echo "⚠️ Package '$package_name' is NOT installed but is available in the repository."
        else
            echo "❌ Package '$package_name' is NOT installed and not available in the repository."
        fi
    fi
}

# Function to check predefined packages
check_predefined_packages() {
    echo "Checking the status of predefined packages:"
    for pkg in "${PREDEFINED_PACKAGES[@]}"; do
        echo "----------------------------------"
        check_package "$pkg"
    done
}

# Function to check multiple packages provided by the user
check_multiple_packages() {
    local packages=("$@")
    echo "Checking the status of specified packages:"
    for pkg in "${packages[@]}"; do
        echo "----------------------------------"
        check_package "$pkg"
    done
}

# Function to list all installed packages
list_installed_packages() {
    echo "Listing all installed packages:"
    zypper se -i | grep "^i" | awk '{print $3}'
}

# Main script logic
echo "🔍 OpenSUSE Package Checker"

# Check and display the openSUSE version
check_opensuse_version
echo

if [[ $1 == "list" ]]; then
    list_installed_packages
elif [[ $1 == "check" ]]; then
    if [[ -z $2 ]]; then
        check_predefined_packages
    else
        shift
        check_multiple_packages "$@"
    fi
else
    echo "Usage:"
    echo "  $0 list                          - List all installed packages"
    echo "  $0 check                         - Check the status of predefined packages"
    echo "  $0 check  [...]   - Check the status of specific packages"
fi

type or paste code here

type or paste code here

You can use one command for installing all packages:
zypper install -f package1 packages2 package3 package4…

The -f --force is the important parameter.
If package2 is installed, it will be reinstalled.
So use all dependcies and it will work.

Its easier to install with one command as writing a script for searching, comparing, installing and errors…