Skip to content

Commit

Permalink
Add error handling to dnf install commands
Browse files Browse the repository at this point in the history
  • Loading branch information
grdumas committed Dec 12, 2024
1 parent b83f983 commit 3fb2959
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

set -eu

# Check if script is being run as root
if (( $EUID == 0 )); then
read -p "For most use cases, running this script as root is NOT recommended. Are you sure? Y/N" yesno
Expand All @@ -39,9 +41,6 @@ packages=(ansible-core git jq python python3-pip terraform wget)
for package in "${packages[@]}"; do
if dnf list installed "$package" &> /dev/null; then
echo "$package is installed."
elif dnf list "$package" &> /dev/null; then
echo "$package is not installed but available. Installing..."
sudo dnf install -y "$package"
elif [ $package == "terraform" ]; then
# Add the terraform repository from HashiCorp
# currently supported distros: fedora, RHEL
Expand All @@ -67,10 +66,14 @@ for package in "${packages[@]}"; do
sudo dnf config-manager --add-repo $repo_url

# install the package
sudo dnf install terraform-1.9.8-1 -y
sudo dnf install terraform-1.9.8-1 -y || {
exit 1
}
else
echo "package $package is not installed and not available."
exit 1
echo "Installing $package..."
sudo dnf install -y "$package" || {
exit 1
}
fi

done
Expand Down

0 comments on commit 3fb2959

Please sign in to comment.