forked from OneUptime/oneuptime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
184 lines (143 loc) · 5.04 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
#!/usr/bin/env bash
set -a
# Talk to the user
echo "Welcome to the OneUptime 🟢 Runner"
echo ""
echo ""
echo ""
echo "Please enter your sudo password now:"
sudo echo ""
echo "Thanks! 🙏"
echo ""
echo "Ok! We'll take it from here 🚀"
echo "Making sure any stack that might exist is stopped"
# If Mac
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ ! $(which brew) ]]; then
echo "Homebrew not installed. Please install homebrew and restart installer"
exit
fi
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DISTRIB=$(awk -F= '/^ID/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "ubuntu"* ]]; then
echo "Grabbing latest apt caches"
sudo apt-get update
elif [[ ${DISTRIB} = "debian"* ]]; then
echo "Grabbing latest apt caches"
sudo apt update
fi
fi
# clone oneuptime
echo "Installing OneUptime 🟢"
if [[ ! $(which git) ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DISTRIB=$(awk -F= '/^ID/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "ubuntu"* ]] || [[ ${DISTRIB} = "debian"* ]]; then
sudo apt install -y git curl
elif [[ ${DISTRIB} = "fedora"* ]] || [[ ${DISTRIB} = "almalinux"* ]] || [[ ${DISTRIB} = "rockylinux"* ]] || [[ ${DISTRIB} = "rhel"* ]]; then
sudo dnf install git curl -y
fi
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install git curl
fi
fi
if [[ $IS_DOCKER == "true" ]]
then
echo "This script should run in the docker container."
else
GIT_REPO_URL=$(git config --get remote.origin.url)
if [[ $GIT_REPO_URL != *oneuptime* ]] # * is used for pattern matching
then
git clone https://github.com/OneUptime/oneuptime.git || true
cd oneuptime
fi
fi
# if this script is not running in CI/CD
if [ -z "$CI_PIPELINE_ID" ]
then
if [[ $IS_DOCKER == "true" ]]
then
echo "Running in docker container. Skipping git pull."
else
git pull
fi
fi
cd ..
if [[ ! $(which node) && ! $(node --version) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Setting up NodeJS"
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
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
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install nodejs
fi
fi
if [[ ! $(which npm) ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DISTRIB=$(awk -F= '/^ID/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "ubuntu"* ]] || [[ ${DISTRIB} = "debian"* ]]; then
echo "Setting up NPM"
sudo apt-get install -y npm
elif [[ ${DISTRIB} = "fedora"* ]] || [[ ${DISTRIB} = "almalinux"* ]] || [[ ${DISTRIB} = "rockylinux"* ]] || [[ ${DISTRIB} = "rhel"* ]]; then
echo "Setting up NPM"
sudo dnf install -y npm
fi
fi
fi
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo "Setting up Docker"
sudo curl -sSL https://get.docker.com/ | sh
fi
# If docker still fails to install, then quit.
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo -e "Failed to install docker. Please install Docker manually here: https://docs.docker.com/install."
echo -e "Exiting the OneUptime installer."
exit
fi
# enable docker without sudo
sudo usermod -aG docker "${USER}" || true
if [[ ! $(which docker-compose) && ! $(docker compose --version) ]]; then
mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.12.2/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
docker compose version
fi
if [[ ! $(which gomplate) ]]; then
ARCHITECTURE=$(uname -m)
if [[ $ARCHITECTURE == "aarch64" ]]; then
ARCHITECTURE="arm64"
fi
if [[ $ARCHITECTURE == "x86_64" ]]; then
ARCHITECTURE="amd64"
fi
echo "ARCHITECTURE:"
echo "$(uname -s) $(uname -m)"
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/gomplate_$(uname -s)-$ARCHITECTURE
sudo chmod 755 /usr/local/bin/gomplate
fi
if [[ ! $(which ts-node) ]]; then
sudo npm install -g ts-node
fi
cd oneuptime
# Create .env file if it does not exist.
touch config.env
# Reload terminal with newly installed packages.
source ~/.bashrc
#Run a scirpt to merge config.env.tpl to config.env
node ./Scripts/Install/MergeEnvTemplate.js
# Load env values from config.env
export $(grep -v '^#' config.env | xargs)
# Write env vars in config files.
for directory_name in $(find . -maxdepth 1 -type d) ; do
if [ -f "$directory_name/Dockerfile.tpl" ]; then
cat $directory_name/Dockerfile.tpl | gomplate > $directory_name/Dockerfile
fi
done