Compare commits
4 Commits
963ccbe956
...
573e2264c5
| Author | SHA1 | Date | |
|---|---|---|---|
| 573e2264c5 | |||
| 5e8a2ae862 | |||
| bc85a9a77a | |||
| 2541c83de7 |
|
|
@ -3,12 +3,10 @@
|
|||
DATE=$(date +"%y%m%d")
|
||||
|
||||
bck_list() {
|
||||
|
||||
zfs list -t snapshot
|
||||
}
|
||||
|
||||
bck_update() {
|
||||
|
||||
zfs set sync=standard joj
|
||||
sleep 5
|
||||
LIST=($(zfs list -j -t snapshot | jq -rc '[ .datasets | .[] | {dataset: .dataset, version: .snapshot_name} ] | group_by(.dataset) | map({(.[0].dataset): .[-1].version}) | .[]' | tr "\n" " " | sed 's/[{}:"]/ /g'))
|
||||
|
|
@ -17,53 +15,42 @@ bck_update() {
|
|||
zfs send -v -i ${LIST[i]}@${LIST[$((i+1))]} ${LIST[i]}@$DATE | ssh manuel@202.121.180.23 ${LIST[i]/joj\/}
|
||||
done
|
||||
zfs set sync=disabled joj
|
||||
|
||||
}
|
||||
|
||||
bck_prune() {
|
||||
|
||||
LIST=($(zfs list -j -t snapshot | jq -rc '[ .datasets | .[] | {dataset: .dataset, version: .snapshot_name} ] | group_by(.dataset) | map({(.[0].dataset): .[-3].version}) | .[]' | tr "\n" " " | sed 's/[{}:"]/ /g'))
|
||||
|
||||
for((i=0; i < ${#LIST[@]}; i+=2)); do
|
||||
[ "${LIST[$((i+1))]}" != "null" ] && zfs destroy ${LIST[i]}@%${LIST[$((i+1))]}
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
bck_init() {
|
||||
|
||||
zfs set sync=standard joj
|
||||
sleep 5
|
||||
zfs snapshot joj/$FS
|
||||
zfs send -v joj/$FS | ssh manuel@202.121.180.23 $FS
|
||||
zfs set sync=disabled joj
|
||||
|
||||
}
|
||||
|
||||
test_net() {
|
||||
|
||||
if ! ping -c 1 202.121.180.23; then
|
||||
echo "Error: backup server cannot be reached."
|
||||
exit 20
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
case $1 in
|
||||
|
||||
list)
|
||||
bck_list
|
||||
;;
|
||||
|
||||
update)
|
||||
test_net
|
||||
bck_update
|
||||
;;
|
||||
|
||||
prune)
|
||||
bck_prune
|
||||
;;
|
||||
|
||||
init)
|
||||
test_net
|
||||
shift
|
||||
|
|
@ -75,7 +62,6 @@ case $1 in
|
|||
bck_init
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 [list|init FSname|update|prune]"
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -43,22 +43,16 @@ software_install() {
|
|||
|
||||
echo "Installing $COURSE software"
|
||||
|
||||
apt-get update && apt-get upgrade -y
|
||||
apt-get install -y $PACKAGES && apt-get clean
|
||||
apt-get update && apt-get upgrade -y
|
||||
apt-get install -y $PACKAGES && apt-get clean
|
||||
|
||||
}
|
||||
|
||||
custom_commands() {
|
||||
for((i=0; i<${#COMMANDS[@]}; i++)); do
|
||||
eval ${COMMANDS[i]};
|
||||
done
|
||||
}
|
||||
|
||||
net_wait
|
||||
|
||||
import_config
|
||||
software_install
|
||||
services_restart
|
||||
custom_commands
|
||||
|
||||
software_install
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,10 +34,15 @@ git_config() {
|
|||
}
|
||||
|
||||
grafana_config() {
|
||||
sed -i "s/JOBNAME/${LXC_NAME}/" $LXC_ROOTFS_MOUNT/etc/promtail/config.yml
|
||||
sed -i "s/JOBNAME/${LXC_NAME}/" $LXC_ROOTFS_MOUNT/etc/alloy/config.alloy
|
||||
echo "Grafana setup completed"
|
||||
}
|
||||
|
||||
host_config() {
|
||||
sed -i "s/jtc/${LXC_NAME}/" $LXC_ROOTFS_MOUNT/etc/hosts
|
||||
echo "Hostname setup completed"
|
||||
}
|
||||
|
||||
import_sshkey
|
||||
|
||||
ar_config
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user