Skip to content

Commit

Permalink
Fix many errors
Browse files Browse the repository at this point in the history
  • Loading branch information
k0baya committed Apr 10, 2024
1 parent 6799a55 commit f63e3f1
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 58 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SERVER_PORT=8080
Authorization=
PROXY_URL=
ARGO_AUTH=
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

* 前往 [Glitch](https://glitch.com/) 注册账户,然后点击右边按钮 =====> [![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/import/github/aurora-develop/aurora-glitch)

然后打开命令终端
然后在`.env`文件中设置环境变量:
|Authorization|PROXY_URL|ARGO_AUTH|
|-|-|-|
|访问 Aurora 时使用的 API-Key|代理池|Cloudflared 客户端 Token|

![屏幕截图](https://jsd.cdn.zzko.cn/gh/xiaozhou26/tuph@main/images/屏幕截图%202024-04-09%20211918.png)

输入
```
bash aurora.sh
```
即部署完成。

部署成功后

Expand Down
112 changes: 103 additions & 9 deletions aurora.sh
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
77 changes: 59 additions & 18 deletions index.js
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}!`));
47 changes: 24 additions & 23 deletions package.json
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"
]
}

0 comments on commit f63e3f1

Please sign in to comment.