From 8e799dfab86d29ea4b5905f10e4c86ebe3257fd7 Mon Sep 17 00:00:00 2001 From: Taimoor Date: Tue, 13 Feb 2024 09:50:56 +0500 Subject: [PATCH 1/2] slight fix in scripts --- cidr2ip/deb.sh | 7 ++++++- cidr2range/deb.sh | 7 ++++++- grepdomain/deb.sh | 7 ++++++- grepip/deb.sh | 7 ++++++- ipinfo/deb.sh | 7 ++++++- matchip/deb.sh | 7 ++++++- prips/deb.sh | 7 ++++++- randip/deb.sh | 7 ++++++- range2cidr/deb.sh | 7 ++++++- range2ip/deb.sh | 7 ++++++- splitcidr/deb.sh | 7 ++++++- 11 files changed, 66 insertions(+), 11 deletions(-) diff --git a/cidr2ip/deb.sh b/cidr2ip/deb.sh index 80527892..5027a2fa 100755 --- a/cidr2ip/deb.sh +++ b/cidr2ip/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -23,7 +28,7 @@ case $ARCH in esac curl -LO https://github.com/ipinfo/cli/releases/download/cidr2ip-${VSN}/cidr2ip_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i cidr2ip_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i cidr2ip_${VSN}_linux_${ARCH_NAME}.deb rm cidr2ip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/cidr2range/deb.sh b/cidr2range/deb.sh index 01b87450..d5a33381 100755 --- a/cidr2range/deb.sh +++ b/cidr2range/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.2.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/cidr2range-${VSN}/cidr2range_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i cidr2range_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i cidr2range_${VSN}_linux_${ARCH_NAME}.deb rm cidr2range_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/grepdomain/deb.sh b/grepdomain/deb.sh index 39ee8121..40edb5bd 100755 --- a/grepdomain/deb.sh +++ b/grepdomain/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/grepdomain-${VSN}/grepdomain_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i grepdomain_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i grepdomain_${VSN}_linux_${ARCH_NAME}.deb rm grepdomain_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/grepip/deb.sh b/grepip/deb.sh index 4da5d4ac..4dd2752d 100755 --- a/grepip/deb.sh +++ b/grepip/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.2.3 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/grepip-${VSN}/grepip_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i grepip_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i grepip_${VSN}_linux_${ARCH_NAME}.deb rm grepip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/ipinfo/deb.sh b/ipinfo/deb.sh index 95676d76..58b32d53 100755 --- a/ipinfo/deb.sh +++ b/ipinfo/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=3.3.0 DEFAULT_ARCH=amd64 @@ -23,7 +28,7 @@ case $ARCH in esac curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-${VSN}/ipinfo_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i ipinfo_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i ipinfo_${VSN}_linux_${ARCH_NAME}.deb rm ipinfo_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/matchip/deb.sh b/matchip/deb.sh index 5920a31d..5eb4147e 100755 --- a/matchip/deb.sh +++ b/matchip/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/matchip-${VSN}/matchip_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i matchip_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i matchip_${VSN}_linux_${ARCH_NAME}.deb rm matchip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/prips/deb.sh b/prips/deb.sh index ef931706..93371c52 100755 --- a/prips/deb.sh +++ b/prips/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/prips-${VSN}/prips_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i prips_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i prips_${VSN}_linux_${ARCH_NAME}.deb rm prips_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/randip/deb.sh b/randip/deb.sh index ef74a235..c47ef70f 100755 --- a/randip/deb.sh +++ b/randip/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.1.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/randip-${VSN}/randip_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i randip_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i randip_${VSN}_linux_${ARCH_NAME}.deb rm randip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/range2cidr/deb.sh b/range2cidr/deb.sh index b4d797b3..9500f125 100755 --- a/range2cidr/deb.sh +++ b/range2cidr/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.3.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/range2cidr-${VSN}/range2cidr_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i range2cidr_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i range2cidr_${VSN}_linux_${ARCH_NAME}.deb rm range2cidr_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/range2ip/deb.sh b/range2ip/deb.sh index 12286e53..32667ffe 100755 --- a/range2ip/deb.sh +++ b/range2ip/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/range2ip-${VSN}/range2ip_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i range2ip_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i range2ip_${VSN}_linux_${ARCH_NAME}.deb rm range2ip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/splitcidr/deb.sh b/splitcidr/deb.sh index a71fae94..e263eced 100755 --- a/splitcidr/deb.sh +++ b/splitcidr/deb.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$(id -u)" -ne 0 ]; then + echo "This script requires root privileges. Please run it as root or with sudo." >&2 + exit 1 +fi + VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -22,7 +27,7 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/splitcidr-${VSN}/splitcidr_${VSN}_linux_${ARCH_NAME}.deb -sudo dpkg -i splitcidr_${VSN}_linux_${ARCH_NAME}.deb +dpkg -i splitcidr_${VSN}_linux_${ARCH_NAME}.deb rm splitcidr_${VSN}_linux_${ARCH_NAME}.deb echo From ba9dd2680319de926344b9163b00b4b5352874b1 Mon Sep 17 00:00:00 2001 From: Taimoor Date: Tue, 13 Feb 2024 11:47:12 +0500 Subject: [PATCH 2/2] using sudo command if it exists --- cidr2ip/deb.sh | 11 +++++------ cidr2range/deb.sh | 11 +++++------ grepdomain/deb.sh | 11 +++++------ grepip/deb.sh | 11 +++++------ ipinfo/deb.sh | 11 +++++------ matchip/deb.sh | 11 +++++------ prips/deb.sh | 11 +++++------ randip/deb.sh | 11 +++++------ range2cidr/deb.sh | 11 +++++------ range2ip/deb.sh | 11 +++++------ splitcidr/deb.sh | 11 +++++------ 11 files changed, 55 insertions(+), 66 deletions(-) diff --git a/cidr2ip/deb.sh b/cidr2ip/deb.sh index 5027a2fa..57bda0ef 100755 --- a/cidr2ip/deb.sh +++ b/cidr2ip/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -28,7 +23,11 @@ case $ARCH in esac curl -LO https://github.com/ipinfo/cli/releases/download/cidr2ip-${VSN}/cidr2ip_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i cidr2ip_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i cidr2ip_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i cidr2ip_${VSN}_linux_${ARCH_NAME}.deb +fi rm cidr2ip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/cidr2range/deb.sh b/cidr2range/deb.sh index d5a33381..cab50eb1 100755 --- a/cidr2range/deb.sh +++ b/cidr2range/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.2.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/cidr2range-${VSN}/cidr2range_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i cidr2range_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i cidr2range_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i cidr2range_${VSN}_linux_${ARCH_NAME}.deb +fi rm cidr2range_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/grepdomain/deb.sh b/grepdomain/deb.sh index 40edb5bd..9a7bfa66 100755 --- a/grepdomain/deb.sh +++ b/grepdomain/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/grepdomain-${VSN}/grepdomain_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i grepdomain_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i grepdomain_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i grepdomain_${VSN}_linux_${ARCH_NAME}.deb +fi rm grepdomain_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/grepip/deb.sh b/grepip/deb.sh index 4dd2752d..abe9069a 100755 --- a/grepip/deb.sh +++ b/grepip/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.2.3 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/grepip-${VSN}/grepip_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i grepip_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i grepip_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i grepip_${VSN}_linux_${ARCH_NAME}.deb +fi rm grepip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/ipinfo/deb.sh b/ipinfo/deb.sh index 58b32d53..60c35d69 100755 --- a/ipinfo/deb.sh +++ b/ipinfo/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=3.3.0 DEFAULT_ARCH=amd64 @@ -28,7 +23,11 @@ case $ARCH in esac curl -LO https://github.com/ipinfo/cli/releases/download/ipinfo-${VSN}/ipinfo_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i ipinfo_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i ipinfo_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i ipinfo_${VSN}_linux_${ARCH_NAME}.deb +fi rm ipinfo_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/matchip/deb.sh b/matchip/deb.sh index 5eb4147e..262c5bd6 100755 --- a/matchip/deb.sh +++ b/matchip/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/matchip-${VSN}/matchip_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i matchip_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i matchip_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i matchip_${VSN}_linux_${ARCH_NAME}.deb +fi rm matchip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/prips/deb.sh b/prips/deb.sh index 93371c52..33299a77 100755 --- a/prips/deb.sh +++ b/prips/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/prips-${VSN}/prips_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i prips_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i prips_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i prips_${VSN}_linux_${ARCH_NAME}.deb +fi rm prips_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/randip/deb.sh b/randip/deb.sh index c47ef70f..85c69cf2 100755 --- a/randip/deb.sh +++ b/randip/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.1.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/randip-${VSN}/randip_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i randip_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i randip_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i randip_${VSN}_linux_${ARCH_NAME}.deb +fi rm randip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/range2cidr/deb.sh b/range2cidr/deb.sh index 9500f125..bcca1131 100755 --- a/range2cidr/deb.sh +++ b/range2cidr/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.3.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/range2cidr-${VSN}/range2cidr_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i range2cidr_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i range2cidr_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i range2cidr_${VSN}_linux_${ARCH_NAME}.deb +fi rm range2cidr_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/range2ip/deb.sh b/range2ip/deb.sh index 32667ffe..7bad2d3b 100755 --- a/range2ip/deb.sh +++ b/range2ip/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/range2ip-${VSN}/range2ip_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i range2ip_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i range2ip_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i range2ip_${VSN}_linux_${ARCH_NAME}.deb +fi rm range2ip_${VSN}_linux_${ARCH_NAME}.deb echo diff --git a/splitcidr/deb.sh b/splitcidr/deb.sh index e263eced..39f64bce 100755 --- a/splitcidr/deb.sh +++ b/splitcidr/deb.sh @@ -1,10 +1,5 @@ #!/bin/sh -if [ "$(id -u)" -ne 0 ]; then - echo "This script requires root privileges. Please run it as root or with sudo." >&2 - exit 1 -fi - VSN=1.0.0 DEFAULT_ARCH=amd64 @@ -27,7 +22,11 @@ case $ARCH in ;; esac curl -LO https://github.com/ipinfo/cli/releases/download/splitcidr-${VSN}/splitcidr_${VSN}_linux_${ARCH_NAME}.deb -dpkg -i splitcidr_${VSN}_linux_${ARCH_NAME}.deb +if command -v sudo >/dev/null 2>&1; then + sudo dpkg -i splitcidr_${VSN}_linux_${ARCH_NAME}.deb +else + dpkg -i splitcidr_${VSN}_linux_${ARCH_NAME}.deb +fi rm splitcidr_${VSN}_linux_${ARCH_NAME}.deb echo