def add_user_to_groups(uname, grpstr, groups=["lsst_lcl", "jovyan"]):
    """Take a user name (a string) and a base group file (as a string) and
    inject the user into the appropriate groups, given in the groups
    parameter (defaults to 'lsst_lcl' and 'jovyan').  Returns a string."""
    glines = grpstr.split("\n")
    g_str = ""
    for grp in glines:
        s_line = grp.strip()
        if not s_line:
            continue
        grpname = s_line.split(":")[0]
        if grpname in groups:
            if s_line.endswith(":"):
                s_line = s_line + uname
            else:
                s_line = s_line + "," + uname
        g_str = g_str + s_line + "\n"
    return g_str