-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
194 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
SERVER_PORT=8080 | ||
Authorization= | ||
PROXY_URL= | ||
ARGO_AUTH= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,110 @@ | ||
#!/bin/bash | ||
FILES_PATH=${FILES_PATH:-./} | ||
CURRENT_VERSION='' | ||
RELEASE_LATEST='' | ||
|
||
OWNER="aurora-develop" | ||
REPO="aurora" | ||
get_current_version() { | ||
CURRENT_VERSION=$(cat VERSION) | ||
} | ||
|
||
LATEST_RELEASE=$(curl -s https://api.github.com/repos/$OWNER/$REPO/releases/latest | grep "tag_name" | cut -d : -f2,3 | tr -d \",) | ||
get_latest_version() { | ||
# Get latest release version number | ||
RELEASE_LATEST=$(curl -s https://api.github.com/repos/aurora-develop/aurora/releases/latest | jq -r '.tag_name') | ||
if [[ -z "$RELEASE_LATEST" ]]; then | ||
echo "error: Failed to get the latest release version, please check your network." | ||
exit 1 | ||
fi | ||
} | ||
|
||
ASSET_URL=$(curl -s https://api.github.com/repos/$OWNER/$REPO/releases/latest | grep "browser_download_url.*linux-amd64.tar.gz" | cut -d : -f2,3 | tr -d \") | ||
download_web() { | ||
DOWNLOAD_LINK="https://github.com/aurora-develop/aurora/releases/latest/download/aurora-linux-amd64.tar.gz" | ||
if ! wget -qO "$ZIP_FILE" "$DOWNLOAD_LINK"; then | ||
echo 'error: Download failed! Please check your network or try again.' | ||
return 1 | ||
fi | ||
curl -s https://api.github.com/repos/aurora-develop/aurora/releases/latest | jq -r '.tag_name' > VERSION | ||
return 0 | ||
} | ||
|
||
wget -O aurora.tar.gz $ASSET_URL | ||
decompression() { | ||
tar -zxf "$1" -C "$TMP_DIRECTORY" | ||
EXIT_CODE=$? | ||
if [ ${EXIT_CODE} -ne 0 ]; then | ||
"rm" -r "$TMP_DIRECTORY" | ||
echo "removed: $TMP_DIRECTORY" | ||
exit 1 | ||
fi | ||
} | ||
|
||
tar -xzvf aurora.tar.gz | ||
install_web() { | ||
install -m 755 ${TMP_DIRECTORY}/aurora ${FILES_PATH}/app.js | ||
} | ||
|
||
chmod +x aurora | ||
run_web() { | ||
killall app.js 2>/dev/null & | ||
if [ "${PROXY_URL}" != "" ]; then | ||
export PROXY_URL=${PROXY_URL} | ||
fi | ||
if [ "${Authorization}" != "" ]; then | ||
export Authorization=${Authorization} | ||
fi | ||
export SERVER_PORT=8080 | ||
exec ./app.js 2>&1 & | ||
} | ||
|
||
./aurora | ||
generate_argo(){ | ||
cat > argo.sh << EOF | ||
check_file() { | ||
[ ! -e cloudflared ] && wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x cloudflared | ||
} | ||
run_argo() { | ||
chmod +x cloudflared && nohup ./cloudflared tunnel --edge-ip-version auto --protocol http2 run --token ${ARGO_AUTH} 2>/dev/null 2>&1 & | ||
} | ||
if [ "${ARGO_AUTH}" != "" ]; then | ||
check_file | ||
run_argo | ||
fi | ||
EOF | ||
} | ||
|
||
generate_autodel() { | ||
cat > auto_del.sh << EOF | ||
while true; do | ||
rm -rf /app/.git | ||
sleep 5 | ||
done | ||
EOF | ||
} | ||
|
||
generate_autodel | ||
generate_argo | ||
[ -e auto_del.sh ] && bash auto_del.sh & | ||
if [ "${ARGO_AUTH}" != "" ]; then | ||
bash argo.sh & | ||
fi | ||
|
||
TMP_DIRECTORY="$(mktemp -d)" | ||
ZIP_FILE="${TMP_DIRECTORY}/aurora-linux-amd64.tar.gz" | ||
|
||
get_current_version | ||
get_latest_version | ||
if [ "${RELEASE_LATEST}" = "${CURRENT_VERSION}" ]; then | ||
"rm" -rf "$TMP_DIRECTORY" | ||
run_web | ||
exit | ||
fi | ||
|
||
download_web | ||
EXIT_CODE=$? | ||
if [ ${EXIT_CODE} -eq 0 ]; then | ||
: | ||
else | ||
"rm" -r "$TMP_DIRECTORY" | ||
run_web | ||
exit | ||
fi | ||
decompression "$ZIP_FILE" | ||
install_web | ||
"rm" -rf "$TMP_DIRECTORY" | ||
run_web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,76 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
const port = 3000; | ||
|
||
const PROJECT_DOMAIN = process.env.PROJECT_DOMAIN; | ||
var exec = require("child_process").exec; | ||
const os = require("os"); | ||
const { createProxyMiddleware } = require("http-proxy-middleware"); | ||
const axios = require('axios'); | ||
var request = require("request"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
|
||
app.get("/", function (req, res) { | ||
let cmdStr = "echo 'Hello, World!'"; | ||
exec(cmdStr, function (err, stdout, stderr) { | ||
if (err) { | ||
res.type("html").send("<pre>命令行执行错误:\n" + err + "</pre>"); | ||
} else { | ||
res.type("html").send("<pre>Powered by Aurora\n" + "</pre>"); | ||
} | ||
}); | ||
}); | ||
|
||
app.use( | ||
"/", | ||
"/" + "*", | ||
createProxyMiddleware({ | ||
target: "http://127.0.0.1:8080/", | ||
changeOrigin: false, | ||
ws: true, | ||
logLevel: "error" | ||
logLevel: "error", | ||
onProxyReq: function onProxyReq(proxyReq, req, res) { } | ||
}) | ||
); | ||
|
||
function keepalive() { | ||
let glitch_app_url = `http://localhost:${port}`; | ||
|
||
axios.get(glitch_app_url) | ||
.then(response => { | ||
if (response.data.indexOf("./app.js") == -1) { | ||
console.log('Server is not running. Restarting...'); | ||
// Restart server here | ||
} | ||
}) | ||
.catch(error => { | ||
console.log("Error: " + error); | ||
}); | ||
exec("pgrep -laf app.js", function (err, stdout, stderr) { | ||
// 1.查后台系统进程,保持唤醒 | ||
if (stdout.includes("./app.js")) { | ||
console.log("Aurora 正在运行"); | ||
} else { | ||
//Argo 未运行,命令行调起 | ||
exec("bash aurora.sh 2>&1 &", function (err, stdout, stderr) { | ||
if (err) { | ||
console.log("保活-调起Aurora-命令行执行错误:" + err); | ||
} else { | ||
console.log("保活-调起Aurora-命令行执行成功!"); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
setInterval(keepalive, 9 * 1000); | ||
|
||
app.listen(port, () => console.log(`App listening on port ${port}!`)); | ||
function keep_argo_alive() { | ||
if (!process.env.ARGO_AUTH) { | ||
console.log("未设置 ARGO_AUTH,跳过启动 Cloudflred!"); | ||
return; | ||
} | ||
exec("pgrep -laf cloudflared", function (err, stdout, stderr) { | ||
// 1.查后台系统进程,保持唤醒 | ||
if (stdout.includes("./cloudflared tunnel")) { | ||
console.log("Argo 正在运行"); | ||
} else { | ||
//Argo 未运行,命令行调起 | ||
exec("bash argo.sh 2>&1 &", function (err, stdout, stderr) { | ||
if (err) { | ||
console.log("保活-调起Argo-命令行执行错误:" + err); | ||
} else { | ||
console.log("保活-调起Argo-命令行执行成功!"); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
setInterval(keep_argo_alive, 30 * 1000); | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
{ | ||
"name": "aurora", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"express": "^4.19.2", | ||
"http-proxy-middleware": "^3.0.0", | ||
"request": "^2.88.2" | ||
}, | ||
"engines": { | ||
"node": "16.x" | ||
}, | ||
"repository": { | ||
"url": "https://glitch.com/edit/#!/glitch-mvp-node" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"node", | ||
"glitch" | ||
] | ||
} | ||
"name": "glitch-mvp-node", | ||
"version": "0.1.1", | ||
"description": "A simple Node app built on fastify, instantly up and running.", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"express": "^4.18.2", | ||
"http-proxy-middleware": "^2.0.6", | ||
"request": "^2.88.2" | ||
}, | ||
"engines": { | ||
"node": "16.x" | ||
}, | ||
"repository": { | ||
"url": "https://glitch.com/edit/#!/glitch-mvp-node" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"node", | ||
"glitch" | ||
] | ||
} |