Skip to content

Instantly share code, notes, and snippets.

@juliusknorr
Created June 15, 2023 14:37
Show Gist options
  • Save juliusknorr/cde77e7f6804bea139ff91ca3f31fe54 to your computer and use it in GitHub Desktop.
Save juliusknorr/cde77e7f6804bea139ff91ca3f31fe54 to your computer and use it in GitHub Desktop.
Smalls script to get etags for debugging sync issues
#!/bin/bash
NC_USER=admin
NC_PASSWORD=admin
NC_URL="http://$NC_USER:[email protected]"
SUBDIR="${1:-}"
echo "=> Parent etags"
dirnames() {
local input
local parent
input="$1"
if [[ "$input" == "" ]]
then
true
elif [[ "$input" == "." || "$input" == "/" ]]
then
printf '%s\n' "$input" #print the root node
else
#printf '%s\n' "$input" #print node (descending)
parent="$(dirname "$input")"
dirnames "$parent"
printf '%s\n' "$input" #print node (ascending)
fi
}
parse_response() {
HREFS=`echo $1 | grep -oE '<d:href>.*?</d:href>'`
ETAGS=`echo $1 | grep -oE '<d:getetag>.*?</d:getetag>'`
#HREFS=${HREFS%$'\n'*}
#ETAGS=${ETAGS%$'\n'*}
IFS=$'\n' HREFS=($HREFS)
IFS=$'\n' ETAGS=($ETAGS)
for i in "${!HREFS[@]}"; do
printf "%s - %s\n" "${HREFS[i]}" "${ETAGS[i]}" | sed -e 's/<[^>]*>//g' | sed -e 's/&quot;//g'
done
}
echo "=> Etags for $SUBDIR"
dirnames $SUBDIR | while read line ; do
RESULT_D0=`curl "$NC_URL/remote.php/dav/files/$NC_USER/$line" -X 'PROPFIND' -H 'Depth: 0' 2>/dev/null`
parse_response "${RESULT_D0}"
done
echo ""
exit 0
## The following is useful to compare etags depending on different depth
RESULT_D0=`curl "$NC_URL/remote.php/dav/files/$NC_USER/$SUBDIR" -X 'PROPFIND' -H 'Depth: 0' 2>/dev/null`
RESULT_D1=`curl "$NC_URL/remote.php/dav/files/$NC_USER/$SUBDIR" -X 'PROPFIND' -H 'Depth: 1' 2>/dev/null`
echo "=> Depth 0"
parse_response "${RESULT_D0}"
echo "=> Depth 1"
parse_response "${RESULT_D1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment