install.sh add supports for CentOS

This commit is contained in:
LouisLam 2021-08-18 14:55:03 +08:00
parent d218661f3d
commit 269ac2410b
5 changed files with 158 additions and 34 deletions

View File

@ -1,9 +1,13 @@
// 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.
println("====================="); println("=====================");
println("Uptime Kuma Installer"); println("Uptime Kuma Installer");
println("====================="); 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("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("");
@ -18,16 +22,19 @@ if ("$1" != "") {
} }
if (type == "local") { if (type == "local") {
defaultPort = "3001";
if ("$1" != "") { defaultInstallPath = "/opt/uptime-kuma";
port = "$3";
} else {
call("read", "-p", "Listening Port [3001]: ", "port");
}
if (exists("/etc/redhat-release")) { if (exists("/etc/redhat-release")) {
os = call("cat", "/etc/redhat-release"); os = call("cat", "/etc/redhat-release");
distribution = "rhel"; distribution = "rhel";
} else if (exists("/etc/issue")) {
bash("os=$(head -n1 /etc/issue | cut -f 1 -d ' ')");
if (os == "Ubuntu") {
distribution = "ubuntu";
}
} }
bash("arch=$(uname -i)"); bash("arch=$(uname -i)");
@ -36,33 +43,89 @@ if (type == "local") {
println("Distribution: " ++ distribution); println("Distribution: " ++ distribution);
println("Arch: " ++ arch); println("Arch: " ++ arch);
if (distribution == "rhel") { if ("$3" != "") {
bash("nodePath=$(command -v node)"); port = "$3";
} else {
call("read", "-p", "Listening Port [$port]: ", "port");
if (nodePath != "") { if (port == "") {
port = defaultPort;
}
}
if ("$2" != "") {
installPath = "$2";
} else {
call("read", "-p", "Installation Path [$installPath]: ", "installPath");
if (installPath == "") {
installPath = defaultInstallPath;
}
}
if (distribution == "rhel") {
bash("nodeCheck=$(node -v)");
if (nodeCheck != "") {
bash("nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')"); bash("nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')");
println("Node Version: " ++ nodeVersion); println("Node Version: " ++ nodeVersion);
if (nodeVersion < "12") { if (nodeVersion < "12") {
println("Error: Required Node.js 14"); println("Error: Required Node.js 14");
call("exit", "1"); call("exit", "1");
} else {
if (nodeVersion == "12") {
println("Warning: NodeJS " ++ nodeVersion ++ " is not tested.");
}
println("OK");
} }
if (nodeVersion == "12") {
println("Warning: NodeJS " ++ nodeVersion ++ " is not tested.");
}
} else { } else {
bash("curlCheck=$(curl --version)");
if (curlCheck == "") {
println("Installing Curl");
bash("yum -y -q install curl");
}
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)");
if (nodeCheckAgain == "") {
println("Error during Node.js installation");
bash("exit 1");
}
} }
bash("check=$(git --version)");
if (check == "") {
println("Installing Git");
bash("yum -y -q install git");
}
bash("check=$(pm2 --version)");
if (check == "") {
println("Installing PM2");
bash("npm install pm2 -g");
bash("pm2 startup");
}
call("yum", "install", "git", "-y"); bash("mkdir -p $installPath");
bash("cd $installPath");
bash("git clone https://github.com/louislam/uptime-kuma.git .");
bash("npm run setup");
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"); call("read", "-p", "Expose Port [3001]: ", "port");
call("read", "-p", "Volume Name [uptime-kuma]: ", "volume"); call("read", "-p", "Volume Name [uptime-kuma]: ", "volume");

View File

@ -1,50 +1,108 @@
# 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.
"echo" "-e" "=====================" "echo" "-e" "====================="
"echo" "-e" "Uptime Kuma Installer" "echo" "-e" "Uptime Kuma Installer"
"echo" "-e" "=====================" "echo" "-e" "====================="
"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" "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" ""
"echo" "-e" "Local - Install Uptime Kuma in your current machine with git, Node.js 14 and pm2" "echo" "-e" "Local - Install Uptime Kuma in your current machine with git, Node.js 14 and pm2"
"echo" "-e" "Docker - Install Uptime Kuma Docker container" "echo" "-e" "Docker - Install Uptime Kuma Docker container"
"echo" "-e" "" "echo" "-e" ""
"echo" "-e" "$1"
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
type="$1" type="$1"
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
if [ "$type" == "local" ]; then if [ "$type" == "local" ]; then
"read" "-p" "Listening Port [3001]: " "port" defaultPort="3001"
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")
distribution="rhel" distribution="rhel"
else
if [ -e "/etc/issue" ]; then
os=$(head -n1 /etc/issue | cut -f 1 -d ' ')
if [ "$os" == "Ubuntu" ]; then
distribution="ubuntu"
fi fi
fi
fi
arch=$(uname -i) arch=$(uname -i)
"echo" "-e" "Your OS: ""$os" "echo" "-e" "Your OS: ""$os"
"echo" "-e" "Distribution: ""$distribution" "echo" "-e" "Distribution: ""$distribution"
"echo" "-e" "Arch: ""$arch" "echo" "-e" "Arch: ""$arch"
if [ "$3" != "" ]; then
port="$3"
else
"read" "-p" "Listening Port [$port]: " "port"
if [ "$port" == "" ]; then
port="$defaultPort"
fi
fi
if [ "$2" != "" ]; then
installPath="$2"
else
"read" "-p" "Installation Path [$installPath]: " "installPath"
if [ "$installPath" == "" ]; then
installPath="$defaultInstallPath"
fi
fi
if [ "$distribution" == "rhel" ]; then if [ "$distribution" == "rhel" ]; then
nodePath=$(command -v node) nodeCheck=$(node -v)
if [ "$nodePath" != "" ]; then if [ "$nodeCheck" != "" ]; then
nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])') nodeVersion=$(node -e 'console.log(process.versions.node.split(`.`)[0])')
"echo" "-e" "Node Version: ""$nodeVersion" "echo" "-e" "Node Version: ""$nodeVersion"
_0="12" _0="12"
if [ $(($nodeVersion < $_0)) == 1 ]; then if [ $(($nodeVersion < $_0)) == 1 ]; then
"echo" "-e" "Error: Required Node.js 14" "echo" "-e" "Error: Required Node.js 14"
"exit" "1" "exit" "1"
else
if [ "$nodeVersion" == "12" ]; then
"echo" "-e" "Warning: NodeJS ""$nodeVersion"" is not tested."
fi fi
"echo" "-e" "OK" if [ "$nodeVersion" == "12" ]; then
fi "echo" "-e" "Warning: NodeJS ""$nodeVersion"" is not tested."
fi
else else
- 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
node -v
nodeCheckAgain=$(node -v)
if [ "$nodeCheckAgain" == "" ]; then
"echo" "-e" "Error during Node.js installation"
exit 1
fi
fi fi
"yum" "install" "git" "-y" check=$(git --version)
if [ "$check" == "" ]; then
"echo" "-e" "Installing Git"
yum -y -q install git
fi
check=$(pm2 --version)
if [ "$check" == "" ]; then
"echo" "-e" "Installing PM2"
npm install pm2 -g
pm2 startup
fi
mkdir -p $installPath
cd $installPath
git clone https://github.com/louislam/uptime-kuma.git .
npm run setup
pm2 start npm --name uptime-kuma -- run start-server -- --port=$port
pm2 list
fi
if [ "$distribution" == "ubuntu" ]; then
"echo" "-e" "TODO"
# TODO
fi fi
else else
"read" "-p" "Expose Port [3001]: " "port" "read" "-p" "Expose Port [3001]: " "port"

View File

@ -1,9 +1,4 @@
FROM centos:7 FROM centos:7
RUN useradd -ms /bin/bash test_user
USER test_user
WORKDIR /home/test_user
COPY ./install.sh . COPY ./install.sh .
RUN ls
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

View File

@ -0,0 +1,4 @@
FROM centos:8
COPY ./install.sh .
RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0

View File

@ -0,0 +1,4 @@
FROM ubuntu:16.04
COPY ./install.sh .
RUN bash install.sh local /opt/uptime-kuma 3000 0.0.0.0