roundcubeupdate.py
· 1.6 KiB · Python
Исходник
# How to run
# python3 roundcubeupdate.py
#
# You may need to run as root or www-data
#
# sudo -u www-data python3 roundcubeupdate.py
#
# sudo python3 roundcubeupdate.py
from tqdm import tqdm
import requests
import sys
import os
import tarfile
print("Checking latest version...")
req = requests.get("https://api.github.com/repos/roundcube/roundcubemail/releases/latest").json()
latest = req["tag_name"]
download = ""
for asset in req["assets"]:
if asset["name"] == f"roundcubemail-{latest}-complete.tar.gz":
download = asset["browser_download_url"]
print(f"Latest: {latest}")
print(f"Download Exists: {download != ''}")
try:
current = open("/var/www/roundcube/index.php").read().split("Version ")[1].split(" ")[0]
except:
current = 0
print(f"Current: {current if current != 0 else 'Not installed!'}")
if current == 0:
sys.exit(1)
if current == latest:
print("No need to update.")
sys.exit()
print("Downloading latest version...")
response = requests.get(download, stream=True)
total_size = int(response.headers.get("content-length", 0))
block_size = 1024
os.mkdir("roundcube.part")
with tqdm(total=total_size, unit="B", unit_scale=True, leave=False) as progress_bar:
with open("roundcube.part/rc.tar.gz", "wb") as file:
for data in response.iter_content(block_size):
progress_bar.update(len(data))
file.write(data)
file = tarfile.open('roundcube.part/rc.tar.gz')
file.extractall('./roundcube.part')
file.close()
os.chdir("roundcube.part")
os.system(f"./roundcubemail-{latest}/bin/installto.sh -y /var/www/roundcube")
os.chdir("..")
os.system("rm -r roundcube.part")
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") |
60 |