Last active
November 28, 2019 07:33
-
-
Save egeneralov/365b2d614cb8821c4c73edcd7f857fd5 to your computer and use it in GitHub Desktop.
upgrade your gitlab instance correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import re | |
| import subprocess | |
| result = subprocess.check_output("/usr/bin/dpkg --status gitlab-ce".split()) | |
| current_version = re.findall(r"Version: (.*)", result)[0].split('-')[0] | |
| print("# Current version: {}".format(current_version)) | |
| command = 'apt-cache madison gitlab-ce' | |
| regex = r' gitlab-ce \| (.*)-ce.0 \| .*' | |
| output = subprocess.check_output(command.split()) | |
| all_versions = re.findall(regex, output.decode()) | |
| versions_to_upgrade = [] | |
| for version in all_versions: | |
| if version == current_version: | |
| break | |
| versions_to_upgrade.append(version) | |
| versions_to_upgrade.reverse() | |
| versions = {} | |
| for version in versions_to_upgrade: | |
| all = re.findall(r'(\w+)\.(\w+)\.(\w+)', version)[0] | |
| major = int(all[0]) | |
| minor = int(all[1]) | |
| bugfix = int(all[2]) | |
| if major not in versions.keys(): | |
| versions[major] = {} | |
| if minor not in versions[major].keys(): | |
| versions[major][minor] = [] | |
| versions[major][minor].append(bugfix) | |
| for major in versions.keys(): | |
| for minor in versions[major].keys(): | |
| print( | |
| "apt-get install -yq gitlab-ce={}.{}.{}-ce.0".format( | |
| major, | |
| minor, | |
| versions[major][minor][0] | |
| ) | |
| ) | |
| print( | |
| "apt-get install -yq gitlab-ce={}.{}.{}-ce.0".format( | |
| major, | |
| minor, | |
| versions[major][minor][-1] | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment