From 475087811c106e35073b83d86a33381bc5c9f135 Mon Sep 17 00:00:00 2001 From: David Hiendl Date: Tue, 5 Dec 2023 15:15:27 +0100 Subject: [PATCH] fix formatting --- action.yml | 86 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/action.yml b/action.yml index a3eb2e7..f2400e1 100644 --- a/action.yml +++ b/action.yml @@ -2,53 +2,55 @@ name: 'docker-fix-socket-perm' description: 'fix docker host socket permissions' inputs: - socket-path: - required: true - description: "location of the docker socket" - default: '/var/run/docker.sock' - workaround-group: - required: true - description: "name of the workaround group to be created (if necessary)" - default: 'hostdocker' + socket-path: + required: true + description: "location of the docker socket" + default: '/var/run/docker.sock' + workaround-group: + required: true + description: "name of the workaround group to be created (if necessary)" + default: 'hostdocker' runs: - using: "composite" - steps: - - shell: bash - run: echo "::debug:: Starting docket-fix-socket-perm A" - - shell: bash - run: 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 }}) - echo "::debug:: ${{ inputs.socket-path }} is owned by gid=$SOCK_OWNER_GID" + using: "composite" + steps: + - shell: bash + run: | + echo "::debug:: Starting docket-fix-socket-perm A" + - shell: bash + run: | + 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 }}) + echo "::debug:: ${{ inputs.socket-path }} is owned by gid=$SOCK_OWNER_GID" - RUNNING_AS_USER=$(whoami) - echo "::debug:: ${{ running as user: $RUNNING_AS_USER }}" + RUNNING_AS_USER=$(whoami) + echo "::debug:: ${{ running as user: $RUNNING_AS_USER }}" - SUDO_PREFIX="" - if [[ "$RUNNING_AS_USER" != "root" ]]; then - echo "::debug:: current user is not sudo, assuming sudo is required" - SUDO_PREFIX="sudo" - fi + SUDO_PREFIX="" + if [[ "$RUNNING_AS_USER" != "root" ]]; then + echo "::debug:: current user is not sudo, assuming sudo is required" + SUDO_PREFIX="sudo" + fi - if getent group $SOCK_OWNER_GID | grep -q "$RUNNING_AS_USER"; then - echo "::debug:: User is already a member of $SOCK_OWNER_GID" - exit 0 - fi + if getent group $SOCK_OWNER_GID | grep -q "$RUNNING_AS_USER"; then + echo "::debug:: User is already a member of $SOCK_OWNER_GID" + exit 0 + fi - if grep -q -E ":$SOCK_OWNER_GID:" /etc/group; then - echo "::debug:: 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 - exit 0 - fi + if grep -q -E ":$SOCK_OWNER_GID:" /etc/group; then + echo "::debug:: 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 + exit 0 + fi - echo "::debug:: 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 }} - echo "::debug:: Group for gid=$SOCK_OWNER_GID created" + echo "::debug:: 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 }} + echo "::debug:: Group for gid=$SOCK_OWNER_GID created" - echo "::debug:: Adding user to workaround group: ${{ input.workaround-group }}" - $SUDO_PREFIX usermod -aG ${{ input.workaround-group }} $RUNNING_AS_USER - echo "::debug:: Added user to workaround group" + echo "::debug:: Adding user to workaround group: ${{ input.workaround-group }}" + $SUDO_PREFIX usermod -aG ${{ input.workaround-group }} $RUNNING_AS_USER + echo "::debug:: Added user to workaround group"