Last active
December 16, 2015 15:09
-
-
Save trustin/5453702 to your computer and use it in GitHub Desktop.
Simple shell script that generates a base64-encoded BitTorrent Sync secret with arbitrary length parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
SECRET_SIZE=128 | |
mkdir -p "$HOME/.local/tmp" | |
rm -f "$HOME/.local/tmp/btsync-secret".* | |
umask 0077 | |
SECRET_FILE="`mktemp "$HOME/.local/tmp/btsync-secret.XXXXXXXXXX"`" | |
echo -n "Generating a $SECRET_SIZE-byte secret " | |
head --bytes=$SECRET_SIZE /dev/random > "$SECRET_FILE" & | |
while true; do | |
CUR_SECRET_SIZE=`stat --format='%s' "$SECRET_FILE"` | |
if [[ $CUR_SECRET_SIZE -eq $SECRET_SIZE ]]; then | |
break | |
fi | |
sleep 1 | |
echo -n '.' | |
done | |
echo ' done' | |
# Encode first to Base32 and then to Base64 so that resulting secret looks pretty. | |
SECRET=`cat "$SECRET_FILE" | python -c "import sys;import base64; sys.stdout.write(base64.b32encode(sys.stdin.read()))"` | |
rm -f "$SECRET_FILE" | |
SECRET=`echo -n "$SECRET" | sed 's/=\+$//' | base64 -w 0 | sed 's/=\+$//'` | |
echo $SECRET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to use these longer secrets in mac os x or windows clients? I presume your generated secret is used by the btsync config files you write for linux?