py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2013-05-31 21:04:49 +02:00
|
|
|
|
2016-07-31 03:01:37 +02:00
|
|
|
import os
|
2013-10-07 22:08:16 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2017-11-06 03:10:47 +01:00
|
|
|
import configparser
|
2013-11-01 00:00:30 +01:00
|
|
|
import re
|
2019-08-25 01:23:14 +02:00
|
|
|
from lib.zulip_tools import parse_os_release, assert_running_as_root
|
2018-11-15 10:56:25 +01:00
|
|
|
|
2018-11-19 19:50:25 +01:00
|
|
|
assert_running_as_root()
|
2018-12-06 20:37:46 +01:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
2013-10-07 22:08:16 +02:00
|
|
|
|
|
|
|
force = False
|
|
|
|
extra_args = sys.argv[1:]
|
|
|
|
|
|
|
|
if len(extra_args) and extra_args[0] in ('-f', '--force'):
|
|
|
|
force = True
|
2013-11-05 19:37:55 +01:00
|
|
|
extra_args = extra_args[1:]
|
2013-10-07 22:08:16 +02:00
|
|
|
|
2016-07-23 20:33:58 +02:00
|
|
|
config = configparser.RawConfigParser()
|
2013-11-01 00:00:30 +01:00
|
|
|
config.read("/etc/zulip/zulip.conf")
|
2013-10-07 22:08:16 +02:00
|
|
|
|
2020-05-20 22:42:10 +02:00
|
|
|
distro_info = parse_os_release()
|
2016-07-31 03:01:37 +02:00
|
|
|
if not os.path.exists("/etc/puppet/hiera.yaml"):
|
2019-08-25 01:23:14 +02:00
|
|
|
if (distro_info['ID'], distro_info['VERSION_ID']) in [('debian', '9'), ('ubuntu', '16.04')]:
|
2018-05-24 19:35:58 +02:00
|
|
|
# Suppress warnings in old puppet about hiera.yaml not existing.
|
2018-07-18 23:50:16 +02:00
|
|
|
open("/etc/puppet/hiera.yaml", "a").close()
|
2016-07-31 03:01:37 +02:00
|
|
|
|
2013-11-01 00:00:30 +01:00
|
|
|
puppet_config = """
|
|
|
|
Exec { path => "/usr/sbin:/usr/bin:/sbin:/bin" }
|
|
|
|
"""
|
|
|
|
|
|
|
|
for pclass in re.split(r'\s*,\s*', config.get('machine', 'puppet_classes')):
|
2013-11-01 20:28:03 +01:00
|
|
|
puppet_config += "include %s\n" % (pclass,)
|
2013-11-01 00:00:30 +01:00
|
|
|
|
2017-02-08 20:05:20 +01:00
|
|
|
# We use the puppet configuration from the same Zulip checkout as this script
|
2018-12-06 20:37:46 +01:00
|
|
|
scripts_path = os.path.join(BASE_DIR, "scripts")
|
|
|
|
puppet_module_path = os.path.join(BASE_DIR, "puppet")
|
2017-02-08 20:05:20 +01:00
|
|
|
puppet_cmd = ["puppet", "apply", "--modulepath", puppet_module_path, "-e", puppet_config]
|
2013-10-07 22:08:16 +02:00
|
|
|
puppet_cmd += extra_args
|
|
|
|
|
2018-12-06 20:37:46 +01:00
|
|
|
# Set the scripts path to be a factor so it can be used by puppet code
|
|
|
|
puppet_env = os.environ.copy()
|
|
|
|
puppet_env["FACTER_zulip_scripts_path"] = scripts_path
|
|
|
|
|
2020-05-20 22:42:10 +02:00
|
|
|
# This is to suppress puppet warnings with ruby 2.7.
|
|
|
|
if (distro_info['ID'], distro_info['VERSION_ID']) in [('ubuntu', '20.04')]:
|
|
|
|
puppet_env["RUBYOPT"] = "-W0"
|
|
|
|
|
2016-07-01 19:15:46 +02:00
|
|
|
if not force:
|
2018-12-06 20:37:46 +01:00
|
|
|
subprocess.check_call(puppet_cmd + ['--noop', '--show_diff'], env=puppet_env)
|
2016-07-01 19:15:46 +02:00
|
|
|
|
|
|
|
do_apply = None
|
|
|
|
while do_apply != 'y':
|
|
|
|
sys.stdout.write("Apply changes? [y/N] ")
|
2017-08-28 03:36:39 +02:00
|
|
|
sys.stdout.flush()
|
2016-07-01 19:15:46 +02:00
|
|
|
do_apply = sys.stdin.readline().strip().lower()
|
|
|
|
if do_apply == '' or do_apply == 'n':
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-12-06 20:37:46 +01:00
|
|
|
ret = subprocess.call(puppet_cmd + ['--detailed-exitcodes'], env=puppet_env)
|
2016-07-01 19:15:46 +02:00
|
|
|
# ret = 0 => no changes, no errors
|
|
|
|
# ret = 2 => changes, no errors
|
|
|
|
# ret = 4 => no changes, yes errors
|
|
|
|
# ret = 6 => changes, yes errors
|
|
|
|
if ret != 0 and ret != 2:
|
|
|
|
sys.exit(1)
|