-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkupdate.py
62 lines (53 loc) · 2.17 KB
/
checkupdate.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
# coding:utf-8
import requests
import os
def checkupdate():
version = requests.get('https://raw.githubusercontent.com/TravellerXi/OpenVpnWithWebControl/master/version/version')
#version.encoding('utf-8')
versionOnline = version.text.replace('.', '').replace('\n','')
with open('version/version', 'r') as f:
versionLocal = f.read()
versionLocal = versionLocal.replace('.', '')
if int(versionOnline) > int(versionLocal):
return(int(versionOnline))
else:
return(0)
def updateversion():
version=requests.get('https://raw.githubusercontent.com/TravellerXi/OpenVpnWithWebControl/master/version/version')
#version.encoding('utf-8')
versionOnline=version.text
versionOnlinecode=versionOnline.replace('.','').replace('\n','')
print (str(versionOnline))
versionlocal=''
with open ('version/version','r') as f:
versionLocal = versionlocal+f.read()
versionLocal=versionLocal.replace('.','').replace('\n','')
print('will print version local')
print(versionLocal)
print(type(versionLocal))
print('will print online version')
print(versionOnline)
print(type(versionOnline))
if versionOnlinecode>versionLocal:
setence2 = 'mkdir -p /openvpnbackup/'+versionLocal
print(setence2)
os.system(setence2)
setence3 = '\cp -R -f /openvpn/* /openvpnbackup/'+versionLocal+'/'
print(setence3)
os.system(setence3)
setence4 = 'rm -rf /openvpnbackup/'+ versionLocal+'/backup'+'/'
print(setence4)
os.system(setence4)
print('backup delete ok')
updateZip=requests.get('https://github.com/TravellerXi/OpenVpnWithWebControl/archive/master.zip')
with open ('master.zip','wb') as code:
code.write(updateZip.content)
os.system('unzip -o /openvpn/master.zip')
os.system('\cp -R -f /openvpn/OpenVpnWithWebControl-master/* /openvpn/')
os.system('rm -rf /openvpn/OpenVpnWithWebControl*')
os.system('rm -rf /openvpn/master.zip')
os.system('chmod +x /openvpn/*')
return 1
else:
return 0