ryantimwilson / rpms / systemd

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