mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
Use regexes to relax matches when updating xmpp hostname.
This commit is contained in:
parent
6d3c39d166
commit
079d774476
30
actions/xmpp
30
actions/xmpp
@ -25,6 +25,7 @@ import argparse
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
||||||
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
||||||
@ -80,9 +81,10 @@ def subcommand_change_hostname(arguments):
|
|||||||
lines = conffile.readlines()
|
lines = conffile.readlines()
|
||||||
with open(JWCHAT_CONFIG, 'w') as conffile:
|
with open(JWCHAT_CONFIG, 'w') as conffile:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
conffile.write(line.replace(
|
if re.match(r'\s*var\s+SITENAME', line):
|
||||||
'var SITENAME = "' + old_hostname + '";',
|
conffile.write('var SITENAME = "' + new_hostname + '";')
|
||||||
'var SITENAME = "' + new_hostname + '";'))
|
else:
|
||||||
|
conffile.write(line)
|
||||||
else:
|
else:
|
||||||
print('Skipping configuring jwchat hostname: %s not found'
|
print('Skipping configuring jwchat hostname: %s not found'
|
||||||
% JWCHAT_CONFIG)
|
% JWCHAT_CONFIG)
|
||||||
@ -94,13 +96,13 @@ def subcommand_change_hostname(arguments):
|
|||||||
in_hosts_section = False
|
in_hosts_section = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if in_hosts_section:
|
if in_hosts_section:
|
||||||
if line.startswith(' - "'):
|
if re.match(r'\s*-\s+"', line):
|
||||||
conffile.write(line.replace(old_hostname, new_hostname))
|
conffile.write(line.replace(old_hostname, new_hostname))
|
||||||
else:
|
else:
|
||||||
in_hosts_section = False
|
in_hosts_section = False
|
||||||
conffile.write(line)
|
conffile.write(line)
|
||||||
else:
|
else:
|
||||||
if line.startswith('hosts:'):
|
if re.match(r'\s*hosts:', line):
|
||||||
in_hosts_section = True
|
in_hosts_section = True
|
||||||
conffile.write(line)
|
conffile.write(line)
|
||||||
|
|
||||||
@ -113,7 +115,7 @@ def subcommand_change_hostname(arguments):
|
|||||||
in_pubsub_node = False
|
in_pubsub_node = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if in_roster:
|
if in_roster:
|
||||||
if line.startswith(' '):
|
if re.match(r'\s+', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"' + old_hostname + '">>',
|
'>>,<<"' + old_hostname + '">>',
|
||||||
'>>,<<"' + new_hostname + '">>'))
|
'>>,<<"' + new_hostname + '">>'))
|
||||||
@ -122,7 +124,7 @@ def subcommand_change_hostname(arguments):
|
|||||||
in_roster = False # check other cases below
|
in_roster = False # check other cases below
|
||||||
|
|
||||||
if in_pubsub_node:
|
if in_pubsub_node:
|
||||||
if line.startswith(' '):
|
if re.match(r'\s+', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
||||||
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
||||||
@ -130,33 +132,33 @@ def subcommand_change_hostname(arguments):
|
|||||||
else:
|
else:
|
||||||
in_pubsub_node = False # check other cases below
|
in_pubsub_node = False # check other cases below
|
||||||
|
|
||||||
if line.startswith('{passwd,'):
|
if re.match(r'\s*{passwd,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'">>,<<"' + old_hostname + '">>},<<"',
|
'">>,<<"' + old_hostname + '">>},<<"',
|
||||||
'">>,<<"' + new_hostname + '">>},<<"'))
|
'">>,<<"' + new_hostname + '">>},<<"'))
|
||||||
elif line.startswith('{private_storage,'):
|
elif re.match(r'\s*{private_storage,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"' + old_hostname + '">>,<<',
|
'>>,<<"' + old_hostname + '">>,<<',
|
||||||
'>>,<<"' + new_hostname + '">>,<<'))
|
'>>,<<"' + new_hostname + '">>,<<'))
|
||||||
elif line.startswith('{last_activity,'):
|
elif re.match(r'\s*{last_activity,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"' + old_hostname + '">>},',
|
'>>,<<"' + old_hostname + '">>},',
|
||||||
'>>,<<"' + new_hostname + '">>},'))
|
'>>,<<"' + new_hostname + '">>},'))
|
||||||
elif line.startswith('{roster,'):
|
elif re.match(r'\s*{roster,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"' + old_hostname + '">>,',
|
'>>,<<"' + old_hostname + '">>,',
|
||||||
'>>,<<"' + new_hostname + '">>,'))
|
'>>,<<"' + new_hostname + '">>,'))
|
||||||
in_roster = True
|
in_roster = True
|
||||||
elif line.startswith('{pubsub_state,'):
|
elif re.match(r'\s*{pubsub_state,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
||||||
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
||||||
elif line.startswith('{pubsub_node,'):
|
elif re.match(r'\s*{pubsub_node,', line):
|
||||||
dumpfile.write(line.replace(
|
dumpfile.write(line.replace(
|
||||||
',{<<"pubsub.' + old_hostname + '">>,<<',
|
',{<<"pubsub.' + old_hostname + '">>,<<',
|
||||||
',{<<"pubsub.' + new_hostname + '">>,<<').replace(
|
',{<<"pubsub.' + new_hostname + '">>,<<').replace(
|
||||||
'>>,<<"/home/' + old_hostname + '">>},',
|
'>>,<<"/home/' + old_hostname + '">>},',
|
||||||
'>>,<<"/home/' + new_hostname + '"..},'))
|
'>>,<<"/home/' + new_hostname + '">>},'))
|
||||||
in_pubsub_node = True
|
in_pubsub_node = True
|
||||||
else:
|
else:
|
||||||
dumpfile.write(line)
|
dumpfile.write(line)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user