mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-05 15:57:23 +01:00
initial commit of some preliminary notes
This commit is contained in:
37
tools/editconf.py
Executable file
37
tools/editconf.py
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys, re
|
||||
|
||||
# sanity check
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: python3 editconf.py /etc/file.conf NAME=VAL [NAME=VAL ...]")
|
||||
sys.exit(1)
|
||||
|
||||
# parse command line arguments
|
||||
filename = sys.argv[1]
|
||||
settings = sys.argv[2:]
|
||||
|
||||
# create the new config file in memory
|
||||
found = set()
|
||||
buf = ""
|
||||
for line in open(filename):
|
||||
for i in range(len(settings)):
|
||||
name, val = settings[i].split("=", 1)
|
||||
if re.match("\s*" + re.escape(name) + "\s*=", line):
|
||||
buf += "#" + line
|
||||
if i in found: break # we've already set the directive
|
||||
buf += name + "=" + val + "\n"
|
||||
found.add(i)
|
||||
break
|
||||
else:
|
||||
# did not match any setting name
|
||||
buf += line
|
||||
|
||||
for i in range(len(settings)):
|
||||
if i not in found:
|
||||
buf += settings[i] + "\n"
|
||||
|
||||
# Write out the new file.
|
||||
with open(filename, "w") as f:
|
||||
f.write(buf)
|
||||
|
||||
26
tools/get_ubuntu_ami.py
Normal file
26
tools/get_ubuntu_ami.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import sys, json, re
|
||||
|
||||
# Arguments:
|
||||
region, version, arch, instance_type = sys.argv[1:]
|
||||
|
||||
# Read bytes from stdin.
|
||||
dat = sys.stdin.read()
|
||||
|
||||
# Be flexible. The Ubuntu AMI list is invalid JSON by having a comma
|
||||
# following the last element in a list.
|
||||
dat = re.sub(r",(\s*)\]", r"\1]", dat)
|
||||
|
||||
# Parse JSON.
|
||||
dat = json.loads(dat)
|
||||
|
||||
for item in dat["aaData"]:
|
||||
if item[0] == region and item[2] == version and item[3] == arch and item[4] == instance_type:
|
||||
ami_link = item[6]
|
||||
|
||||
# The field comes in the form of <a href="...">ami-id</a>
|
||||
ami_link = re.sub(r"<.*?>", "", ami_link)
|
||||
|
||||
print(ami_link)
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user