Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save petergi/b772377c72cdcfaccc512b5ed5e268ac to your computer and use it in GitHub Desktop.

Select an option

Save petergi/b772377c72cdcfaccc512b5ed5e268ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Check ownership and permissions of a file
function checkPermissions() {
file="$1"
expectedOwner="$2"
expectedPermissions="$3"
expectedUid=`id -u "$expectedOwner"`
uid=`stat -f "%u" "$file"`
permissions=`stat -f "%Sp" "$file"`
if [ "$uid" -ne "$expectedUid" ]; then
return -1
fi
if [ "$permissions" != "$expectedPermissions" ]; then
return -1
fi
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment