forked from cs50/codespace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update50.sh
37 lines (29 loc) · 977 Bytes
/
update50.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
#!/bin/bash
# Get remote JSON
remote=$(curl https://code.cs50.io/.devcontainer.json 2> /dev/null)
if [ $? -ne 0 ]; then
echo "Could not update codespace. Try again later."
exit 1
fi
# Parse remote JSON
image=$(echo $remote | jq .image 2> /dev/null)
regex='"ghcr.io/cs50/codespace:([0-9a-z]*)"'
if [[ "$image" =~ $regex ]]; then
tag="${BASH_REMATCH[1]}"
else
echo "Could not determine latest version. Try again later."
exit 1
fi
# Get local version
issue=$(tail -1 /etc/issue 2> /dev/null)
# Get local JSON
local=$(cat "/workspaces/$RepositoryName/.devcontainer.json" 2> /dev/null)
# If versions differ (or forcibly updating)
if [ "$remote" != "$local" ] || [ "$tag" != "$issue" ] || [ "$1" == "-f" ] || [ "$1" == "--force" ]; then
# Update JSON
echo "$remote" > "/workspaces/$RepositoryName/.devcontainer.json"
# Trigger rebuild
command50 github.codespaces.fullRebuildEnvironment
else
echo "Your codespace is already up-to-date!"
fi