2022-11-08 15:24:58 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-11-08 16:22:19 +00:00
|
|
|
ONEUPTIME_SECRET=$(openssl rand -hex 12)
|
|
|
|
export ONEUPTIME_SECRET=$ONEUPTIME_SECRET
|
2022-11-08 15:24:58 +00:00
|
|
|
|
2022-11-08 16:22:19 +00:00
|
|
|
DATABASE_PASSWORD=$(openssl rand -hex 12)
|
2023-04-05 09:48:35 +00:00
|
|
|
export DATABASE_PASSWORD=$DATABASE_PASSWORD
|
2022-11-08 16:22:19 +00:00
|
|
|
|
2023-04-04 11:18:30 +00:00
|
|
|
CLICKHOUSE_PASSWORD=$(openssl rand -hex 12)
|
2023-04-05 09:48:35 +00:00
|
|
|
export CLICKHOUSE_PASSWORD=$CLICKHOUSE_PASSWORD
|
2023-04-04 11:18:30 +00:00
|
|
|
|
2022-11-08 16:22:19 +00:00
|
|
|
REDIS_PASSWORD=$(openssl rand -hex 12)
|
|
|
|
export REDIS_PASSWORD=$REDIS_PASSWORD
|
|
|
|
|
|
|
|
ENCRYPTION_SECRET=$(openssl rand -hex 12)
|
|
|
|
export ENCRYPTION_SECRET=$ENCRYPTION_SECRET
|
|
|
|
|
|
|
|
INTERNAL_SMTP_PASSWORD=$(openssl rand -hex 12)
|
|
|
|
export INTERNAL_SMTP_PASSWORD=$INTERNAL_SMTP_PASSWORD
|
2022-11-08 15:24:58 +00:00
|
|
|
|
2023-05-02 16:44:49 +00:00
|
|
|
GLOBAL_PROBE_1_KEY=$(openssl rand -hex 12)
|
|
|
|
export GLOBAL_PROBE_1_KEY=$GLOBAL_PROBE_1_KEY
|
|
|
|
|
|
|
|
GLOBAL_PROBE_2_KEY=$(openssl rand -hex 12)
|
|
|
|
export GLOBAL_PROBE_2_KEY=$GLOBAL_PROBE_2_KEY
|
|
|
|
|
|
|
|
GLOBAL_PROBE_3_KEY=$(openssl rand -hex 12)
|
|
|
|
export GLOBAL_PROBE_3_KEY=$GLOBAL_PROBE_3_KEY
|
|
|
|
|
2022-11-08 15:24:58 +00:00
|
|
|
# Talk to the user
|
2022-11-08 17:17:58 +00:00
|
|
|
echo "Welcome to the OneUptime 🟢 Runner"
|
2022-11-08 15:24:58 +00:00
|
|
|
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
|
2022-11-08 17:17:58 +00:00
|
|
|
if [[ ! $(which brew) ]]; then
|
|
|
|
echo "Homebrew not installed. Please install homebrew and restart installer"
|
|
|
|
exit
|
|
|
|
fi
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If linux
|
|
|
|
if [[ "$OSTYPE" != "darwin"* ]]; then
|
2022-11-08 17:17:58 +00:00
|
|
|
echo "Grabbing latest apt caches"
|
|
|
|
sudo apt update
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# clone oneuptime
|
|
|
|
echo "Installing OneUptime 🟢"
|
|
|
|
if [[ ! $(which git) ]]; then
|
2022-11-08 17:17:58 +00:00
|
|
|
if [[ "$OSTYPE" != "darwin"* ]]; then
|
|
|
|
sudo apt install -y git
|
|
|
|
fi
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
brew install git
|
|
|
|
fi
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-09 13:25:06 +00:00
|
|
|
|
2023-04-18 13:26:37 +00:00
|
|
|
if [[ $IS_DOCKER == "true" ]]
|
|
|
|
then
|
2023-04-18 13:20:14 +00:00
|
|
|
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
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-18 13:20:14 +00:00
|
|
|
|
|
|
|
|
2022-11-09 13:43:42 +00:00
|
|
|
# if this script is not running in CI/CD
|
|
|
|
if [ -z "$CI_PIPELINE_ID" ]
|
|
|
|
then
|
2023-04-18 13:56:58 +00:00
|
|
|
if [[ $IS_DOCKER == "true" ]]
|
|
|
|
then
|
|
|
|
echo "Running in docker container. Skipping git pull."
|
|
|
|
else
|
|
|
|
git pull
|
|
|
|
fi
|
2022-11-09 13:43:42 +00:00
|
|
|
fi
|
2022-11-08 15:24:58 +00:00
|
|
|
|
2022-11-09 14:51:19 +00:00
|
|
|
cd ..
|
|
|
|
|
2022-11-08 15:24:58 +00:00
|
|
|
if [[ ! $(which node) && ! $(node --version) ]]; then
|
|
|
|
if [[ "$OSTYPE" != "darwin"* ]]; then
|
|
|
|
echo "Setting up NodeJS"
|
|
|
|
sudo apt-get install -y nodejs
|
|
|
|
sudo apt-get install -y npm
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
brew install nodejs
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-12-30 13:19:45 +00:00
|
|
|
|
|
|
|
if [[ ! $(which npm) && ! $(npm --version) ]]; then
|
|
|
|
if [[ "$OSTYPE" != "darwin"* ]]; then
|
|
|
|
echo "Setting up NPM"
|
|
|
|
sudo apt-get install -y npm
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-11-09 18:23:01 +00:00
|
|
|
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
|
|
|
|
|
2022-12-07 07:49:18 +00:00
|
|
|
if [[ ! $(which docker-compose) && ! $(docker compose --version) ]]; then
|
2022-11-09 18:23:01 +00:00
|
|
|
mkdir -p /usr/local/lib/docker/cli-plugins
|
2022-12-07 07:49:18 +00:00
|
|
|
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
|
2022-11-09 18:23:01 +00:00
|
|
|
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
|
|
|
|
docker compose version
|
|
|
|
fi
|
|
|
|
|
2022-11-09 18:34:16 +00:00
|
|
|
if [[ ! $(which gomplate) ]]; then
|
2022-11-09 19:03:56 +00:00
|
|
|
ARCHITECTURE=$(uname -m)
|
|
|
|
|
2022-11-09 19:18:04 +00:00
|
|
|
if [[ $ARCHITECTURE == "aarch64" ]]; then
|
|
|
|
ARCHITECTURE="arm64"
|
2022-11-09 19:03:56 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-09 21:09:56 +00:00
|
|
|
if [[ $ARCHITECTURE == "x86_64" ]]; then
|
|
|
|
ARCHITECTURE="amd64"
|
|
|
|
fi
|
|
|
|
|
2022-11-09 21:05:46 +00:00
|
|
|
echo "ARCHITECTURE:"
|
|
|
|
echo "$(uname -s) $(uname -m)"
|
|
|
|
|
2022-11-09 19:20:42 +00:00
|
|
|
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/gomplate_$(uname -s)-$ARCHITECTURE
|
2022-11-09 18:36:26 +00:00
|
|
|
sudo chmod 755 /usr/local/bin/gomplate
|
2022-11-09 18:34:16 +00:00
|
|
|
fi
|
2022-11-08 15:24:58 +00:00
|
|
|
|
2022-11-09 19:13:41 +00:00
|
|
|
|
|
|
|
|
2022-11-09 12:53:55 +00:00
|
|
|
if [[ ! $(which ts-node) ]]; then
|
|
|
|
sudo npm install -g ts-node
|
|
|
|
fi
|
|
|
|
|
2022-11-08 15:24:58 +00:00
|
|
|
cd oneuptime
|
|
|
|
|
2022-12-06 08:04:15 +00:00
|
|
|
# Generate Self Signed SSL certificate.
|
|
|
|
|
2022-12-14 10:23:04 +00:00
|
|
|
CERT=./Certs/ServerCerts/Cert.crt
|
2022-12-06 08:04:15 +00:00
|
|
|
if test -f "$CERT"; then
|
|
|
|
echo "SSL Certificate exists. Skipping generating a new one."
|
|
|
|
else
|
|
|
|
echo "SSL Certificate not found. Generating a new certificate."
|
2023-01-02 11:31:50 +00:00
|
|
|
openssl req -new -x509 -nodes -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" -out ./Certs/ServerCerts/Cert.crt -keyout ./Certs/ServerCerts/Key.key -days 99999
|
2022-12-06 08:04:15 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-08 15:24:58 +00:00
|
|
|
# Create .env file if it does not exist.
|
|
|
|
touch config.env
|
|
|
|
|
|
|
|
#Run a scirpt to merge config.env.tpl to config.env
|
2022-11-09 12:53:55 +00:00
|
|
|
ts-node-esm ./Scripts/Install/MergeEnvTemplate.ts
|
2022-11-08 15:24:58 +00:00
|
|
|
|
2022-12-28 14:20:35 +00:00
|
|
|
cat config.env.temp | gomplate > config.env
|
2022-11-08 16:22:19 +00:00
|
|
|
|
2022-12-07 08:38:02 +00:00
|
|
|
|
2022-12-28 14:20:35 +00:00
|
|
|
rm config.env.temp
|
2022-11-08 15:24:58 +00:00
|
|
|
|
|
|
|
# Load env values from config.env
|
|
|
|
export $(grep -v '^#' config.env | xargs)
|
|
|
|
|
|
|
|
# Write env vars in config files.
|
|
|
|
|
2022-11-08 17:40:45 +00:00
|
|
|
|
2023-04-12 09:49:45 +00:00
|
|
|
for directory_name in $(find . -maxdepth 1 -type d) ; do
|
2022-11-08 17:40:45 +00:00
|
|
|
if [ -f "$directory_name/.env.tpl" ]; then
|
2022-12-28 14:20:35 +00:00
|
|
|
cat $directory_name/.env.tpl | gomplate > $directory_name/.env
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
2022-11-08 16:22:19 +00:00
|
|
|
|
2022-11-08 17:40:45 +00:00
|
|
|
if [ -f "$directory_name/Dockerfile.tpl" ]; then
|
2022-12-28 14:20:35 +00:00
|
|
|
cat $directory_name/Dockerfile.tpl | gomplate > $directory_name/Dockerfile
|
2022-11-08 17:19:49 +00:00
|
|
|
fi
|
|
|
|
done
|
2022-11-08 16:22:19 +00:00
|
|
|
|
2022-11-08 17:40:45 +00:00
|
|
|
# Convert template to docker-compose.
|
2022-12-28 14:20:35 +00:00
|
|
|
cat docker-compose.tpl.yml | gomplate > docker-compose.yml
|
2022-12-07 08:38:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Convert nginx conf template to nginx
|
2022-12-28 14:20:35 +00:00
|
|
|
cat ./Nginx/default.tpl.conf | gomplate > ./Nginx/default.conf
|