-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·78 lines (65 loc) · 1.79 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·78 lines (65 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
#
# install.sh - installs the `ipdata` CLI (ipdata-bash)
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/IPDataInfo/ipdata-bash/main/install.sh | sh
# PREFIX=$HOME/.local curl -fsSL .../install.sh | sh
# ./install.sh --prefix /usr/local
set -euo pipefail
REPO="IPDataInfo/ipdata-bash"
RAW_URL="https://raw.githubusercontent.com/${REPO}/main/ipdata"
PREFIX="${PREFIX:-/usr/local}"
usage() {
cat <<'EOF'
install.sh - install the ipdata CLI
USAGE:
./install.sh [--prefix DIR]
ENVIRONMENT:
PREFIX install prefix (default: /usr/local), binary goes to $PREFIX/bin
EOF
}
while [[ "$#" -gt 0 ]]; do
case "$1" in
--prefix)
[[ "$#" -ge 2 ]] || { echo "install.sh: --prefix requires a value" >&2; exit 1; }
PREFIX="$2"
shift 2
;;
--prefix=*)
PREFIX="${1#--prefix=}"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "install.sh: unknown argument: $1" >&2
usage
exit 1
;;
esac
done
BIN_DIR="${PREFIX}/bin"
DEST="${BIN_DIR}/ipdata"
command -v curl >/dev/null 2>&1 || { echo "install.sh: curl is required" >&2; exit 1; }
mkdir -p "$BIN_DIR"
# If running from a local checkout (this script sits next to `ipdata`), copy
# the local file instead of re-downloading it.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
if [[ -f "${SCRIPT_DIR}/ipdata" ]]; then
cp "${SCRIPT_DIR}/ipdata" "$DEST"
else
curl -fsSL "$RAW_URL" -o "$DEST"
fi
chmod +x "$DEST"
echo "ipdata installed to ${DEST}"
case ":$PATH:" in
*":${BIN_DIR}:"*) ;;
*)
echo "warning: ${BIN_DIR} is not on your PATH. Add this to your shell profile:"
echo " export PATH=\"${BIN_DIR}:\$PATH\""
;;
esac
echo "Run 'ipdata help' to get started, or 'ipdata lookup' to look up your own IP."