diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-06-16 16:06:04 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-06-16 16:15:16 +0200 |
commit | b8b00563546dc4d94db4a2602fc9be873f2436e1 (patch) | |
tree | c76ffc7e62fda765eafaa7662dd4628b9b767050 | |
parent | 50257eca2476d80d5d50f099be285d2c2cb0f1ad (diff) | |
download | matterbridge-b8b00563546dc4d94db4a2602fc9be873f2436e1.tar.gz matterbridge-b8b00563546dc4d94db4a2602fc9be873f2436e1.tar.bz2 matterbridge-b8b00563546dc4d94db4a2602fc9be873f2436e1.zip |
generate-matterbridge-config.py: rework password replacement logic
This fixes the netrc hostnames that weren't real hostnames.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r-- | README.txt | 4 | ||||
-rwxr-xr-x | generate-matterbridge-config.py | 49 |
2 files changed, 33 insertions, 20 deletions
@@ -83,8 +83,8 @@ in the current directory or in ~/.netrc. The netrc file should have lines that looks like that (with different passwords): -machine irc.liberachat password Hdrgdx7dRkHsPO16UgS8rkzP8lHgJQ/O1qSsHqGBtnUkC1/g -machine irc.OFTC password jsRb4dmIAx7cgfr0EfkGqINcqs9Duq7JRfHkvKDSetezi7oxKqefOB +machine irc.libera.chat password Hdrgdx7dRkHsPO16UgS8rkzP8lHgJQ/O1qSsHqGBtnUkC1/gxZl +machine irc.oftc.net password jsRb4dmIAx7cgfr0EfkGqINcqs9Duq7JRfHkvKDSetezi7oxKqefOB You will then be able to generate the matterbridge.toml with the following command: diff --git a/generate-matterbridge-config.py b/generate-matterbridge-config.py index 47f181b..19bcdc7 100755 --- a/generate-matterbridge-config.py +++ b/generate-matterbridge-config.py @@ -14,10 +14,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. import os + +import toml import netrc -example = open('matterbridge.toml.example', 'r') -generated = open('matterbridge.toml', 'w') +example_file = open('matterbridge.toml.example', 'r') +example_toml = toml.load(example_file) +example_file.close() # We use the netrc standard to store password. This way, when the template file # is updated, we can automatically generate the resulting matterbridge.toml for @@ -28,25 +31,35 @@ password_files_paths = [ os.environ['HOME'] + os.sep + '.netrc', ] +data = {} +for name in example_toml['irc']: + data[name] = { + 'username' : example_toml['irc'][name]['Nick'], + 'address' : example_toml['irc'][name]['Server'].split(':')[0], + } + for password_file_path in password_files_paths: password_file = netrc.netrc(password_file_path) - hackint_entry = password_file.authenticators('irc.hackint') - liberachat_entry = password_file.authenticators('irc.liberachat') - oftc_entry = password_file.authenticators('irc.OFTC') - if hackint_entry == None: - continue - if liberachat_entry == None: - continue - if oftc_entry == None: - continue + found_all_entries = True + for name in data: + entry = password_file.authenticators(data[name]['address']) + if entry == None: + found_all_entries = False + continue + + data[name]['login'] = entry[0] + data[name]['password'] = entry[2] - hackint_password = hackint_entry[2] - liberachat_password = liberachat_entry[2] - oftc_password = oftc_entry[2] + if not found_all_entries: + continue - for line in example: - line = line.replace('HACKINT-PASSWORD', hackint_password) - line = line.replace('LIBERACHAT-PASSWORD', liberachat_password) - line = line.replace('OFTC-PASSWORD', oftc_password) + example_file = open('matterbridge.toml.example', 'r') + generated = open('matterbridge.toml', 'w') + for line in example_file: + for name in data: + dummy_password = name.upper() + '-PASSWORD' + password = data[name]['password'] + line = line.replace(dummy_password, password) generated.write(line) + generated.close() |