Skip to content

Commit

Permalink
fix: ensure package function
Browse files Browse the repository at this point in the history
  • Loading branch information
okaufmann committed Feb 27, 2024
1 parent 262e902 commit d0ed0e1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions shell/.functions
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env bash

function ensurePackage() {
if ! command -v "$1" &> /dev/null
then
echo "Installing $1"
sudo apt-get install "$1" -y
local commandName="$1"
local packageName="${2:-$commandName}"

if ! command -v "$commandName" &> /dev/null; then
echo "Installing $packageName"
sudo apt-get install "$packageName" -y
fi
}

Expand All @@ -20,7 +22,7 @@ function updateDotfiles() {
}

function ips() {
ensurePackage dnsutils
ensurePackage dns dnsutils

nameservers=(8.8.8.8 8.8.4.4 1.1.1.1 195.129.12.122 192.76.144.66 158.43.240.3 77.88.8.8)
type=${2:-A}
Expand All @@ -33,13 +35,13 @@ function ips() {
}

function wholisten() {
ensurePackage net-tools
ensurePackage netstat net-tools

sudo netstat -ltnp | grep ":$1"
}

function ports() {
ensurePackage net-tools
ensurePackage netstat net-tools

sudo netstat -ltnp
}
Expand All @@ -52,7 +54,7 @@ function mkd() {

# All the dig info
function digga() {
ensurePackage dnsutils
ensurePackage dig dnsutils

type=${2:-A}
dig +nocmd "$1" "$type" +multiline +noall +answer
Expand Down

0 comments on commit d0ed0e1

Please sign in to comment.