-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (77 loc) · 2.69 KB
/
install.sh
File metadata and controls
executable file
·95 lines (77 loc) · 2.69 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
if [ -z "${BASH_VERSION:-}" ]; then
# Fail fast if not bash (Use [] in case POSIX).
echo 'Bash is required to interpret this script.' >&2
echo 'Use: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jsware/utils/HEAD/install.sh)"' >&2
exit 1
fi
# Help text (check $0 also for /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jsware/utils/HEAD/install.sh)" --help)
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" || "${0:-}" == "--help" || "${1:-}" == "-h" ]]; then
cat <<:END
Install jsware/utils
Usage: install.sh [Options]
Options:
-h, --help Show this help.
-v, --verbose Verbose output.
-x, --debug Debug output.
-xx, --trace Trace output.
:END
exit 0
fi
set -o errexit -o errtrace -o nounset -o pipefail # Robust scripting (-euo pipefail)
origDir="$(pwd)"; cd -P "$(dirname "$0")"; scriptDir="$(pwd)"; scriptName="$(basename "$0")"; cd "$origDir" # Get the script directory
# Verbose logging
exec 3>/dev/null # Send verbose logging output to dev/null by default
# Exit with a message and exit code
die() {
local rc=$?
if [[ $rc > 0 ]]; then
echo "ERROR: ${*:-Aborting} (RC $rc)" >&2
else
echo "ERROR: ${*:-Aborting}" >&2
fi
exit $rc
}
# Parse arguments
args=("$@")
for ((arg=0;arg<${#args[@]};arg++)); do
opt="${args[$arg]:-}"
param="${args[$((arg+1))]:-}"
case "$opt" in
-v|--verbose) exec 3>&2;; # Send verbose output to stderr
-x|--debug) set -o verbose;;
-xx|--trace) set -o verbose
set -o xtrace;;
--) arg=$((arg+1))
break;;
-*) die "Invalid option '$opt' found. Try --help";;
*) break;; # End of options
esac
done
shift $arg
# Verify arguments
if [[ -n "${1:-}" ]]; then
die "Unexpected argument(s) '$*' found. Try --help."
fi
# Let's go!
echo "Installing jsware/utils..."
echo "Variables:" >&3
echo " Orig Dir: $origDir" >&3
echo " Script Dir: $scriptDir" >&3
echo " Script Name: $scriptName" >&3
if [[ -z "$(which git)" ]]; then
echo "Installing git..."
sudo apt-get install git -y >&3 || die "Failed to install git."
fi
gitURL="$(cd $scriptDir && git remote get-url origin 2>&1 || true)"
echo " Git URL: $gitURL" >&3
if [[ -n "$gitURL" && "$gitURL" == http* ]]; then
echo "Updating existing jsware/utils repository..."
cd "$scriptDir" || die "Failed to change directory to $scriptDir."
git pull || die "Failed to update existing jsware/utils repository."
else
echo "Cloning jsware/utils repository to $(pwd)..."
git clone https://github.com/jsware/utils.git || die "Failed to clone jsware/utils repository."
cd ./utils || die "Failed to change directory to ./utils after cloning it."
fi
echo "Installing jsware/utils complete."