Skip to content

Instantly share code, notes, and snippets.

@xZero707
Last active September 21, 2021 20:02

Revisions

  1. xZero707 revised this gist Sep 21, 2021. 1 changed file with 1 addition and 82 deletions.
    83 changes: 1 addition & 82 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -1,82 +1 @@
    #!/usr/bin/env sh
    # This script is recursive by default
    # Adapted from https://github.com/just-containers/s6-overlay/issues/146#issuecomment-256545379

    if [ $# -eq 0 ]; then
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    fi

    # Arguments. Simple handling.
    TARGET_PATH=${1:-}
    RECURSIVE=${2:-}
    OWNERSHIP=${3:-}
    FMODE=${4:-}
    DMODE=${5:-}

    # Always required
    if [ -z "${TARGET_PATH}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    # Always required
    if [ -z "${OWNERSHIP}" ]; then
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    fi

    # This is always required, regardless of target type, but it can be false to indicate only directory handling
    if [ -z "${FMODE}" ]; then
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    fi

    # Argument is here even though not implemented, for the sake of compatibility with skarnet/s6 fix-attrs.d
    if [ "${RECURSIVE}" = false ]; then
    echo "Warning: Disabling recursive mode is not supported yet"
    fi

    doChown() {
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi

    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi

    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    }

    doChmod() {
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi

    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi

    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    }

    doChown
    doChmod
    # Update: Development moved to separate repository https://github.com/N0rthernL1ghts/attr
  2. xZero707 revised this gist Feb 13, 2021. 1 changed file with 39 additions and 39 deletions.
    78 changes: 39 additions & 39 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,15 @@
    # Adapted from https://github.com/just-containers/s6-overlay/issues/146#issuecomment-256545379

    if [ $# -eq 0 ]; then
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    fi

    # Arguments. Simple handling.
    @@ -23,59 +23,59 @@ DMODE=${5:-}

    # Always required
    if [ -z "${TARGET_PATH}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    # Always required
    if [ -z "${OWNERSHIP}" ]; then
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    fi

    # This is always required, regardless of target type, but it can be false to indicate only directory handling
    if [ -z "${FMODE}" ]; then
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    fi

    # Argument is here even though not implemented, for the sake of compatibility with skarnet/s6 fix-attrs.d
    if [ "${RECURSIVE}" = false ]; then
    echo "Warning: Disabling recursive mode is not supported yet"
    echo "Warning: Disabling recursive mode is not supported yet"
    fi

    doChown() {
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi

    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi
    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi

    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi
    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    }

    doChmod() {
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi

    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi
    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi

    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    }

    doChown
  3. xZero707 revised this gist Feb 13, 2021. 1 changed file with 40 additions and 41 deletions.
    81 changes: 40 additions & 41 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,15 @@
    # Adapted from https://github.com/just-containers/s6-overlay/issues/146#issuecomment-256545379

    if [ $# -eq 0 ]; then
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    fi

    # Arguments. Simple handling.
    @@ -21,63 +21,62 @@ OWNERSHIP=${3:-}
    FMODE=${4:-}
    DMODE=${5:-}


    # Always required
    if [ -z "${TARGET_PATH}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    # Always required
    if [ -z "${OWNERSHIP}" ]; then
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    fi

    # This is always required, regardless of target type, but it can be false to indicate only directory handling
    if [ -z "${FMODE}" ]; then
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    fi

    # Argument is here even though not implemented, for the sake of compatibility with skarnet/s6 fix-attrs.d
    if [ "${RECURSIVE}" = false ]; then
    echo "Warning: Disabling recursive mode is not supported yet"
    echo "Warning: Disabling recursive mode is not supported yet"
    fi

    doChown() {
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi

    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi
    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi

    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi
    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    }

    doChmod() {
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi

    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi
    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi

    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    }

    doChown
    doChmod
    doChmod
  4. xZero707 revised this gist Feb 13, 2021. 1 changed file with 62 additions and 11 deletions.
    73 changes: 62 additions & 11 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,83 @@
    #!/usr/bin/env sh
    # This script is recursive by default
    # Adapted from https://github.com/just-containers/s6-overlay/issues/146#issuecomment-256545379

    # Arguments
    if [ $# -eq 0 ]; then
    echo "No arguments supplied"
    echo ""
    echo "Usage: "
    echo " attr /path/to true||false root||root:root 0777||false [0777||false]"
    echo "Example: "
    echo " attr /path/to true root:root 0777 0777"
    echo ""
    echo "Script is recursive by default, and recursion cannot be disabled (not implemented)"
    exit 1
    fi

    # Arguments. Simple handling.
    TARGET_PATH=${1:-}
    OWNERSHIP=${2:-}
    FMODE=${3:-}
    DMODE=${4:-}
    RECURSIVE=${2:-}
    OWNERSHIP=${3:-}
    FMODE=${4:-}
    DMODE=${5:-}


    # Always required
    if [ -z "${TARGET_PATH}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    # Always required
    if [ -z "${OWNERSHIP}" ]; then
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    fi

    # This is always required, regardless of target type, but it can be false to indicate only directory handling
    if [ -z "${FMODE}" ]; then
    echo "InvalidArgumentError: Missing target path"
    echo "InvalidArgumentError: Missing file chmod"
    exit 1
    fi

    if [ -z "${DMODE}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    # Argument is here even though not implemented, for the sake of compatibility with skarnet/s6 fix-attrs.d
    if [ "${RECURSIVE}" = false ]; then
    echo "Warning: Disabling recursive mode is not supported yet"
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    chmod -R "${FMODE}" "${TARGET_PATH}"
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    doChown() {
    if [ "${OWNERSHIP}" = false ]; then
    return 0
    fi

    if [ "${FMODE}" = false ]; then
    find "${TARGET_PATH}" -type d -exec chown "${OWNERSHIP}" {} \;
    return $?
    fi

    if [ -f "${TARGET_PATH}" ]; then
    chown "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    return $?
    }

    doChmod() {
    if [ "${FMODE}" = false ] && [ "${DMODE}" = false ]; then
    return 0
    fi

    if [ -f "${TARGET_PATH}" ] && [ "${FMODE}" != false ]; then
    chmod "${FMODE}" "${TARGET_PATH}"
    return $?
    fi

    if [ "${DMODE}" != false ]; then
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
    fi
    }

    doChown
    doChmod
  5. xZero707 revised this gist Feb 8, 2021. 1 changed file with 29 additions and 5 deletions.
    34 changes: 29 additions & 5 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,32 @@
    #!/usr/bin/env sh
    # This script is recursive by default

    OWNERSHIP=${1:-}
    CHMOD=${2:-}
    TARGET=${3:-}
    # Arguments
    TARGET_PATH=${1:-}
    OWNERSHIP=${2:-}
    FMODE=${3:-}
    DMODE=${4:-}

    chown -hR "${OWNERSHIP}" "${TARGET}"
    chmod -R "${CHMOD}" "${TARGET}"
    if [ -z "${TARGET_PATH}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    if [ -z "${OWNERSHIP}" ]; then
    echo "InvalidArgumentError: Missing ownership"
    exit 1
    fi

    if [ -z "${FMODE}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    if [ -z "${DMODE}" ]; then
    echo "InvalidArgumentError: Missing target path"
    exit 1
    fi

    chown -hR "${OWNERSHIP}" "${TARGET_PATH}"
    chmod -R "${FMODE}" "${TARGET_PATH}"
    find "${TARGET_PATH}" -type d -exec chmod "${DMODE}" {} \;
  6. xZero707 created this gist Feb 8, 2021.
    8 changes: 8 additions & 0 deletions attr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/usr/bin/env sh

    OWNERSHIP=${1:-}
    CHMOD=${2:-}
    TARGET=${3:-}

    chown -hR "${OWNERSHIP}" "${TARGET}"
    chmod -R "${CHMOD}" "${TARGET}"