fix invalid formatting of input variable

This commit is contained in:
David Hiendl 2023-12-05 15:17:23 +01:00
parent 475087811c
commit 0450511708

View File

@ -16,41 +16,37 @@ runs:
steps: steps:
- shell: bash - shell: bash
run: | run: |
echo "::debug:: Starting docket-fix-socket-perm A" echo "Starting docket-fix-socket-perm A"
- shell: bash - shell: bash
run: | run: |
echo "Starting docket-fix-socket-perm B" echo "Starting docket-fix-socket-perm B"
- shell: bash
run: |
echo "Starting docket-fix-socket-perm C"
echo "::debug:: Starting docket-fix-socket-perm D"
SOCK_OWNER_GID=$(stat -c %g ${{ inputs.socket-path }}) SOCK_OWNER_GID=$(stat -c %g ${{ inputs.socket-path }})
echo "::debug:: ${{ inputs.socket-path }} is owned by gid=$SOCK_OWNER_GID" echo "${{ inputs.socket-path }} is owned by gid=$SOCK_OWNER_GID"
RUNNING_AS_USER=$(whoami) RUNNING_AS_USER=$(whoami)
echo "::debug:: ${{ running as user: $RUNNING_AS_USER }}" echo "running as user: $RUNNING_AS_USER"
SUDO_PREFIX="" SUDO_PREFIX=""
if [[ "$RUNNING_AS_USER" != "root" ]]; then if [[ "$RUNNING_AS_USER" != "root" ]]; then
echo "::debug:: current user is not sudo, assuming sudo is required" echo "current user is not sudo, assuming sudo is required"
SUDO_PREFIX="sudo" SUDO_PREFIX="sudo"
fi fi
if getent group $SOCK_OWNER_GID | grep -q "$RUNNING_AS_USER"; then if getent group $SOCK_OWNER_GID | grep -q "$RUNNING_AS_USER"; then
echo "::debug:: User is already a member of $SOCK_OWNER_GID" echo "User is already a member of $SOCK_OWNER_GID"
exit 0 exit 0
fi fi
if grep -q -E ":$SOCK_OWNER_GID:" /etc/group; then if grep -q -E ":$SOCK_OWNER_GID:" /etc/group; then
echo "::debug:: Group for gid=$SOCK_OWNER_GID already exists, adding user to it" echo "Group for gid=$SOCK_OWNER_GID already exists, adding user to it"
$SUDO_PREFIX usermod -aG $(getent group $SOCK_OWNER_GID | cut -d: -f1) $RUNNING_AS_USER $SUDO_PREFIX usermod -aG $(getent group $SOCK_OWNER_GID | cut -d: -f1) $RUNNING_AS_USER
exit 0 exit 0
fi fi
echo "::debug:: Group for gid=$SOCK_OWNER_GID does not exist, creating workaround group: ${{ input.workaround-group }}" echo "Group for gid=$SOCK_OWNER_GID does not exist, creating workaround group: ${{ input.workaround-group }}"
$SUDO_PREFIX groupadd -g $SOCK_OWNER_GID ${{ input.workaround-group }} $SUDO_PREFIX groupadd -g $SOCK_OWNER_GID ${{ input.workaround-group }}
echo "::debug:: Group for gid=$SOCK_OWNER_GID created" echo "Group for gid=$SOCK_OWNER_GID created"
echo "::debug:: Adding user to workaround group: ${{ input.workaround-group }}" echo "Adding user to workaround group: ${{ input.workaround-group }}"
$SUDO_PREFIX usermod -aG ${{ input.workaround-group }} $RUNNING_AS_USER $SUDO_PREFIX usermod -aG ${{ input.workaround-group }} $RUNNING_AS_USER
echo "::debug:: Added user to workaround group" echo "Added user to workaround group"