uptime-kuma/extra/install.batsh

277 lines
7.8 KiB
Plaintext
Raw Normal View History

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