-
-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·118 lines (95 loc) · 2.77 KB
/
install.sh
File metadata and controls
executable file
·118 lines (95 loc) · 2.77 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
set -e
# This is an installation script for the Harbor project.
# See https://github.com/av/harbor for more information.
# ========================================
HARBOR_INSTALL_PATH="${HOME}/.harbor"
HARBOR_REPO_URL="https://github.com/av/harbor.git"
HARBOR_RELEASE_URL="https://api.github.com/repos/av/harbor/releases/latest"
HARBOR_REQUIREMENTS_URL="https://raw.githubusercontent.com/av/harbor/refs/heads/main/requirements.sh"
HARBOR_VERSION=""
INSTALL_REQUIREMENTS=false
# ========================================
resolve_harbor_version() {
curl -s "$HARBOR_RELEASE_URL" | sed -n 's/.*"tag_name": "\(.*\)".*/\1/p'
}
print_help() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Install Harbor from the latest release.
Run with options from a pipe as: bash -s -- [OPTIONS]
Options:
--install-requirements Run remote requirements installer before dependency checks
-h, --help Show this help message and exit
EOF
}
parse_args() {
while [ "$#" -gt 0 ]; do
case "$1" in
--install-requirements|--hands-off)
INSTALL_REQUIREMENTS=true
;;
-h|--help)
print_help
exit 0
;;
*)
echo "Error: Unknown option: $1"
echo
print_help
exit 1
;;
esac
shift
done
}
check_dependencies() {
if ! command -v docker >/dev/null 2>&1 || ! command -v git >/dev/null 2>&1; then
echo "Error: Docker or Git not found. Please install missing dependencies."
exit 1
fi
}
install_or_update_project() {
if [ -d "$HARBOR_INSTALL_PATH" ]; then
echo "Existing installation found. Updating..."
cd "$HARBOR_INSTALL_PATH"
git fetch --all --tags
git checkout "tags/$HARBOR_VERSION"
else
echo "Cloning project repository..."
git clone --depth 1 --branch "$HARBOR_VERSION" "$HARBOR_REPO_URL" "$HARBOR_INSTALL_PATH"
cd "$HARBOR_INSTALL_PATH"
fi
}
main() {
parse_args "$@"
echo "Installing Harbor."
if [ "$INSTALL_REQUIREMENTS" = true ]; then
echo "Installing requirements..."
if ! (set -o pipefail; curl -fsSL "$HARBOR_REQUIREMENTS_URL" | bash); then
echo "Error: Failed to download or execute requirements installer from $HARBOR_REQUIREMENTS_URL"
exit 1
fi
fi
echo "Checking dependencies..."
check_dependencies
echo "Resolving version..."
HARBOR_VERSION=$(resolve_harbor_version)
if [ -z "$HARBOR_VERSION" ]; then
echo "Error: Unable to resolve Harbor version."
exit 1
else
echo "Resolved Harbor version: $HARBOR_VERSION"
fi
echo "Starting installation..."
install_or_update_project
./harbor.sh -v
./harbor.sh ln
if [ "$INSTALL_REQUIREMENTS" = true ]; then
echo "Running post-install requirements check..."
newgrp docker
./harbor.sh doctor
fi
echo "Installation complete."
}
main "$@"