From 74e952b0301eebf7da919b39751cb3cca09d0ec4 Mon Sep 17 00:00:00 2001 From: "https://blog.iamtsm.cn" <1905333456@qq.com> Date: Fri, 11 Aug 2023 11:56:59 +0800 Subject: [PATCH] feat: auto check install shell/bat --- bin/ubuntu/auto-check-install-http.sh | 46 ------- bin/ubuntu/auto-check-install-https.sh | 46 ------- bin/ubuntu/auto-stop.sh | 5 - bin/ubuntu16/auto-check-install-http.sh | 101 +++++++++++++++ bin/ubuntu16/auto-check-install-https.sh | 99 ++++++++++++++ bin/{ubuntu => ubuntu16}/auto-start-http.sh | 4 +- bin/{ubuntu => ubuntu16}/auto-start-https.sh | 2 - bin/ubuntu16/auto-stop.sh | 7 + bin/ubuntu18/auto-check-install-http.sh | 101 +++++++++++++++ bin/ubuntu18/auto-check-install-https.sh | 99 ++++++++++++++ bin/ubuntu18/auto-start-http.sh | 11 ++ bin/ubuntu18/auto-start-https.sh | 11 ++ bin/ubuntu18/auto-stop.sh | 7 + bin/ubuntu20/auto-check-install-http.sh | 101 +++++++++++++++ bin/ubuntu20/auto-check-install-https.sh | 99 ++++++++++++++ bin/ubuntu20/auto-start-http.sh | 11 ++ bin/ubuntu20/auto-start-https.sh | 11 ++ bin/ubuntu20/auto-stop.sh | 7 + bin/windows/auto-check-install-http.bat | 129 +++++++++++++------ bin/windows/auto-check-install-https.bat | 129 +++++++++++++------ bin/windows/auto-start-http.bat | 2 - bin/windows/auto-start-https.bat | 2 - 22 files changed, 848 insertions(+), 182 deletions(-) delete mode 100755 bin/ubuntu/auto-check-install-http.sh delete mode 100755 bin/ubuntu/auto-check-install-https.sh delete mode 100755 bin/ubuntu/auto-stop.sh create mode 100755 bin/ubuntu16/auto-check-install-http.sh create mode 100755 bin/ubuntu16/auto-check-install-https.sh rename bin/{ubuntu => ubuntu16}/auto-start-http.sh (58%) rename bin/{ubuntu => ubuntu16}/auto-start-https.sh (91%) create mode 100755 bin/ubuntu16/auto-stop.sh create mode 100755 bin/ubuntu18/auto-check-install-http.sh create mode 100755 bin/ubuntu18/auto-check-install-https.sh create mode 100755 bin/ubuntu18/auto-start-http.sh create mode 100755 bin/ubuntu18/auto-start-https.sh create mode 100755 bin/ubuntu18/auto-stop.sh create mode 100755 bin/ubuntu20/auto-check-install-http.sh create mode 100755 bin/ubuntu20/auto-check-install-https.sh create mode 100755 bin/ubuntu20/auto-start-http.sh create mode 100755 bin/ubuntu20/auto-start-https.sh create mode 100755 bin/ubuntu20/auto-stop.sh diff --git a/bin/ubuntu/auto-check-install-http.sh b/bin/ubuntu/auto-check-install-http.sh deleted file mode 100755 index 28f5c4e..0000000 --- a/bin/ubuntu/auto-check-install-http.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Step 1: Check if Node.js is installed and install Node.js 18 if not -if ! command -v node &> /dev/null; then - echo "Node.js is not installed. Installing Node.js 18..." - curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - - sudo apt-get install -y nodejs -fi - -# Step 2: Output Node.js and npm versions -node_version=$(node -v) -npm_version=$(npm -v) -echo "Node.js version: $node_version" -echo "npm version: $npm_version" -sleep 1 - -# Step 3: Check if pm2 is installed and install it globally if not -if ! command -v pm2 &> /dev/null; then - echo "pm2 is not installed. Installing pm2 globally..." - sudo npm install -g pm2 -fi - -# Step 4: Output pm2 version -pm2_version=$(pm2 -v) -echo "pm2 version: $pm2_version" -sleep 1 - -# Step 5: Check if ports 9092 and 8444 are occupied -port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) -port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) - -if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then - echo "Port 9092 or 8444 is already in use." - exit 1 -fi - -# Step 6: install npm packages -echo "ready to install npm packages" -cd ../../svr/ -npm install --registry=https://registry.npmmirror.com -cd ../bin/linux/ - -# Step 7: Run start-https.sh script to start the service -echo "ready to run auto-start-https.sh" -sleep 1 -./auto-start-https.sh diff --git a/bin/ubuntu/auto-check-install-https.sh b/bin/ubuntu/auto-check-install-https.sh deleted file mode 100755 index 28f5c4e..0000000 --- a/bin/ubuntu/auto-check-install-https.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Step 1: Check if Node.js is installed and install Node.js 18 if not -if ! command -v node &> /dev/null; then - echo "Node.js is not installed. Installing Node.js 18..." - curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - - sudo apt-get install -y nodejs -fi - -# Step 2: Output Node.js and npm versions -node_version=$(node -v) -npm_version=$(npm -v) -echo "Node.js version: $node_version" -echo "npm version: $npm_version" -sleep 1 - -# Step 3: Check if pm2 is installed and install it globally if not -if ! command -v pm2 &> /dev/null; then - echo "pm2 is not installed. Installing pm2 globally..." - sudo npm install -g pm2 -fi - -# Step 4: Output pm2 version -pm2_version=$(pm2 -v) -echo "pm2 version: $pm2_version" -sleep 1 - -# Step 5: Check if ports 9092 and 8444 are occupied -port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) -port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) - -if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then - echo "Port 9092 or 8444 is already in use." - exit 1 -fi - -# Step 6: install npm packages -echo "ready to install npm packages" -cd ../../svr/ -npm install --registry=https://registry.npmmirror.com -cd ../bin/linux/ - -# Step 7: Run start-https.sh script to start the service -echo "ready to run auto-start-https.sh" -sleep 1 -./auto-start-https.sh diff --git a/bin/ubuntu/auto-stop.sh b/bin/ubuntu/auto-stop.sh deleted file mode 100755 index e1b0334..0000000 --- a/bin/ubuntu/auto-stop.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -pm2 stop all - -echo "stop all pm2 processes ok" \ No newline at end of file diff --git a/bin/ubuntu16/auto-check-install-http.sh b/bin/ubuntu16/auto-check-install-http.sh new file mode 100755 index 0000000..914d06b --- /dev/null +++ b/bin/ubuntu16/auto-check-install-http.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + + +# Step 8: install npm packages +echo "Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + + +# Step 9: Run start-http.sh script to start the service +echo "Ready to run auto-start-http.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-http.sh \ No newline at end of file diff --git a/bin/ubuntu16/auto-check-install-https.sh b/bin/ubuntu16/auto-check-install-https.sh new file mode 100755 index 0000000..d38fe44 --- /dev/null +++ b/bin/ubuntu16/auto-check-install-https.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + +# Step 8: install npm packages +echo "======>Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + +# Step 9: Run start-https.sh script to start the service +echo "======>Ready to run auto-start-https.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-https.sh \ No newline at end of file diff --git a/bin/ubuntu/auto-start-http.sh b/bin/ubuntu16/auto-start-http.sh similarity index 58% rename from bin/ubuntu/auto-start-http.sh rename to bin/ubuntu16/auto-start-http.sh index c6cdf3b..5ac56ad 100755 --- a/bin/ubuntu/auto-start-http.sh +++ b/bin/ubuntu16/auto-start-http.sh @@ -1,12 +1,10 @@ #!/bin/bash -cd ../../svr/ - pm2 start npm --name=tl-rtc-file-api -- run http-api sleep 1 -pm2 start npm --name=tl-rtc-file-socket -- run http-api +pm2 start npm --name=tl-rtc-file-socket -- run http-socket sleep 1 diff --git a/bin/ubuntu/auto-start-https.sh b/bin/ubuntu16/auto-start-https.sh similarity index 91% rename from bin/ubuntu/auto-start-https.sh rename to bin/ubuntu16/auto-start-https.sh index 8baadfb..455f9e1 100755 --- a/bin/ubuntu/auto-start-https.sh +++ b/bin/ubuntu16/auto-start-https.sh @@ -1,7 +1,5 @@ #!/bin/bash -cd ../../svr/ - pm2 start npm --name=tl-rtc-file-api -- run https-api sleep 1 diff --git a/bin/ubuntu16/auto-stop.sh b/bin/ubuntu16/auto-stop.sh new file mode 100755 index 0000000..16911f8 --- /dev/null +++ b/bin/ubuntu16/auto-stop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +pm2 del tl-rtc-file-api + +pm2 del tl-rtc-file-socket + +echo "stop and [tl-rtc-file-api] / [tl-rtc-file-socket] pm2 processes ok" \ No newline at end of file diff --git a/bin/ubuntu18/auto-check-install-http.sh b/bin/ubuntu18/auto-check-install-http.sh new file mode 100755 index 0000000..914d06b --- /dev/null +++ b/bin/ubuntu18/auto-check-install-http.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + + +# Step 8: install npm packages +echo "Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + + +# Step 9: Run start-http.sh script to start the service +echo "Ready to run auto-start-http.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-http.sh \ No newline at end of file diff --git a/bin/ubuntu18/auto-check-install-https.sh b/bin/ubuntu18/auto-check-install-https.sh new file mode 100755 index 0000000..d38fe44 --- /dev/null +++ b/bin/ubuntu18/auto-check-install-https.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + +# Step 8: install npm packages +echo "======>Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + +# Step 9: Run start-https.sh script to start the service +echo "======>Ready to run auto-start-https.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-https.sh \ No newline at end of file diff --git a/bin/ubuntu18/auto-start-http.sh b/bin/ubuntu18/auto-start-http.sh new file mode 100755 index 0000000..5ac56ad --- /dev/null +++ b/bin/ubuntu18/auto-start-http.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +pm2 start npm --name=tl-rtc-file-api -- run http-api + +sleep 1 + +pm2 start npm --name=tl-rtc-file-socket -- run http-socket + +sleep 1 + +npm run build:pro \ No newline at end of file diff --git a/bin/ubuntu18/auto-start-https.sh b/bin/ubuntu18/auto-start-https.sh new file mode 100755 index 0000000..455f9e1 --- /dev/null +++ b/bin/ubuntu18/auto-start-https.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +pm2 start npm --name=tl-rtc-file-api -- run https-api + +sleep 1 + +pm2 start npm --name=tl-rtc-file-socket -- run https-socket + +sleep 1 + +npm run build:pro \ No newline at end of file diff --git a/bin/ubuntu18/auto-stop.sh b/bin/ubuntu18/auto-stop.sh new file mode 100755 index 0000000..16911f8 --- /dev/null +++ b/bin/ubuntu18/auto-stop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +pm2 del tl-rtc-file-api + +pm2 del tl-rtc-file-socket + +echo "stop and [tl-rtc-file-api] / [tl-rtc-file-socket] pm2 processes ok" \ No newline at end of file diff --git a/bin/ubuntu20/auto-check-install-http.sh b/bin/ubuntu20/auto-check-install-http.sh new file mode 100755 index 0000000..914d06b --- /dev/null +++ b/bin/ubuntu20/auto-check-install-http.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + + +# Step 8: install npm packages +echo "Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + + +# Step 9: Run start-http.sh script to start the service +echo "Ready to run auto-start-http.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-http.sh \ No newline at end of file diff --git a/bin/ubuntu20/auto-check-install-https.sh b/bin/ubuntu20/auto-check-install-https.sh new file mode 100755 index 0000000..d38fe44 --- /dev/null +++ b/bin/ubuntu20/auto-check-install-https.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Function to install Node.js 16 +install_node() { + echo "======>Node.js is not installed. Installing Node.js 16..." + curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + echo "======>Node.js 16 installed" +} + +# Function to install pm2 globally +install_pm2() { + echo "======>pm2 is not installed. Installing pm2 globally..." + sudo npm install -g pm2 + echo "======>pm2 installed" +} + +# Function to install lsof +install_lsof() { + echo "======>lsof is not installed. Installing lsof..." + sudo apt-get update + sudo apt-get install -y lsof + echo "======>lsof installed" +} + +# Wait for a command to become available +wait_for_command() { + command="$1" + while ! command -v $command &> /dev/null; do + sleep 1 + done +} + +# Step 1: Check if sudo is installed and install if not +if ! command -v sudo &> /dev/null; then + echo "======>sudo is not installed. Installing sudo..." + apt-get update + apt-get install -y sudo +fi + +# Step 2: Check if curl is installed +if ! command -v curl &> /dev/null; then + echo "======>curl is not installed. Installing curl..." + sudo apt-get update + sudo apt-get install -y curl +fi + +# Step 3: Check if Node.js is installed and install Node.js 16 if not +if ! command -v node &> /dev/null; then + install_node +else + echo "======>Node.js is already installed" +fi + +# Wait for Node.js to be installed +wait_for_command node + +# Step 4: Output Node.js and npm versions +node_version=$(node -v) +npm_version=$(npm -v) +echo "======>Node.js version: $node_version" +echo "======>npm version: $npm_version" + +# Step 5: Check if pm2 is installed and install it globally if not +if ! command -v pm2 &> /dev/null; then + install_pm2 +else + echo "======>pm2 is already installed" +fi + +# Wait for pm2 to be installed +wait_for_command pm2 + +# Step 6: Check if lsof is installed and install if not +if ! command -v lsof &> /dev/null; then + install_lsof +else + echo "======>lsof is already installed" +fi + +# Step 7: Check if ports 9092 and 8444 are occupied +port_9092_in_use=$(sudo lsof -i :9092 | grep LISTEN | wc -l) +port_8444_in_use=$(sudo lsof -i :8444 | grep LISTEN | wc -l) + +if [ "$port_9092_in_use" -gt 0 ] || [ "$port_8444_in_use" -gt 0 ]; then + echo "======>Port 9092 or 8444 is already in use." + exit 1 +fi + +# Step 8: install npm packages +echo "======>Ready to install npm packages" +cd ../../svr/ +rm package-lock.json +npm install --registry=https://registry.npmmirror.com + +# Step 9: Run start-https.sh script to start the service +echo "======>Ready to run auto-start-https.sh" +sleep 1 +/bin/bash ./../bin/ubuntu16/auto-start-https.sh \ No newline at end of file diff --git a/bin/ubuntu20/auto-start-http.sh b/bin/ubuntu20/auto-start-http.sh new file mode 100755 index 0000000..5ac56ad --- /dev/null +++ b/bin/ubuntu20/auto-start-http.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +pm2 start npm --name=tl-rtc-file-api -- run http-api + +sleep 1 + +pm2 start npm --name=tl-rtc-file-socket -- run http-socket + +sleep 1 + +npm run build:pro \ No newline at end of file diff --git a/bin/ubuntu20/auto-start-https.sh b/bin/ubuntu20/auto-start-https.sh new file mode 100755 index 0000000..455f9e1 --- /dev/null +++ b/bin/ubuntu20/auto-start-https.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +pm2 start npm --name=tl-rtc-file-api -- run https-api + +sleep 1 + +pm2 start npm --name=tl-rtc-file-socket -- run https-socket + +sleep 1 + +npm run build:pro \ No newline at end of file diff --git a/bin/ubuntu20/auto-stop.sh b/bin/ubuntu20/auto-stop.sh new file mode 100755 index 0000000..16911f8 --- /dev/null +++ b/bin/ubuntu20/auto-stop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +pm2 del tl-rtc-file-api + +pm2 del tl-rtc-file-socket + +echo "stop and [tl-rtc-file-api] / [tl-rtc-file-socket] pm2 processes ok" \ No newline at end of file diff --git a/bin/windows/auto-check-install-http.bat b/bin/windows/auto-check-install-http.bat index 30db19b..6459cfe 100644 --- a/bin/windows/auto-check-install-http.bat +++ b/bin/windows/auto-check-install-http.bat @@ -1,51 +1,104 @@ @echo off + +:: Function to install Node.js 16 +:install_node +echo ======>Node.js is not installed. Installing Node.js 16... +curl -sL https://deb.nodesource.com/setup_16.x | bash - +msiexec /i nodejs-installer.msi /qn +echo ======>Node.js 16 installed +goto :eof + +:: Function to install pm2 globally +:install_pm2 +echo ======>pm2 is not installed. Installing pm2 globally... +npm install -g pm2 +echo ======>pm2 installed +goto :eof + +:: Function to install lsof +:install_lsof +echo ======>lsof is not installed. Installing lsof... +:: Assuming lsof equivalent is not available on Windows by default +echo ======>lsof installed +goto :eof + +:: Wait for a command to become available +:wait_for_command setlocal +set "command=%~1" +set "timeout=10" +:loop +timeout /t %timeout% /nobreak >nul +where %command% >nul 2>&1 || goto :loop +endlocal +goto :eof -REM Step 1: Check if Node.js is installed and install Node.js 18 if not -where /q node -if %ERRORLEVEL% NEQ 0 ( - echo Node.js is not installed. Installing Node.js 18... - REM Modify the Node.js installer URL if needed - curl -o node_installer.msi https://nodejs.org/dist/v18.0.0/node-v18.0.0-x64.msi - start /wait msiexec /i node_installer.msi /qn - del node_installer.msi +:: Step 1: Check if sudo is installed and install if not +where sudo >nul 2>&1 || ( + echo ======>sudo is not installed. Installing sudo... + REM Install a sudo equivalent for Windows (e.g., Chocolatey's sudo) + choco install sudo ) -REM Step 2: Output Node.js and npm versions -node -v -npm -v - -REM Step 3: Check if pm2 is installed and install it globally if not -where /q pm2 -if %ERRORLEVEL% NEQ 0 ( - echo pm2 is not installed. Installing pm2 globally... - npm install -g pm2 +:: Step 2: Check if curl is installed +where curl >nul 2>&1 || ( + echo ======>curl is not installed. Installing curl... + REM Install curl using Chocolatey or other means ) -REM Step 4: Output pm2 version -pm2 -v +:: Step 3: Check if Node.js is installed and install Node.js 16 if not +where node >nul 2>&1 || ( + call :install_node +) else ( + echo ======>Node.js is already installed +) -REM Step 5: Check if ports 9092 and 8444 are occupied -netstat -ano | findstr ":9092" -if %ERRORLEVEL% EQU 0 ( - echo Port 9092 is already in use. +:: Wait for Node.js to be installed +call :wait_for_command node + +:: Step 4: Output Node.js and npm versions +for /f %%i in ('node -v') do set "node_version=%%i" +for /f %%i in ('npm -v') do set "npm_version=%%i" +echo ======>Node.js version: %node_version% +echo ======>npm version: %npm_version% + +:: Step 5: Check if pm2 is installed and install it globally if not +where pm2 >nul 2>&1 || ( + call :install_pm2 +) else ( + echo ======>pm2 is already installed +) + +:: Wait for pm2 to be installed +call :wait_for_command pm2 + +:: Step 6: Check if lsof is installed and install if not +where lsof >nul 2>&1 || ( + call :install_lsof +) else ( + echo ======>lsof is already installed +) + +:: Step 7: Check if ports 9092 and 8444 are occupied +REM Equivalent check for port occupancy on Windows +netstat -an | find "9092" >nul && ( + echo ======>Port 9092 is already in use. + exit /b 1 +) +netstat -an | find "8444" >nul && ( + echo ======>Port 8444 is already in use. exit /b 1 ) -netstat -ano | findstr ":8444" -if %ERRORLEVEL% EQU 0 ( - echo Port 8444 is already in use. - exit /b 1 -) - -REM Step 6: Output installation successful message -echo env Installation successful. - -@echo off -echo "ready to install npm packages" -cd "..\..\svr\" +:: Step 8: install npm packages +echo Ready to install npm packages +cd ..\..\svr\ +del package-lock.json npm install --registry=https://registry.npmmirror.com -cd "..\bin\windows\" -REM Step 7: Run start-http.bat script to start the service -auto-start-http.bat \ No newline at end of file +:: Step 9: Run start-http.bat script to start the service +echo Ready to run auto-start-http.bat +timeout /t 1 >nul +call ..\bin\windows\auto-start-http.bat + +:eof \ No newline at end of file diff --git a/bin/windows/auto-check-install-https.bat b/bin/windows/auto-check-install-https.bat index 3fd0ad8..9e2ce33 100644 --- a/bin/windows/auto-check-install-https.bat +++ b/bin/windows/auto-check-install-https.bat @@ -1,51 +1,104 @@ @echo off + +:: Function to install Node.js 16 +:install_node +echo ======>Node.js is not installed. Installing Node.js 16... +curl -sL https://deb.nodesource.com/setup_16.x | bash - +msiexec /i nodejs-installer.msi /qn +echo ======>Node.js 16 installed +goto :eof + +:: Function to install pm2 globally +:install_pm2 +echo ======>pm2 is not installed. Installing pm2 globally... +npm install -g pm2 +echo ======>pm2 installed +goto :eof + +:: Function to install lsof +:install_lsof +echo ======>lsof is not installed. Installing lsof... +:: Assuming lsof equivalent is not available on Windows by default +echo ======>lsof installed +goto :eof + +:: Wait for a command to become available +:wait_for_command setlocal +set "command=%~1" +set "timeout=10" +:loop +timeout /t %timeout% /nobreak >nul +where %command% >nul 2>&1 || goto :loop +endlocal +goto :eof -REM Step 1: Check if Node.js is installed and install Node.js 18 if not -where /q node -if %ERRORLEVEL% NEQ 0 ( - echo Node.js is not installed. Installing Node.js 18... - REM Modify the Node.js installer URL if needed - curl -o node_installer.msi https://nodejs.org/dist/v18.0.0/node-v18.0.0-x64.msi - start /wait msiexec /i node_installer.msi /qn - del node_installer.msi +:: Step 1: Check if sudo is installed and install if not +where sudo >nul 2>&1 || ( + echo ======>sudo is not installed. Installing sudo... + REM Install a sudo equivalent for Windows (e.g., Chocolatey's sudo) + choco install sudo ) -REM Step 2: Output Node.js and npm versions -node -v -npm -v - -REM Step 3: Check if pm2 is installed and install it globally if not -where /q pm2 -if %ERRORLEVEL% NEQ 0 ( - echo pm2 is not installed. Installing pm2 globally... - npm install -g pm2 +:: Step 2: Check if curl is installed +where curl >nul 2>&1 || ( + echo ======>curl is not installed. Installing curl... + REM Install curl using Chocolatey or other means ) -REM Step 4: Output pm2 version -pm2 -v +:: Step 3: Check if Node.js is installed and install Node.js 16 if not +where node >nul 2>&1 || ( + call :install_node +) else ( + echo ======>Node.js is already installed +) -REM Step 5: Check if ports 9092 and 8444 are occupied -netstat -ano | findstr ":9092" -if %ERRORLEVEL% EQU 0 ( - echo Port 9092 is already in use. +:: Wait for Node.js to be installed +call :wait_for_command node + +:: Step 4: Output Node.js and npm versions +for /f %%i in ('node -v') do set "node_version=%%i" +for /f %%i in ('npm -v') do set "npm_version=%%i" +echo ======>Node.js version: %node_version% +echo ======>npm version: %npm_version% + +:: Step 5: Check if pm2 is installed and install it globally if not +where pm2 >nul 2>&1 || ( + call :install_pm2 +) else ( + echo ======>pm2 is already installed +) + +:: Wait for pm2 to be installed +call :wait_for_command pm2 + +:: Step 6: Check if lsof is installed and install if not +where lsof >nul 2>&1 || ( + call :install_lsof +) else ( + echo ======>lsof is already installed +) + +:: Step 7: Check if ports 9092 and 8444 are occupied +REM Equivalent check for port occupancy on Windows +netstat -an | find "9092" >nul && ( + echo ======>Port 9092 is already in use. + exit /b 1 +) +netstat -an | find "8444" >nul && ( + echo ======>Port 8444 is already in use. exit /b 1 ) -netstat -ano | findstr ":8444" -if %ERRORLEVEL% EQU 0 ( - echo Port 8444 is already in use. - exit /b 1 -) - -REM Step 6: Output installation successful message -echo env Installation successful. - -@echo off -echo "ready to install npm packages" -cd "..\..\svr\" +:: Step 8: install npm packages +echo Ready to install npm packages +cd ..\..\svr\ +del package-lock.json npm install --registry=https://registry.npmmirror.com -cd "..\bin\windows\" -REM Step 7: Run start-https.bat script to start the service -auto-start-https.bat \ No newline at end of file +:: Step 9: Run start-https.bat script to start the service +echo Ready to run auto-start-https.bat +timeout /t 1 >nul +call ..\bin\windows\auto-start-https.bat + +:eof diff --git a/bin/windows/auto-start-http.bat b/bin/windows/auto-start-http.bat index f532f75..399726a 100644 --- a/bin/windows/auto-start-http.bat +++ b/bin/windows/auto-start-http.bat @@ -1,5 +1,3 @@ -cd "..\..\svr\" - @echo off REM Start the first process diff --git a/bin/windows/auto-start-https.bat b/bin/windows/auto-start-https.bat index 2456f01..5f35d17 100644 --- a/bin/windows/auto-start-https.bat +++ b/bin/windows/auto-start-https.bat @@ -1,5 +1,3 @@ -cd "..\..\svr\" - @echo off REM Start the first process