Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02c7fa68aa | |||
| c0bdb4fb5e | |||
| f6df4ae838 | |||
| 6fab798946 |
@@ -15,10 +15,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: https://gitea.com/actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
uses: https://gitea.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
@@ -48,11 +48,36 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Publish Gitea Release
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
api_key: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ steps.tag.outputs.name }}
|
||||
title: ${{ steps.tag.outputs.name }}
|
||||
files: |-
|
||||
release/app.mjs
|
||||
release/install.sh
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
TAG: ${{ steps.tag.outputs.name }}
|
||||
run: |
|
||||
set -eu
|
||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases"
|
||||
parse_id='let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{process.stdout.write(String(JSON.parse(d).id||""))}catch(e){}})'
|
||||
|
||||
rid=$(curl -sS -X POST "$API" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"draft\":false,\"prerelease\":false}" \
|
||||
| node -e "$parse_id")
|
||||
|
||||
if [ -z "$rid" ]; then
|
||||
echo "release may already exist, fetching by tag $TAG"
|
||||
rid=$(curl -sS "$API/tags/$TAG" -H "Authorization: token $TOKEN" | node -e "$parse_id")
|
||||
fi
|
||||
|
||||
if [ -z "$rid" ]; then
|
||||
echo "failed to create or find release for $TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "release id=$rid"
|
||||
|
||||
for f in release/app.mjs release/install.sh; do
|
||||
name=$(basename "$f")
|
||||
echo "uploading $name"
|
||||
curl -sS -X POST "$API/$rid/assets?name=$name" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-F "attachment=@$f" \
|
||||
-o /dev/null -w " -> HTTP %{http_code}\n"
|
||||
done
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# server-config-cli installer
|
||||
#
|
||||
# Usage:
|
||||
# curl -fsSL <REPO>/releases/latest/download/install.sh | bash
|
||||
# Usage (always latest, no version needed):
|
||||
# curl -fsSL https://gitea1.deeppolicy.cn:3002/hanruo/server-config-cli/raw/branch/main/scripts/install.sh | bash
|
||||
#
|
||||
# Environment overrides:
|
||||
# VERSION release tag to install (default: latest)
|
||||
@@ -47,7 +47,22 @@ NODE_URL="${NODE_MIRROR}/${NODE_VERSION}/${NODE_PKG}"
|
||||
NODE_DIR="${INSTALL_DIR}/node-${NODE_VERSION}-${NODE_OS}-${NODE_ARCH}"
|
||||
|
||||
if [ "$VERSION" = "latest" ]; then
|
||||
BUNDLE_URL="${REPO_BASE}/releases/latest/download/app.mjs"
|
||||
# Resolve the newest release tag via the API (works on all Gitea versions,
|
||||
# unlike the GitHub-style /releases/latest/download shortcut).
|
||||
proto="${REPO_BASE%%://*}"
|
||||
rest="${REPO_BASE#*://}"
|
||||
host="${rest%%/*}"
|
||||
repo_path="${rest#*/}"
|
||||
API_BASE="${proto}://${host}/api/v1/repos/${repo_path}"
|
||||
|
||||
log "Resolving latest release tag"
|
||||
TAG=$(curl -fsSL "${API_BASE}/releases/latest" \
|
||||
| grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' \
|
||||
| head -1 \
|
||||
| sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/')
|
||||
[ -n "$TAG" ] || die "could not resolve latest release tag from ${API_BASE}/releases/latest"
|
||||
log "Latest release is ${TAG}"
|
||||
BUNDLE_URL="${REPO_BASE}/releases/download/${TAG}/app.mjs"
|
||||
else
|
||||
BUNDLE_URL="${REPO_BASE}/releases/download/${VERSION}/app.mjs"
|
||||
fi
|
||||
|
||||
@@ -47,9 +47,9 @@ function zshInstallPlan() {
|
||||
const syntaxHighlightingDir = path.join(customDir, "plugins", "zsh-syntax-highlighting");
|
||||
|
||||
const steps = [
|
||||
run("apt update", "sudo", ["apt", "update"]),
|
||||
run("apt upgrade", "sudo", ["apt", "upgrade", "-y"]),
|
||||
run("install zsh & friends", "sudo", ["apt", "install", "zsh", "git", "curl", "wget", "-y"]),
|
||||
run("apt update", "sudo", aptArgs("update")),
|
||||
run("apt upgrade", "sudo", aptArgs("upgrade", "-y")),
|
||||
run("install zsh & friends", "sudo", aptArgs("install", "zsh", "git", "curl", "wget", "-y")),
|
||||
run("git credential helper = store", "git", ["config", "--global", "credential.helper", "store"]),
|
||||
run("change shell to zsh", "sudo", ["chsh", "-s", "/bin/zsh", os.userInfo().username]),
|
||||
run("install oh-my-zsh", "sh", ["-c", OH_MY_ZSH_COMMAND]),
|
||||
@@ -125,8 +125,8 @@ function sshInstallPlan() {
|
||||
return {
|
||||
title: "Install OpenSSH server",
|
||||
steps: [
|
||||
run("apt update", "sudo", ["apt", "update"]),
|
||||
run("install openssh-server", "sudo", ["apt", "install", "openssh-server", "-y"]),
|
||||
run("apt update", "sudo", aptArgs("update")),
|
||||
run("install openssh-server", "sudo", aptArgs("install", "openssh-server", "-y")),
|
||||
run("enable + start ssh", "sudo", ["systemctl", "enable", "--now", "ssh"]),
|
||||
],
|
||||
};
|
||||
@@ -351,6 +351,18 @@ function requireToken(value) {
|
||||
return token;
|
||||
}
|
||||
|
||||
function aptArgs(...args) {
|
||||
return [
|
||||
"DEBIAN_FRONTEND=noninteractive",
|
||||
"NEEDRESTART_MODE=a",
|
||||
"NEEDRESTART_SUSPEND=1",
|
||||
"apt-get",
|
||||
"-o", "Dpkg::Options::=--force-confold",
|
||||
"-o", "Dpkg::Options::=--force-confdef",
|
||||
...args,
|
||||
];
|
||||
}
|
||||
|
||||
function run(label, command, args) {
|
||||
return { kind: "run", label, command, args };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user