From 9058a829a1a1d6eeb7db1e0082ebe5029901abf2 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 21 Jul 2023 16:09:35 +0800 Subject: [PATCH] Update install.sh (#3464) --- extra/install.batsh | 60 +++++++++++++------ install.sh | 54 +++++++++++------ package.json | 5 +- .../alpine3.dockerfile.dockerignore | 0 .../centos7.dockerfile.dockerignore | 0 .../debian-buster.dockerfile | 10 ++++ .../debian-buster.dockerfile.dockerignore | 0 test/test_install_script/debian.dockerfile | 2 +- .../debian.dockerfile.dockerignore | 0 ...ntos8.dockerfile => rockylinux.dockerfile} | 2 +- .../rockylinux.dockerfile.dockerignore | 0 test/test_install_script/ubuntu.dockerfile | 3 +- .../ubuntu.dockerfile.dockerignore | 0 .../test_install_script/ubuntu1604.dockerfile | 5 +- .../ubuntu1604.dockerfile.dockerignore | 0 .../test_install_script/ubuntu1804.dockerfile | 4 ++ .../ubuntu1804.dockerfile.dockerignore | 0 test/ubuntu-nodejs16.dockerfile | 10 ---- 18 files changed, 104 insertions(+), 51 deletions(-) create mode 100644 test/test_install_script/alpine3.dockerfile.dockerignore create mode 100644 test/test_install_script/centos7.dockerfile.dockerignore create mode 100644 test/test_install_script/debian-buster.dockerfile create mode 100644 test/test_install_script/debian-buster.dockerfile.dockerignore create mode 100644 test/test_install_script/debian.dockerfile.dockerignore rename test/test_install_script/{centos8.dockerfile => rockylinux.dockerfile} (81%) create mode 100644 test/test_install_script/rockylinux.dockerfile.dockerignore create mode 100644 test/test_install_script/ubuntu.dockerfile.dockerignore create mode 100644 test/test_install_script/ubuntu1604.dockerfile.dockerignore create mode 100644 test/test_install_script/ubuntu1804.dockerfile create mode 100644 test/test_install_script/ubuntu1804.dockerfile.dockerignore delete mode 100644 test/ubuntu-nodejs16.dockerfile diff --git a/extra/install.batsh b/extra/install.batsh index 65e95cd0e..84099202e 100644 --- a/extra/install.batsh +++ b/extra/install.batsh @@ -5,15 +5,15 @@ // curl -o kuma_install.sh https://raw.githubusercontent.com/louislam/uptime-kuma/master/install.sh && sudo bash kuma_install.sh println("====================="); -println("Uptime Kuma Installer"); +println("Uptime Kuma Install Script"); println("====================="); -println("Supported OS: CentOS 7/8, Ubuntu >= 16.04 and Debian"); +println("Supported OS: Ubuntu >= 16.04, Debian and CentOS/RHEL 7/8"); 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(""); -println("Local - Install Uptime Kuma in your current machine with git, Node.js 14 and pm2"); +println("Local - Install Uptime Kuma on your current machine with git, Node.js and pm2"); println("Docker - Install Uptime Kuma Docker container"); println(""); @@ -29,14 +29,10 @@ function checkNode() { bash("nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')"); println("Node Version: " ++ nodeVersion); - if (nodeVersion < "12") { + if (nodeVersion <= "12") { println("Error: Required Node.js 14"); call("exit", "1"); } - - if (nodeVersion == "12") { - println("Warning: NodeJS " ++ nodeVersion ++ " is not tested."); - } } function deb() { @@ -60,8 +56,8 @@ function deb() { bash("apt --yes install curl"); } - println("Installing Node.js 14"); - bash("curl -sL https://deb.nodesource.com/setup_14.x | bash - > log.txt"); + println("Installing Node.js 16"); + bash("curl -sL https://deb.nodesource.com/setup_16.x | bash - > log.txt"); bash("apt --yes install nodejs"); bash("node -v"); @@ -91,6 +87,10 @@ if (type == "local") { bash("os=$(head -n1 /etc/issue | cut -f 1 -d ' ')"); if (os == "Ubuntu") { distribution = "ubuntu"; + + // Get ubuntu version + bash(". /etc/lsb-release"); + version = DISTRIB_RELEASE; } if (os == "Debian") { distribution = "debian"; @@ -101,6 +101,7 @@ if (type == "local") { println("Your OS: " ++ os); println("Distribution: " ++ distribution); + println("Version: " ++ version); println("Arch: " ++ arch); if ("$3" != "") { @@ -131,15 +132,32 @@ if (type == "local") { checkNode(); } else { - bash("curlCheck=$(curl --version)"); - if (curlCheck == "") { - println("Installing Curl"); - bash("yum -y -q install curl"); + 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"); } - println("Installing Node.js 14"); - bash("curl -sL https://rpm.nodesource.com/setup_14.x | bash - > log.txt"); - bash("yum install -y -q nodejs"); + bash("node -v"); bash("nodeCheckAgain=$(node -v)"); @@ -193,6 +211,14 @@ if (type == "local") { bash("pm2 startup"); } + + // Check again + bash("check=$(pm2 --version)"); + if (check == "") { + println("Error: pm2 is not found!"); + bash("exit 1"); + } + bash("mkdir -p $installPath"); bash("cd $installPath"); bash("git clone https://github.com/louislam/uptime-kuma.git ."); diff --git a/install.sh b/install.sh index 27b30688f..a206e558e 100644 --- a/install.sh +++ b/install.sh @@ -3,15 +3,15 @@ # The command is working on Windows PowerShell and Docker for Windows only. # curl -o kuma_install.sh https://raw.githubusercontent.com/louislam/uptime-kuma/master/install.sh && sudo bash kuma_install.sh "echo" "-e" "=====================" -"echo" "-e" "Uptime Kuma Installer" +"echo" "-e" "Uptime Kuma Install Script" "echo" "-e" "=====================" -"echo" "-e" "Supported OS: CentOS 7/8, Ubuntu >= 16.04 and Debian" +"echo" "-e" "Supported OS: Ubuntu >= 16.04, Debian and CentOS/RHEL 7/8" "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" "" -"echo" "-e" "Local - Install Uptime Kuma in your current machine with git, Node.js 14 and pm2" +"echo" "-e" "Local - Install Uptime Kuma on your current machine with git, Node.js and pm2" "echo" "-e" "Docker - Install Uptime Kuma Docker container" "echo" "-e" "" if [ "$1" != "" ]; then @@ -25,12 +25,9 @@ function checkNode { nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])') "echo" "-e" "Node Version: ""$nodeVersion" _0="12" - if [ $(($nodeVersion < $_0)) == 1 ]; then + 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 { @@ -50,8 +47,8 @@ fi "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 + "echo" "-e" "Installing Node.js 16" + curl -sL https://deb.nodesource.com/setup_16.x | bash - > log.txt apt --yes install nodejs node -v nodeCheckAgain=$(node -v) @@ -75,7 +72,10 @@ if [ "$type" == "local" ]; then if [ -e "/etc/issue" ]; then os=$(head -n1 /etc/issue | cut -f 1 -d ' ') if [ "$os" == "Ubuntu" ]; then - distribution="ubuntu" + distribution="ubuntu" + # Get ubuntu version + . /etc/lsb-release + version="$DISTRIB_RELEASE" fi if [ "$os" == "Debian" ]; then distribution="debian" @@ -85,6 +85,7 @@ fi arch=$(uname -i) "echo" "-e" "Your OS: ""$os" "echo" "-e" "Distribution: ""$distribution" + "echo" "-e" "Version: ""$version" "echo" "-e" "Arch: ""$arch" if [ "$3" != "" ]; then port="$3" @@ -108,14 +109,27 @@ fi if [ "$nodeCheck" != "" ]; then "checkNode" else - curlCheck=$(curl --version) - if [ "$curlCheck" == "" ]; then - "echo" "-e" "Installing Curl" - yum -y -q install curl + 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 14" - curl -sL https://rpm.nodesource.com/setup_14.x | bash - > log.txt - yum install -y -q nodejs + "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 node -v nodeCheckAgain=$(node -v) if [ "$nodeCheckAgain" == "" ]; then @@ -161,6 +175,12 @@ fi "echo" "-e" "Installing PM2" npm install pm2 -g && pm2 install pm2-logrotate pm2 startup +fi + # Check again + check=$(pm2 --version) + if [ "$check" == "" ]; then + "echo" "-e" "Error: pm2 is not found!" + exit 1 fi mkdir -p $installPath cd $installPath diff --git a/package.json b/package.json index d19f01f13..3d5bee044 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,14 @@ "reset-password": "node extra/reset-password.js", "remove-2fa": "node extra/remove-2fa.js", "compile-install-script": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./extra/compile-install-script.ps1", + "test-install-script-rockylinux": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/rockylinux.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-debian": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian.dockerfile .", + "test-install-script-debian-buster": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/debian-buster.dockerfile .", "test-install-script-ubuntu": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu.dockerfile .", + "test-install-script-ubuntu1804": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1804.dockerfile .", "test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .", - "test-nodejs16": "docker build --progress plain -f test/ubuntu-nodejs16.dockerfile .", "simple-dns-server": "node extra/simple-dns-server.js", "simple-mqtt-server": "node extra/simple-mqtt-server.js", "update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix", diff --git a/test/test_install_script/alpine3.dockerfile.dockerignore b/test/test_install_script/alpine3.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/centos7.dockerfile.dockerignore b/test/test_install_script/centos7.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/debian-buster.dockerfile b/test/test_install_script/debian-buster.dockerfile new file mode 100644 index 000000000..cd5e8abb4 --- /dev/null +++ b/test/test_install_script/debian-buster.dockerfile @@ -0,0 +1,10 @@ +FROM debian:buster-slim + +# 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 diff --git a/test/test_install_script/debian-buster.dockerfile.dockerignore b/test/test_install_script/debian-buster.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/debian.dockerfile b/test/test_install_script/debian.dockerfile index 33d4f5753..6e1d172ec 100644 --- a/test/test_install_script/debian.dockerfile +++ b/test/test_install_script/debian.dockerfile @@ -1,4 +1,4 @@ -FROM debian +FROM debian:bookworm-slim # Test invalid node version, these commands install nodejs 10 # RUN apt-get update diff --git a/test/test_install_script/debian.dockerfile.dockerignore b/test/test_install_script/debian.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/centos8.dockerfile b/test/test_install_script/rockylinux.dockerfile similarity index 81% rename from test/test_install_script/centos8.dockerfile rename to test/test_install_script/rockylinux.dockerfile index 7a121f728..884ec473a 100644 --- a/test/test_install_script/centos8.dockerfile +++ b/test/test_install_script/rockylinux.dockerfile @@ -1,4 +1,4 @@ -FROM centos:8 +FROM rockylinux:9 COPY ./install.sh . RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0 diff --git a/test/test_install_script/rockylinux.dockerfile.dockerignore b/test/test_install_script/rockylinux.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/ubuntu.dockerfile b/test/test_install_script/ubuntu.dockerfile index fc9dcd3f4..07d8a25a4 100644 --- a/test/test_install_script/ubuntu.dockerfile +++ b/test/test_install_script/ubuntu.dockerfile @@ -6,4 +6,5 @@ FROM ubuntu # RUN ln -s /usr/bin/nodejs /usr/bin/node # RUN node -v -RUN curl -o kuma_install.sh http://git.kuma.pet/install.sh && bash kuma_install.sh local /opt/uptime-kuma 3000 0.0.0.0 +COPY ./install.sh . +RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0 diff --git a/test/test_install_script/ubuntu.dockerfile.dockerignore b/test/test_install_script/ubuntu.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/ubuntu1604.dockerfile b/test/test_install_script/ubuntu1604.dockerfile index 34230a144..c6b529abe 100644 --- a/test/test_install_script/ubuntu1604.dockerfile +++ b/test/test_install_script/ubuntu1604.dockerfile @@ -1,10 +1,9 @@ FROM ubuntu:16.04 -RUN apt-get update -RUN apt --yes install curl # Test invalid node version, these commands install nodejs 10 #RUN apt --yes install nodejs # RUN ln -s /usr/bin/nodejs /usr/bin/node # RUN node -v -RUN curl -o kuma_install.sh http://git.kuma.pet/install.sh && bash kuma_install.sh local /opt/uptime-kuma 3000 0.0.0.0 +COPY ./install.sh . +RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0 diff --git a/test/test_install_script/ubuntu1604.dockerfile.dockerignore b/test/test_install_script/ubuntu1604.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_install_script/ubuntu1804.dockerfile b/test/test_install_script/ubuntu1804.dockerfile new file mode 100644 index 000000000..d41f67ede --- /dev/null +++ b/test/test_install_script/ubuntu1804.dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu:18.04 + +COPY ./install.sh . +RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0 diff --git a/test/test_install_script/ubuntu1804.dockerfile.dockerignore b/test/test_install_script/ubuntu1804.dockerfile.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/ubuntu-nodejs16.dockerfile b/test/ubuntu-nodejs16.dockerfile deleted file mode 100644 index a2dd2ec86..000000000 --- a/test/ubuntu-nodejs16.dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu -WORKDIR /app -RUN apt update && apt --yes install git curl -RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - -RUN apt --yes install nodejs -RUN git clone https://github.com/louislam/uptime-kuma.git . -RUN npm run setup - -# Option 1. Try it -RUN node server/server.js