Browse code

Add saltstack-driven-system-upgrades.

1 1
new file mode 100755
... ...
@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+codename='sid'
3
+salt -C "G@lsb_distrib_codename:${codename}" -b 1 cmd.run 'git -C /opt/diff-so-fancy pull; ionice -c3 nice -n 19 apt update && ionice -c3 nice -n 19 apt full-upgrade -d -y'
0 4
new file mode 100755
... ...
@@ -0,0 +1,66 @@
1
+#!/usr/bin/env python
2
+import subprocess
3
+import pipes
4
+import json
5
+import sys
6
+import os
7
+import re
8
+
9
+CODENAME='sid'
10
+REVIEW_CMD=['apt', 'full-upgrade']
11
+UPGRADE_CMD=['apt', 'full-upgrade', '-y']
12
+
13
+def make_remote_command(cmd):
14
+	return ' '.join([pipes.quote(token) for token in cmd])
15
+
16
+def get_candidate_hosts():
17
+	remote_command = make_remote_command(REVIEW_CMD)
18
+	command = ['salt', '--output=json', '--static', '-G', 'lsb_distrib_codename:%s' % CODENAME, 'cmd.run', remote_command]
19
+	try:
20
+		raw_output = subprocess.check_output(command)
21
+	except subprocess.CalledProcessError as cpe:
22
+		# So what, punk?
23
+		raw_output = cpe.output
24
+	json_output = json.loads(raw_output)
25
+	return json_output
26
+
27
+def get_hosts_to_actually_upgrade():
28
+	hosts_to_actually_upgrade = []
29
+	json_output = get_candidate_hosts()
30
+	sorted_hosts = json_output.keys()
31
+	sorted_hosts.sort()
32
+	for host in sorted_hosts:
33
+		print host + ':'
34
+		lines = json_output[host].split('\n')
35
+		for line in lines[:-1]:
36
+			if line:
37
+				rem = re.search('apt does not have a stable CLI interface', line)
38
+				if not rem:
39
+					print '    ' + line
40
+		sys.stdout.write('    Do you want to continue? [y/N] ')
41
+		reply = raw_input().lower()
42
+		if reply == 'y':
43
+			hosts_to_actually_upgrade.append(host)
44
+	return hosts_to_actually_upgrade
45
+
46
+def upgrade(hosts):
47
+	if hosts:
48
+		remote_command = make_remote_command(UPGRADE_CMD)
49
+		command = ['salt', '-L', ','.join(hosts), '-b', '1', 'cmd.run', remote_command, 'env={"DEBIAN_FRONTEND": "noninteractive"}']
50
+		print command
51
+		os.execvp('salt', command)
52
+
53
+def main():
54
+	hosts_to_actually_upgrade = get_hosts_to_actually_upgrade()
55
+	if hosts_to_actually_upgrade:
56
+		print ''
57
+		print 'The following hosts are about to be upgraded:'
58
+		for host in hosts_to_actually_upgrade:
59
+			print '    - %s' % host
60
+		sys.stdout.write('Go? [y/N] ')
61
+		reply = raw_input().lower()
62
+		if reply == 'y':
63
+			upgrade(hosts_to_actually_upgrade)
64
+
65
+if __name__ == '__main__':
66
+	main()
0 67
new file mode 100755
... ...
@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+codename='sid'
3
+salt -C "G@lsb_distrib_codename:${codename}" -b 2 cmd.run 'apt autoremove --purge -y'
0 4
new file mode 100755
... ...
@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+codename='sid'
3
+salt -C "G@lsb_distrib_codename:${codename}" -b 2 cmd.run 'apt clean'
0 4
new file mode 100755
... ...
@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+for codename in jessie stretch; do
3
+	salt -C "G@lsb_distrib_codename:${codename}" -b 1 pkg.upgrade dist_upgrade=True
4
+	salt -C "G@lsb_distrib_codename:${codename}" -b 2 cmd.run 'git -C /opt/diff-so-fancy pull'
5
+done