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)
|
|
|
|
export DATABASE_PASSWORD=$DATABASE_PASSWORD.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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 "⚠️ You really need 8gb or more of memory to run this stack ⚠️"
|
|
|
|
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 docker-compose is installed and if docker-compose.yml is found then, stop the stack.
|
|
|
|
if [[ $(which docker-compose) ]]; then
|
2022-11-08 17:17:58 +00:00
|
|
|
if [ -f ./docker-compose.yml ]; then
|
|
|
|
sudo -E docker-compose -f docker-compose.yml stop || true
|
|
|
|
fi
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
GIT_REPO_URL=$(git config --get remote.origin.url)
|
2022-11-09 13:25:06 +00:00
|
|
|
|
|
|
|
if [[ $GIT_REPO_URL != *oneuptime* ]] # * is used for pattern matching
|
2022-11-08 15:24:58 +00:00
|
|
|
then
|
|
|
|
git clone https://github.com/OneUptime/oneuptime.git || true
|
|
|
|
cd oneuptime
|
|
|
|
fi
|
|
|
|
|
|
|
|
# try to clone - if folder is already there pull latest for that branch
|
|
|
|
git pull
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
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-11-08 16:22:19 +00:00
|
|
|
if [[ ! $(which gomplate) ]]; then
|
2022-11-08 18:49:13 +00:00
|
|
|
sudo npm install -g gomplate
|
2022-11-08 15:24:58 +00:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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-11-08 16:22:19 +00:00
|
|
|
cat config.env.temp | gomplate > config.env
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
for directory_name in $(find . -type d -maxdepth 1) ; do
|
|
|
|
if [ -f "$directory_name/.env.tpl" ]; then
|
|
|
|
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
|
|
|
|
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-11-08 16:22:19 +00:00
|
|
|
cat docker-compose.tpl.yml | gomplate > docker-compose.yml
|