Skip to content

Check if Package is Installed | if not then Install

Examples:

Bash
REQUIRED_PKG="pwgen"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
echo Checking for $REQUIRED_PKG: $PKG_OK
if [ "" = "$PKG_OK" ]; then
  echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG."
  sudo apt-get --yes install $REQUIRED_PKG
fi
Bash
if [ -f /usr/local/bin/aws ]; then
    echo "aws-cli is already installed!"
else
    echo "aws-cli is not not installed!"
    echo ""
    echo "Installing aws-cli now ..."
    echo ""

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
sudo rm -rf awscliv2.zip

# Adding AWS credentials (Optianal)

mkdir $HOME/.aws

cat > $HOME/.aws/config << EOF
[default]
region = eu-west-1
EOF

cat > $HOME/.aws/credentials << EOF
[default]
aws_access_key_id = xxxxxxxxxxxxxxx
aws_secret_access_key = rxxxRT0BxxxxxxxxxxxGwcxxxxxiHxxxrh
EOF

fi
Back to top