uptime-kuma/install.sh

229 lines
7.0 KiB
Bash
Raw Normal View History

2021-08-18 02:55:03 -04:00
# install.sh is generated by ./extra/install.batsh, do not modify it directly.
# "npm run compile-install-script" to compile install.sh
# The command is working on Windows PowerShell and Docker for Windows only.
2021-08-19 00:39:51 -04:00
# curl -o kuma_install.sh https://raw.githubusercontent.com/louislam/uptime-kuma/master/install.sh && sudo bash kuma_install.sh
2021-08-17 11:08:35 -04:00
"echo" "-e" "====================="
2023-07-21 04:09:35 -04:00
"echo" "-e" "Uptime Kuma Install Script"
2021-08-17 11:08:35 -04:00
"echo" "-e" "====================="
2023-07-21 04:09:35 -04:00
"echo" "-e" "Supported OS: Ubuntu >= 16.04, Debian and CentOS/RHEL 7/8"
2021-08-17 11:08:35 -04:00
"echo" "-e" "---------------------------------------"
"echo" "-e" "This script is designed for Linux and basic usage."
"echo" "-e" "For advanced usage, please go to https://github.com/louislam/uptime-kuma/wiki/Installation"
"echo" "-e" "---------------------------------------"
"echo" "-e" ""
2023-07-21 04:09:35 -04:00
"echo" "-e" "Local - Install Uptime Kuma on your current machine with git, Node.js and pm2"
2021-08-17 11:08:35 -04:00
"echo" "-e" "Docker - Install Uptime Kuma Docker container"
"echo" "-e" ""
if [ "$1" != "" ]; then
type="$1"
else
"read" "-p" "Which installation method do you prefer? [DOCKER/local]: " "type"
fi
2021-08-18 14:04:49 -04:00
defaultPort="3001"
function checkNode {
local _0
nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')
"echo" "-e" "Node Version: ""$nodeVersion"
_0="12"
2023-07-21 04:09:35 -04:00
if [ $(($nodeVersion <= $_0)) == 1 ]; then
2021-08-18 14:04:49 -04:00
"echo" "-e" "Error: Required Node.js 14"
"exit" "1"
fi
}
function deb {
nodeCheck=$(node -v)
apt --yes update
if [ "$nodeCheck" != "" ]; then
"checkNode"
else
# Old nodejs binary name is "nodejs"
check=$(nodejs --version)
if [ "$check" != "" ]; then
"echo" "-e" "Error: 'node' command is not found, but 'nodejs' command is found. Your NodeJS should be too old."
exit 1
fi
curlCheck=$(curl --version)
if [ "$curlCheck" == "" ]; then
"echo" "-e" "Installing Curl"
apt --yes install curl
fi
2023-07-21 04:09:35 -04:00
"echo" "-e" "Installing Node.js 16"
curl -sL https://deb.nodesource.com/setup_16.x | bash - > log.txt
2021-08-18 14:04:49 -04:00
apt --yes install nodejs
node -v
nodeCheckAgain=$(node -v)
if [ "$nodeCheckAgain" == "" ]; then
"echo" "-e" "Error during Node.js installation"
exit 1
fi
fi
check=$(git --version)
if [ "$check" == "" ]; then
"echo" "-e" "Installing Git"
apt --yes install git
fi
}
2021-08-17 11:08:35 -04:00
if [ "$type" == "local" ]; then
2021-08-18 02:55:03 -04:00
defaultInstallPath="/opt/uptime-kuma"
2021-08-17 11:08:35 -04:00
if [ -e "/etc/redhat-release" ]; then
os=$("cat" "/etc/redhat-release")
2021-08-18 02:55:03 -04:00
distribution="rhel"
else
if [ -e "/etc/issue" ]; then
os=$(head -n1 /etc/issue | cut -f 1 -d ' ')
if [ "$os" == "Ubuntu" ]; then
2023-07-21 04:09:35 -04:00
distribution="ubuntu"
# Get ubuntu version
. /etc/lsb-release
version="$DISTRIB_RELEASE"
2021-08-18 14:04:49 -04:00
fi
if [ "$os" == "Debian" ]; then
distribution="debian"
2021-08-18 02:55:03 -04:00
fi
2021-08-17 11:08:35 -04:00
fi
2021-08-18 02:55:03 -04:00
fi
2021-08-17 11:08:35 -04:00
arch=$(uname -i)
"echo" "-e" "Your OS: ""$os"
"echo" "-e" "Distribution: ""$distribution"
2023-07-21 04:09:35 -04:00
"echo" "-e" "Version: ""$version"
2021-08-17 11:08:35 -04:00
"echo" "-e" "Arch: ""$arch"
2021-08-18 02:55:03 -04:00
if [ "$3" != "" ]; then
port="$3"
else
2021-08-18 14:38:45 -04:00
"read" "-p" "Listening Port [$defaultPort]: " "port"
2021-08-18 02:55:03 -04:00
if [ "$port" == "" ]; then
port="$defaultPort"
fi
fi
if [ "$2" != "" ]; then
installPath="$2"
else
2021-08-18 14:38:45 -04:00
"read" "-p" "Installation Path [$defaultInstallPath]: " "installPath"
2021-08-18 02:55:03 -04:00
if [ "$installPath" == "" ]; then
installPath="$defaultInstallPath"
fi
fi
2021-08-18 14:04:49 -04:00
# CentOS
2021-08-17 11:08:35 -04:00
if [ "$distribution" == "rhel" ]; then
2021-08-18 02:55:03 -04:00
nodeCheck=$(node -v)
if [ "$nodeCheck" != "" ]; then
2021-08-18 14:04:49 -04:00
"checkNode"
2021-08-17 11:08:35 -04:00
else
2023-07-21 04:09:35 -04:00
dnfCheck=$(dnf --version)
# Use yum
if [ "$dnfCheck" == "" ]; then
curlCheck=$(curl --version)
if [ "$curlCheck" == "" ]; then
"echo" "-e" "Installing Curl"
yum -y -q install curl
fi
"echo" "-e" "Installing Node.js 16"
curl -sL https://rpm.nodesource.com/setup_16.x | bash - > log.txt
yum install -y -q nodejs
else
curlCheck=$(curl --version)
if [ "$curlCheck" == "" ]; then
"echo" "-e" "Installing Curl"
dnf -y install curl
fi
"echo" "-e" "Installing Node.js 16"
curl -sL https://rpm.nodesource.com/setup_16.x | bash - > log.txt
dnf install -y nodejs
fi
2021-08-18 02:55:03 -04:00
node -v
nodeCheckAgain=$(node -v)
if [ "$nodeCheckAgain" == "" ]; then
"echo" "-e" "Error during Node.js installation"
exit 1
fi
2021-08-17 11:08:35 -04:00
fi
2021-08-18 02:55:03 -04:00
check=$(git --version)
if [ "$check" == "" ]; then
"echo" "-e" "Installing Git"
yum -y -q install git
fi
2021-08-18 14:04:49 -04:00
# Ubuntu
else
if [ "$distribution" == "ubuntu" ]; then
"deb"
# Debian
else
if [ "$distribution" == "debian" ]; then
"deb"
else
# Unknown distribution
error=$((0))
check=$(git --version)
if [ "$check" == "" ]; then
error=$((1))
"echo" "-e" "Error: git is not found!"
"echo" "-e" "help: an installation guide is available at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"
2021-08-18 02:55:03 -04:00
fi
2021-08-18 14:04:49 -04:00
check=$(node -v)
if [ "$check" == "" ]; then
error=$((1))
"echo" "-e" "Error: node is not found"
"echo" "-e" "help: an installation guide is available at https://nodejs.org/en/download"
2021-08-18 02:55:03 -04:00
fi
2021-08-18 14:04:49 -04:00
if [ $(($error > 0)) == 1 ]; then
"echo" "-e" "Please install above missing software"
exit 1
2021-08-17 11:08:35 -04:00
fi
2021-08-18 14:04:49 -04:00
fi
fi
fi
check=$(pm2 --version)
if [ "$check" == "" ]; then
"echo" "-e" "Installing PM2"
2022-03-22 23:17:23 -04:00
npm install pm2 -g && pm2 install pm2-logrotate
2021-08-18 14:04:49 -04:00
pm2 startup
2023-07-21 04:09:35 -04:00
fi
# Check again
check=$(pm2 --version)
if [ "$check" == "" ]; then
"echo" "-e" "Error: pm2 is not found!"
"echo" "-e" "help: an installation guide is available at https://pm2.keymetrics.io/docs/usage/quick-start/"
2023-07-21 04:09:35 -04:00
exit 1
2021-08-18 14:04:49 -04:00
fi
mkdir -p $installPath
cd $installPath
git clone https://github.com/louislam/uptime-kuma.git .
npm run setup
pm2 start server/server.js --name uptime-kuma -- --port=$port
2021-08-17 11:08:35 -04:00
else
2021-08-18 14:04:49 -04:00
defaultVolume="uptime-kuma"
check=$(docker -v)
if [ "$check" == "" ]; then
"echo" "-e" "Error: docker is not found!"
"echo" "-e" "help: an installation guide is available at https://docs.docker.com/desktop/"
2021-08-18 14:04:49 -04:00
exit 1
2021-08-19 00:15:07 -04:00
fi
check=$(docker info)
2021-08-19 00:47:11 -04:00
if [[ "$check" == *"Is the docker daemon running"* ]]; then
2021-09-01 02:56:19 -04:00
"echo" "Error: docker is not running"
"echo" "help: a troubleshooting guide is available at https://docs.docker.com/config/daemon/troubleshoot/"
2021-09-01 02:56:19 -04:00
"exit" "1"
2021-08-19 00:39:51 -04:00
fi
2021-08-18 14:04:49 -04:00
if [ "$3" != "" ]; then
port="$3"
else
2021-08-18 14:38:45 -04:00
"read" "-p" "Expose Port [$defaultPort]: " "port"
2021-08-18 14:04:49 -04:00
if [ "$port" == "" ]; then
port="$defaultPort"
fi
fi
if [ "$2" != "" ]; then
volume="$2"
else
"read" "-p" "Volume Name [$defaultVolume]: " "volume"
if [ "$volume" == "" ]; then
volume="$defaultVolume"
fi
fi
"echo" "-e" "Port: $port"
"echo" "-e" "Volume: $volume"
docker volume create $volume
docker run -d --restart=always -p $port:3001 -v $volume:/app/data --name uptime-kuma louislam/uptime-kuma:1
2021-08-17 11:08:35 -04:00
fi
2021-08-18 14:38:45 -04:00
"echo" "-e" "http://localhost:$port"