/usr/share/ofono/scripts/activate-context is in ofono-scripts 1.21-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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  | #!/usr/bin/python3
import sys
import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager')
if (len(sys.argv) == 3):
	modem = sys.argv[1]
	context_idx = int(sys.argv[2]) - 1
else:
	modem = None
	modems = manager.GetModems()
	for path, properties in modems:
		if "org.ofono.ConnectionManager" in properties["Interfaces"]:
			modem = path
			break
	if (modem is None):
		exit(2)
	if (len(sys.argv) == 1):
		context_idx = 0
	elif (len(sys.argv) == 2):
		context_idx = int(sys.argv[1]) - 1
	else:
		print("Usage: %s [modem] [context_number]" % (sys.argv[0]))
		exit(1)
modemapi = dbus.Interface(bus.get_object('org.ofono', modem), 'org.ofono.Modem')
properties = modemapi.GetProperties()
if "org.ofono.ConnectionManager" not in properties["Interfaces"]:
	print("org.ofono.ConnectionManager not found")
	exit(2)
connman = dbus.Interface(bus.get_object('org.ofono', modem),
				'org.ofono.ConnectionManager')
contexts = connman.GetContexts()
if (len(contexts) == 0):
	print("No context available")
	exit(1)
connman.SetProperty("Powered", dbus.Boolean(1))
path = contexts[context_idx][0]
context = dbus.Interface(bus.get_object('org.ofono', path),
				'org.ofono.ConnectionContext')
try:
	context.SetProperty("Active", dbus.Boolean(1), timeout = 100)
except dbus.DBusException as e:
	print("Error activating %s: %s" % (path, str(e)))
	exit(2)
 |