-
Notifications
You must be signed in to change notification settings - Fork 0
/
applyPatch.py
executable file
·61 lines (38 loc) · 1.33 KB
/
applyPatch.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
#!/usr/bin/env python
import paramiko
import sys
import urllib
usage = '''
Execute the script with this parameters port for ssh connection.
host port user password patchnumber
'''
if len(sys.argv) < 5:
print usage
sys.exit()
host = str(sys.argv[1])
port = int(sys.argv[2])
user = str(sys.argv[3])
password = str(sys.argv[4])
patch = int(sys.argv[5])
github_url = 'http://github.com/owncloud/core/pull/'
urllib.urlretrieve ("{0}{1}.patch".format(github_url,patch), "{0}.patch".format(patch))
transport = paramiko.Transport((host, port))
transport.connect(username = user, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
filepath = '/opt/owncloud/{0}.patch'.format(patch)
localpath = './{0}.patch'.format(patch)
sftp.put(localpath, filepath)
sftp.close()
transport.close()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=user, password=password, port=port)
#PATCH IS NOT INSTALLED IN THE DOCKERS BY DEFAULT
stdin, stdout, stderr = ssh.exec_command("apt-get update && apt-get install patch")
output = stdout.readlines()
for line in output:
print line
stdin, stdout, stderr = ssh.exec_command("cd /opt/owncloud && patch -p1 < {0}.patch".format(patch))
output = stdout.readlines()
for line in output:
print line