-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.py
33 lines (30 loc) · 955 Bytes
/
upgrade.py
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
# retrieve current sha & upgrade to latest release of coder/coder
import requests
import json
import os
def getSha():
# make API call
res = requests.get("https://api.github.com/repos/coder/coder/tags")
# convert JSON response to bytes
c = res.content
# deserialize JSON bytes to Python object
tags = json.loads(c)
# pull latest version sha
latest_sha = tags[0]['commit']['sha']
return latest_sha
# read file for previous sha
with open('sha.txt', 'r') as file:
current_sha = file.read().rstrip()
# compare previous sha to current sha
if current_sha != getSha():
# install latest version of coder
install = 'curl -L https://coder.com/install.sh | sh'
os.system(install)
# reload coder service
reload = 'sudo systemctl daemon-reload && sudo systemctl restart coder.service'
os.system(reload)
# write new sha to file
with open('sha.txt', 'w') as f:
print(getSha(), file=f)
else:
pass # do nothing