Skip to content

Instantly share code, notes, and snippets.

@kmarius
Created July 12, 2019 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmarius/63076f502090010d543b5e1ff2b27377 to your computer and use it in GitHub Desktop.
Save kmarius/63076f502090010d543b5e1ff2b27377 to your computer and use it in GitHub Desktop.
#!/system/bin/sh
APIKEY=get this from syncthing config
# wait for service to start
retries=5
while ! curl -s -L -k -X GET -H "X-API-Key: $APIKEY" "http://localhost:8384/rest/system/ping"
do
sleep 1
if test $retries -eq 0; then
exit 100
fi
retries=$((retries-1))
done
# force rescan
curl -s -L -k -X POST -H "X-API-Key: $APIKEY" "http://localhost:8384/rest/db/scan"
# wait for completion
while
sleep 5
do
if ! curl -s -L -k -X GET -H "X-API-Key: $APIKEY" \
"http://localhost:8384/rest/system/ping"
then
exit 101
fi
if ! curl -s -L -k -X GET -H "X-API-Key: $APIKEY" \
"http://localhost:8384/rest/system/connections" \
| grep -q '"connected":.*true'
then
exit 102
fi
if curl -s -L -k -X GET -H "X-API-Key: $APIKEY" \
"http://localhost:8384/rest/events?events=FolderCompletion&limit=1&timeout=15" \
| grep -q '"completion":.*100'
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment