1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-20 20:11:39 +02:00

wip: implementing install script

This commit is contained in:
LouisLam 2021-08-19 02:04:49 +08:00
parent de4515ea6e
commit 61944d642e
8 changed files with 16330 additions and 6953 deletions

View File

@ -7,7 +7,7 @@ println("=====================");
println(""); println("");
println("---------------------------------------"); println("---------------------------------------");
println("This script is designed for Linux and basic usage."); println("This script is designed for Linux and basic usage.");
println("Tested with CentOS 7/8"); println("Supported OS: CentOS 7/8, Ubuntu >= 16.04 and Debian");
println("For advanced usage, please go to https://github.com/louislam/uptime-kuma/wiki/Installation"); println("For advanced usage, please go to https://github.com/louislam/uptime-kuma/wiki/Installation");
println("---------------------------------------"); println("---------------------------------------");
println(""); println("");
@ -21,8 +21,64 @@ if ("$1" != "") {
call("read", "-p", "Which installation method do you prefer? [DOCKER/local]: ", "type"); call("read", "-p", "Which installation method do you prefer? [DOCKER/local]: ", "type");
} }
defaultPort = "3001";
function checkNode() {
bash("nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')");
println("Node Version: " ++ nodeVersion);
if (nodeVersion < "12") {
println("Error: Required Node.js 14");
call("exit", "1");
}
if (nodeVersion == "12") {
println("Warning: NodeJS " ++ nodeVersion ++ " is not tested.");
}
}
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");
}
println("Installing Node.js 14");
bash("curl -sL https://deb.nodesource.com/setup_14.x | bash - > log.txt");
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");
}
}
if (type == "local") { if (type == "local") {
defaultPort = "3001";
defaultInstallPath = "/opt/uptime-kuma"; defaultInstallPath = "/opt/uptime-kuma";
if (exists("/etc/redhat-release")) { if (exists("/etc/redhat-release")) {
@ -34,7 +90,9 @@ if (type == "local") {
if (os == "Ubuntu") { if (os == "Ubuntu") {
distribution = "ubuntu"; distribution = "ubuntu";
} }
if (os == "Debian") {
distribution = "debian";
}
} }
bash("arch=$(uname -i)"); bash("arch=$(uname -i)");
@ -63,21 +121,12 @@ if (type == "local") {
} }
} }
// CentOS
if (distribution == "rhel") { if (distribution == "rhel") {
bash("nodeCheck=$(node -v)"); bash("nodeCheck=$(node -v)");
if (nodeCheck != "") { if (nodeCheck != "") {
bash("nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')"); checkNode();
println("Node Version: " ++ nodeVersion);
if (nodeVersion < "12") {
println("Error: Required Node.js 14");
call("exit", "1");
}
if (nodeVersion == "12") {
println("Warning: NodeJS " ++ nodeVersion ++ " is not tested.");
}
} else { } else {
bash("curlCheck=$(curl --version)"); bash("curlCheck=$(curl --version)");
@ -105,6 +154,36 @@ if (type == "local") {
bash("yum -y -q install git"); bash("yum -y -q install git");
} }
// Ubuntu
} else if (distribution == "ubuntu") {
deb();
// Debian
} else if (distribution == "debian") {
deb();
} else {
// Unknown distribution
error = 0;
bash("check=$(git --version)");
if (check == "") {
error = 1;
println("Error: git is missing");
}
bash("check=$(node -v)");
if (check == "") {
error = 1;
println("Error: node is missing");
}
if (error > 0) {
println("Please install above missing software");
bash("exit 1");
}
}
bash("check=$(pm2 --version)"); bash("check=$(pm2 --version)");
if (check == "") { if (check == "") {
println("Installing PM2"); println("Installing PM2");
@ -118,15 +197,38 @@ if (type == "local") {
bash("npm run setup"); bash("npm run setup");
bash("pm2 start npm --name uptime-kuma -- run start-server -- --port=$port"); bash("pm2 start npm --name uptime-kuma -- run start-server -- --port=$port");
bash("pm2 list");
}
if (distribution == "ubuntu") {
println("TODO");
// TODO
}
} else { } else {
call("read", "-p", "Expose Port [3001]: ", "port"); defaultVolume = "uptime-kuma";
call("read", "-p", "Volume Name [uptime-kuma]: ", "volume");
bash("check=$(docker -v)");
if (check == "") {
println("Error: docker is not found!");
bash("exit 1");
}
if ("$3" != "") {
port = "$3";
} else {
call("read", "-p", "Expose Port [$port]: ", "port");
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");
} }

View File

@ -7,7 +7,7 @@
"echo" "-e" "" "echo" "-e" ""
"echo" "-e" "---------------------------------------" "echo" "-e" "---------------------------------------"
"echo" "-e" "This script is designed for Linux and basic usage." "echo" "-e" "This script is designed for Linux and basic usage."
"echo" "-e" "Tested with CentOS 7/8" "echo" "-e" "Supported OS: CentOS 7/8, Ubuntu >= 16.04 and Debian"
"echo" "-e" "For advanced usage, please go to https://github.com/louislam/uptime-kuma/wiki/Installation" "echo" "-e" "For advanced usage, please go to https://github.com/louislam/uptime-kuma/wiki/Installation"
"echo" "-e" "---------------------------------------" "echo" "-e" "---------------------------------------"
"echo" "-e" "" "echo" "-e" ""
@ -19,8 +19,54 @@ if [ "$1" != "" ]; then
else else
"read" "-p" "Which installation method do you prefer? [DOCKER/local]: " "type" "read" "-p" "Which installation method do you prefer? [DOCKER/local]: " "type"
fi fi
defaultPort="3001"
function checkNode {
local _0
nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')
"echo" "-e" "Node Version: ""$nodeVersion"
_0="12"
if [ $(($nodeVersion < $_0)) == 1 ]; then
"echo" "-e" "Error: Required Node.js 14"
"exit" "1"
fi
if [ "$nodeVersion" == "12" ]; then
"echo" "-e" "Warning: NodeJS ""$nodeVersion"" is not tested."
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
"echo" "-e" "Installing Node.js 14"
curl -sL https://deb.nodesource.com/setup_14.x | bash - > log.txt
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
}
if [ "$type" == "local" ]; then if [ "$type" == "local" ]; then
defaultPort="3001"
defaultInstallPath="/opt/uptime-kuma" defaultInstallPath="/opt/uptime-kuma"
if [ -e "/etc/redhat-release" ]; then if [ -e "/etc/redhat-release" ]; then
os=$("cat" "/etc/redhat-release") os=$("cat" "/etc/redhat-release")
@ -30,6 +76,9 @@ if [ "$type" == "local" ]; then
os=$(head -n1 /etc/issue | cut -f 1 -d ' ') os=$(head -n1 /etc/issue | cut -f 1 -d ' ')
if [ "$os" == "Ubuntu" ]; then if [ "$os" == "Ubuntu" ]; then
distribution="ubuntu" distribution="ubuntu"
fi
if [ "$os" == "Debian" ]; then
distribution="debian"
fi fi
fi fi
fi fi
@ -53,19 +102,11 @@ fi
installPath="$defaultInstallPath" installPath="$defaultInstallPath"
fi fi
fi fi
# CentOS
if [ "$distribution" == "rhel" ]; then if [ "$distribution" == "rhel" ]; then
nodeCheck=$(node -v) nodeCheck=$(node -v)
if [ "$nodeCheck" != "" ]; then if [ "$nodeCheck" != "" ]; then
nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])') "checkNode"
"echo" "-e" "Node Version: ""$nodeVersion"
_0="12"
if [ $(($nodeVersion < $_0)) == 1 ]; then
"echo" "-e" "Error: Required Node.js 14"
"exit" "1"
fi
if [ "$nodeVersion" == "12" ]; then
"echo" "-e" "Warning: NodeJS ""$nodeVersion"" is not tested."
fi
else else
curlCheck=$(curl --version) curlCheck=$(curl --version)
if [ "$curlCheck" == "" ]; then if [ "$curlCheck" == "" ]; then
@ -87,6 +128,34 @@ fi
"echo" "-e" "Installing Git" "echo" "-e" "Installing Git"
yum -y -q install git yum -y -q install git
fi fi
# 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 missing"
fi
check=$(node -v)
if [ "$check" == "" ]; then
error=$((1))
"echo" "-e" "Error: node is missing"
fi
if [ $(($error > 0)) == 1 ]; then
"echo" "-e" "Please install above missing software"
exit 1
fi
fi
fi
fi
check=$(pm2 --version) check=$(pm2 --version)
if [ "$check" == "" ]; then if [ "$check" == "" ]; then
"echo" "-e" "Installing PM2" "echo" "-e" "Installing PM2"
@ -98,13 +167,31 @@ fi
git clone https://github.com/louislam/uptime-kuma.git . git clone https://github.com/louislam/uptime-kuma.git .
npm run setup npm run setup
pm2 start npm --name uptime-kuma -- run start-server -- --port=$port pm2 start npm --name uptime-kuma -- run start-server -- --port=$port
pm2 list
fi
if [ "$distribution" == "ubuntu" ]; then
"echo" "-e" "TODO"
# TODO
fi
else else
"read" "-p" "Expose Port [3001]: " "port" defaultVolume="uptime-kuma"
"read" "-p" "Volume Name [uptime-kuma]: " "volume" check=$(docker -v)
if [ "$check" == "" ]; then
"echo" "-e" "Error: docker is not found!"
exit 1
fi
if [ "$3" != "" ]; then
port="$3"
else
"read" "-p" "Expose Port [$port]: " "port"
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
fi fi

9220
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,11 @@
"mark-as-nightly": "node extra/mark-as-nightly.js", "mark-as-nightly": "node extra/mark-as-nightly.js",
"reset-password": "node extra/reset-password.js", "reset-password": "node extra/reset-password.js",
"compile-install-script": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./extra/compile-install-script.ps1", "compile-install-script": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./extra/compile-install-script.ps1",
"test-install-script": "docker build --no-cache -f test/test_install_script/centos7.dockerfile ." "test-install-script-centos7": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/centos7.dockerfile .",
"test-install-script-alpine3": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/alpine3.dockerfile .",
"test-install-script-ubuntu": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu.dockerfile .",
"test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .",
"test-install-script-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile ."
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.36", "@fortawesome/fontawesome-svg-core": "^1.2.36",

View File

@ -0,0 +1,4 @@
FROM alpine:3
RUN apk add --update nodejs npm git
COPY ./install.sh .
RUN /bin/sh install.sh local /opt/uptime-kuma 3000 0.0.0.0

View File

@ -0,0 +1,10 @@
FROM debian
# Test invalid node version, these commands install nodejs 10
# RUN apt-get update
# RUN apt --yes install nodejs
# RUN ln -s /usr/bin/nodejs /usr/bin/node
# RUN node -v
COPY ./install.sh .
RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0

View File

@ -0,0 +1,10 @@
FROM ubuntu
# Test invalid node version, these commands install nodejs 10
# RUN apt-get update
# RUN apt --yes install nodejs
# RUN ln -s /usr/bin/nodejs /usr/bin/node
# RUN node -v
COPY ./install.sh .
RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0

View File

@ -1,4 +1,10 @@
FROM ubuntu:16.04 FROM ubuntu:16.04
# Test invalid node version, these commands install nodejs 10
RUN apt-get update
RUN apt --yes install nodejs
# RUN ln -s /usr/bin/nodejs /usr/bin/node
# RUN node -v
COPY ./install.sh . COPY ./install.sh .
RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0 RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0