generated from trywilco/Anythink-Market-Public
-
Notifications
You must be signed in to change notification settings - Fork 4
/
start_quest.sh
executable file
·44 lines (34 loc) · 1.23 KB
/
start_quest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
API_BASE_URL="${API_BASE_URL:="https://engine.wilco.gg"}"
WILCO_ID="`cat .wilco 2> /dev/null`"
sendEvent() {
curl -m 5 -X POST $API_BASE_URL/users/$WILCO_ID/event -d "$1" -H 'Content-Type: application/json' &> /dev/null
}
sendScriptRunningEvent() {
body='{"event":"start_quest_script_running", "metadata": {"remote": false}}'
sendEvent "$body"
}
sendScriptRanEvent() {
body='{"event":"start_quest_script_ran", "metadata": {"success": '$1', "remote": false, "error": "'$2'"}}'
sendEvent "$body"
}
sendScriptRunningEvent
if [[ -z $WILCO_ID ]]; then
printf "Please run the script in the root folder of the repo. Aborting.\n"
exit 1
fi
printf "[= ] Stashing any existing changes ... \n"
git stash &> /dev/null
printf "[== ] Resetting local 'main' branch to 'origin/main' ... \n"
git_output=$( (git checkout main && git fetch origin main && git reset --hard origin/main) 2>&1 > /dev/null)
git_exit_code=$?
if ! test "$git_exit_code" -eq 0
then
printf "[==X] ERROR: Could not reset local 'main' branch. Aborting.\n"
sendScriptRanEvent false "$git_output"
echo "[==X] GIT ERROR: $git_output"
exit 1
fi
printf "[===] SUCCESS: Your local 'main' branch is now up to date with origin.\n"
sendScriptRanEvent true
exit 0