Last active 1749444410

swee revised this gist 1749444409. Go to revision

1 file changed, 59 insertions

roundcubeupdate.py(file created)

@@ -0,0 +1,59 @@
1 + # How to run
2 + # python3 roundcubeupdate.py
3 + #
4 + # You may need to run as root or www-data
5 + #
6 + # sudo -u www-data python3 roundcubeupdate.py
7 + #
8 + # sudo python3 roundcubeupdate.py
9 +
10 + from tqdm import tqdm
11 + import requests
12 + import sys
13 + import os
14 + import tarfile
15 + print("Checking latest version...")
16 + req = requests.get("https://api.github.com/repos/roundcube/roundcubemail/releases/latest").json()
17 + latest = req["tag_name"]
18 + download = ""
19 + for asset in req["assets"]:
20 + if asset["name"] == f"roundcubemail-{latest}-complete.tar.gz":
21 + download = asset["browser_download_url"]
22 +
23 + print(f"Latest: {latest}")
24 + print(f"Download Exists: {download != ''}")
25 +
26 + try:
27 + current = open("/var/www/roundcube/index.php").read().split("Version ")[1].split(" ")[0]
28 + except:
29 + current = 0
30 + print(f"Current: {current if current != 0 else 'Not installed!'}")
31 + if current == 0:
32 + sys.exit(1)
33 + if current == latest:
34 + print("No need to update.")
35 + sys.exit()
36 +
37 + print("Downloading latest version...")
38 +
39 + response = requests.get(download, stream=True)
40 +
41 + total_size = int(response.headers.get("content-length", 0))
42 + block_size = 1024
43 +
44 + os.mkdir("roundcube.part")
45 +
46 + with tqdm(total=total_size, unit="B", unit_scale=True, leave=False) as progress_bar:
47 + with open("roundcube.part/rc.tar.gz", "wb") as file:
48 + for data in response.iter_content(block_size):
49 + progress_bar.update(len(data))
50 + file.write(data)
51 +
52 + file = tarfile.open('roundcube.part/rc.tar.gz')
53 + file.extractall('./roundcube.part')
54 + file.close()
55 +
56 + os.chdir("roundcube.part")
57 + os.system(f"./roundcubemail-{latest}/bin/installto.sh -y /var/www/roundcube")
58 + os.chdir("..")
59 + os.system("rm -r roundcube.part")
Newer Older