Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created April 5, 2024 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmolveau/e2f07ef9a652ea2c5699826f6cb1b536 to your computer and use it in GitHub Desktop.
Save gmolveau/e2f07ef9a652ea2c5699826f6cb1b536 to your computer and use it in GitHub Desktop.
linuxserver.io lsiown script (extracted with `docker run --rm -it ghcr.io/linuxserver/baseimage-ubuntu:jammy cat /usr/bin/lsiown`)
#!/bin/bash
MAXDEPTH=("-maxdepth" "0")
OPTIONS=()
while getopts RcfvhHLP OPTION
do
if [[ "${OPTION}" != "?" && "${OPTION}" != "R" ]]; then
OPTIONS+=("-${OPTION}")
fi
if [[ "${OPTION}" = "R" ]]; then
MAXDEPTH=()
fi
done
shift $((OPTIND - 1))
OWNER=$1
IFS=: read -r USER GROUP <<< "${OWNER}"
if [[ -z "${GROUP}" ]]; then
printf '**** Permissions could not be set. Group is missing or incorrect, expecting user:group. ****\n'
exit 0
fi
ERROR='**** Permissions could not be set. This is probably because your volume mounts are remote or read-only. ****\n**** The app may not work properly and we will not provide support for it. ****\n'
PATH=("${@:2}")
/usr/bin/find "${PATH[@]}" "${MAXDEPTH[@]}" \( ! -group "${GROUP}" -o ! -user "${USER}" \) -exec chown "${OPTIONS[@]}" "${USER}":"${GROUP}" {} + || printf "${ERROR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment