daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
d0811f
#!/bin/bash
d0811f
9e3166
process_u() {
9e3166
    if [ ! -z "${2##*[!0-9]*}" ]; then
9e3166
        # Single shared static ID.
9e3166
        echo "user($1) = $2"
9e3166
        echo "group($1) = $2"
9e3166
    elif [[ $2 == *:* ]]; then
9e3166
        # UID:<group>.
9e3166
        uid=$(echo $2 | cut -d':' -f1 -)
9e3166
        group=$(echo $2 | cut -d':' -f2 -)
9e3166
        if [ ! -z "${group##*[!0-9]*}" ]; then
9e3166
            # UID:GID.
9e3166
            echo "user($1) = ${uid}"
9e3166
            echo "group($1) = ${group}"
9e3166
        else
9e3166
            # UID:<groupname>.
9e3166
            echo "user($1) = ${uid}"
9e3166
            echo "group(${group})"
9e3166
        fi
9e3166
    else
9e3166
        # Dynamic (or something else uninteresting).
9e3166
        echo "user($1)"
9e3166
        echo "group($1)"
9e3166
    fi
9e3166
}
9e3166
9e3166
process_g() {
9e3166
    if [ ! -z "${2##*[!0-9]*}" ]; then
9e3166
        # Static GID.
9e3166
        echo "group($1) = $2"
9e3166
    else
9e3166
        # Dynamic (or something else uninteresting).
9e3166
        echo "group($1)"
9e3166
    fi
9e3166
}
9e3166
d0811f
parse() {
d0811f
    while read line; do
d0811f
        [ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue
d0811f
        line="${line## *}"
d0811f
        [ -z "$line" ] && continue
d0811f
        set -- $line
d0811f
        case "$1" in
d0811f
            ('u')
9e3166
                process_u "$2" "$3"
d0811f
                ;;
d0811f
            ('g')
9e3166
                process_g "$2" "$3"
d0811f
                ;;
d0811f
            ('m')
d0811f
                echo "user($2)"
d0811f
                echo "group($3)"
d0811f
                ;;
d0811f
        esac
d0811f
    done
d0811f
}
d0811f
d0811f
while read fn; do
d0811f
    parse < "$fn"
d0811f
done