-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathconfigure.sh
211 lines (179 loc) · 6.48 KB
/
configure.sh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
# Exit on error, undefined variables, and pipe failures
set -euo pipefail
# Global variables
DOCKER_COMPOSE_VERSION="2.12.2"
GOMPLATE_VERSION="3.11.8"
MINIMUM_DOCKER_VERSION="20.0.0"
MINIMUM_NODE_VERSION="14.0.0"
NVM_VERSION="0.40.1"
REQUIRED_PACKAGES="git curl"
# Print with color
print_info() {
echo -e "\033[0;34m[INFO]\033[0m $1"
}
print_success() {
echo -e "\033[0;32m[SUCCESS]\033[0m $1"
}
print_error() {
echo -e "\033[0;31m[ERROR]\033[0m $1" >&2
}
# Check version meets minimum requirement
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install system packages based on OS
install_system_packages() {
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! command_exists brew; then
print_error "Homebrew not installed. Please install homebrew and restart installer"
exit 1
fi
brew install $REQUIRED_PACKAGES
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
local DISTRIB
DISTRIB=$(awk -F= '/^ID/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "ubuntu"* ]] || [[ ${DISTRIB} = "debian"* ]]; then
print_info "Updating package cache..."
sudo apt-get update
sudo apt-get install -y $REQUIRED_PACKAGES
elif [[ ${DISTRIB} = "fedora"* ]] || [[ ${DISTRIB} = "almalinux"* ]] || [[ ${DISTRIB} = "rockylinux"* ]] || [[ ${DISTRIB} = "rhel"* ]]; then
print_info "Updating package cache..."
sudo dnf install -y $REQUIRED_PACKAGES
else
print_error "Unsupported Linux distribution: $DISTRIB"
exit 1
fi
elif [[ "$OSTYPE" == "linux-musl"* ]]; then
local DISTRIB
DISTRIB=$(awk -F= '/^ID/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "alpine"* ]]; then
print_info "Updating package cache..."
sudo apk update
sudo apk add $REQUIRED_PACKAGES
else
print_error "Unsupported Linux distribution: $DISTRIB"
exit 1
fi
else
print_error "Unsupported operating system: $OSTYPE"
exit 1
fi
}
setup_nodejs() {
if ! command_exists node || ! command_exists npm; then
print_info "Installing Node.js..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install nodejs
else
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
# shellcheck disable=SC1090
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install lts/*
nvm use lts/*
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
fi
fi
# Verify Node.js version
local NODE_VERSION
NODE_VERSION=$(node --version | cut -d 'v' -f 2)
if ! version_gt "$NODE_VERSION" "$MINIMUM_NODE_VERSION"; then
print_error "Node.js version $NODE_VERSION is too old. Minimum required version is $MINIMUM_NODE_VERSION"
exit 1
fi
}
setup_docker() {
if ! command_exists docker; then
print_info "Installing Docker..."
sudo curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker "${USER}"
fi
# Verify Docker version
local DOCKER_VERSION
DOCKER_VERSION=$(docker --version | cut -d ' ' -f 3 | cut -d ',' -f 1)
if ! version_gt "$DOCKER_VERSION" "$MINIMUM_DOCKER_VERSION"; then
print_error "Docker version $DOCKER_VERSION is too old. Minimum required version is $MINIMUM_DOCKER_VERSION"
exit 1
fi
if ! command_exists docker-compose && ! docker compose version >/dev/null 2>&1; then
print_info "Installing Docker Compose..."
mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL "https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
fi
}
setup_gomplate() {
if ! command_exists gomplate; then
print_info "Installing gomplate..."
local ARCHITECTURE
ARCHITECTURE=$(uname -m)
case $ARCHITECTURE in
"aarch64") ARCHITECTURE="arm64" ;;
"x86_64") ARCHITECTURE="amd64" ;;
esac
sudo curl -o /usr/local/bin/gomplate -sSL \
"https://github.com/hairyhenderson/gomplate/releases/download/v${GOMPLATE_VERSION}/gomplate_$(uname -s)-$ARCHITECTURE"
sudo chmod 755 /usr/local/bin/gomplate
fi
}
clone_oneuptime() {
if [[ ${IS_DOCKER:-false} != "true" ]]; then
local GIT_REPO_URL
GIT_REPO_URL=$(git config --get remote.origin.url || echo "")
if [[ $GIT_REPO_URL != *oneuptime* ]]; then
print_info "Cloning OneUptime repository..."
git clone https://github.com/OneUptime/oneuptime.git || true
cd oneuptime
fi
# Update repository if not in CI/CD
if [ -z "${CI_PIPELINE_ID:-}" ]; then
git pull
fi
fi
}
setup_tsnode() {
if ! command_exists ts-node; then
print_info "Installing ts-node..."
sudo npm install -g ts-node
fi
}
# Main installation process
main() {
print_info "Welcome to the OneUptime 🟢 Runner"
echo ""
# Request sudo access upfront
print_info "Please enter your sudo password:"
sudo echo ""
print_success "Authentication successful! 🙏"
install_system_packages
setup_nodejs
setup_docker
setup_gomplate
setup_tsnode
clone_oneuptime
# Configure environment
touch config.env
print_info "Merging environment templates..."
node ./Scripts/Install/MergeEnvTemplate.js
# Load environment variables
# shellcheck disable=SC2046
export $(grep -v '^#' config.env | xargs)
print_info "Generating Dockerfile configurations..."
find . -maxdepth 1 -type d -exec sh -c '
for dir do
if [ -f "$dir/Dockerfile.tpl" ]; then
cat "$dir/Dockerfile.tpl" | gomplate > "$dir/Dockerfile"
fi
done
' sh {} +
print_success "OneUptime installation completed successfully! 🚀"
}
# Run main function
main