Changeset 614fd92 in rattail-fabric2


Ignore:
Timestamp:
11/01/2022 06:41:27 PM (3 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
46440b6
Parents:
a2dca4e
Message:

Use shlex.join() when adding postfix alias

a bit convoluted perhaps, but still better...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail_fabric2/postfix.py

    ra2dca4e r614fd92  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2019 Lance Edgar
     5#  Copyright © 2010-2022 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    2525"""
    2626
     27import shlex
     28
    2729from rattail_fabric2 import apt
    2830
     
    4345    if c.run("grep '^{}:' /etc/aliases".format(name), warn=True).failed:
    4446        # append new entry
    45         c.sudo("""bash -c 'echo "{}: {}" >> /etc/aliases'""".format(name, alias_to))
     47        entry = '{}: {}'.format(name, alias_to)
     48        echo = shlex.join(['echo', entry])
     49        cmd = '{} >> /etc/aliases'.format(echo)
     50        cmd = shlex.join(['bash', '-c', cmd])
     51        c.sudo(cmd)
    4652    else:
    4753        # update existing entry
    48         c.sudo('sed -i.bak -e "s/^{}: .*/{}: {}/" /etc/aliases'.format(name, name, alias_to))
     54        alias_to = alias_to.replace('|', '\\|')
     55        sub = "s|^{}: .*|{}: {}|".format(name, name, alias_to)
     56        cmd = shlex.join(['sed', '-i.bak', '-E', sub, '/etc/aliases'])
     57        c.sudo(cmd)
    4958
    5059    c.sudo('newaliases')
Note: See TracChangeset for help on using the changeset viewer.