From 2541c83de73d257d947a9692eef6a17dc2e79f46 Mon Sep 17 00:00:00 2001 From: bot-ece477 Date: Tue, 17 Mar 2026 18:56:51 +0800 Subject: [PATCH] feat: generate bot and ar tokens --- admin/scripts/joj-container-deploy | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/admin/scripts/joj-container-deploy b/admin/scripts/joj-container-deploy index 78d2cca..d2c5b60 100755 --- a/admin/scripts/joj-container-deploy +++ b/admin/scripts/joj-container-deploy @@ -6,11 +6,15 @@ echoerr() { ERR=$1; shift; echo -e "Error: $@" 1>&2; exit $ERR; } # exit if no course provided [ -z $1 ] && echoerr 255 "Usage: $0 coursecode" - COURSE=$1 -COURSECFG=$HOME/$COURSE +COURSECFG=$HOME/courses/$COURSE GITEAAPI="https://focs.ji.sjtu.edu.cn/git/api/v1" + +read -n 1 -p "Before proceeding confirm that $COURSE organization, $COURSE-joj repository, and bot-$COURSE user exist: [y/N] " READY +[ "x$READY" = "xy" ] || { echo; exit; } + + # dir for course config/setup [ -d $COURSECFG ] || mkdir $COURSECFG @@ -28,20 +32,21 @@ fs_create() { # generate token (write user: ssh key, read org: action runner token) # create course-joj action secret for teapot gitea_config() { - if [ ! -e $COURSECFG/teapot.env ]; then - echo "Configuring Gitea access" read -s -p "Input bot-$COURSE passwd: " BOTPWD GTOKEN=$(curl -s -X POST -u "bot-$COURSE:$BOTPWD" "$GITEAAPI/users/bot-$COURSE/tokens" -H "Content-Type: application/json" -d '{"name":"teapot","scopes":["write:issue", "read:organization", "write:repository", "write:user"]}' | jq -r '.sha1') echo -e "GITEA_ORG_NAME=$COURSE\nGITEA_ACCESS_TOKEN=$GTOKEN" > $COURSECFG/teapot.env + . $COURSECFG/teapot.env + + curl -s -X PUT "$GITEAAPI/repos/$COURSE/$COURSE-joj/actions/secrets/TEAPOT_GITEA_TOKEN" -H "Content-Type: application/json" -d "{\"data\":\"$GITEA_ACCESS_TOKEN\"}" -H "Authorization: Bearer $GITEA_ACCESS_TOKEN" + + else + . $COURSECFG/teapot.env fi - . $COURSECFG/teapot.env - - curl -s -X PUT "$GITEAAPI/repos/$COURSE/$COURSE-joj/actions/secrets/TEAPOT_GITEA_TOKEN" -H "Content-Type: application/json" -d "{\"data\":\"$GITEA_ACCESS_TOKEN\"}" -H "Authorization: Bearer $GITEA_ACCESS_TOKEN" } @@ -60,11 +65,10 @@ ssh_config() { } ar_preconfig() { - - echo "Getting an act_runner token" - - curl -X GET -s "$GITEAAPI/orgs/$COURSE/actions/runners/registration-token?token=$GITEA_ACCESS_TOKEN" | jq -r '.token' > $COURSECFG/act_runner.token - + if [ ! -e $COURSECFG/act_runner.token ]; then + echo "Getting an act_runner token" + curl -X GET -s "$GITEAAPI/orgs/$COURSE/actions/runners/registration-token?token=$GITEA_ACCESS_TOKEN" | jq -r '.token' > $COURSECFG/act_runner.token + fi }