Shell script I wrote to update btsync on linux/unix


Recommended Posts

killall -9 btsync
rm btsync
wget $1 -O download.tar.gz
tar -xzvf download.tar.gz
rm download.tar.gz

Save the file as btupdater in the same directory as your btsync executable


chmod +x btupdater

to allow execution

To use, pass of the location of the latest btsync tar.gz file as the first argument.



I wonder, could btsync be used to update itself with a new binary?

Assuming all your btsync daemons are running the same architecture, could you sync the actual executable folder and replace the executable on one and it will replace on all the others?

I'm not a professional scripter or anything.

Link to comment
Share on other sites

Just a side not: Is there a reason why you use key code 9 instead of the default one? This is not a smooth shutdown and in my cases btsync wants to reindex the whole collection after another restart which can be quite time-consuming. I would just consider "killall btsync".

Link to comment
Share on other sites

Personally I would not hard code a possible maximum time that depends on your system and especially on your system load. Make an endless loop with a sleep inside and check whether btsync has been shutdown or not. For example you can check the amount of 'btsync' in the process table:

ps aux | grep btsync | wc -l

If thats =1 btsync has been shutdown.

Link to comment
Share on other sites


Instead of the killall, it may be better to use some init-script. I did this one on my Debian computers/servers:

# Largely adapted from xdm's init script:
# Copyright 1998-2002, 2004, 2005 Branden Robinson <>.
# Copyright 2006 Eugene Konev <>
# Provides: btsync
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop the SLiM daemon.
DAEMON_OPTS="--config ${CONFIG}"
case $1 in
kill $(cat /tmp/
echo 'Usage: start|stop'
# End of file

Smarter, and this allows Sync to start on boot :).

The equivalent for Gentoo computer:


depend() {
use net

start() {
ebegin "Starting btsync"
su -c "/usr/local/bin/btsync --config /etc/btsync.json" <username>
eend $?

stop() {
ebegin "Stopping btsync"
kill $(cat /tmp/
eend $?

With the location, you may as well use this command line for tar:

tar zxp <archive> -C /usr/local/bin/

As for the URL, it may be better to fix it in the script, and just pass arch and version as arguments.

Modified script would look like:

if [ $# -ne 2 ]; then
echo 'Please provide architecture and version'
exit 1
wget $url -O /tmp/download.tar.gz
tar -xzvf /tmp/download.tar.gz -C /usr/local/bin/ || (echo 'ERROR: unable to download' && exit 2)
service btsync stop
rm -f /tmp/download.tar.gz
service btsync start



Link to comment
Share on other sites

By the way, it's maybe even better to download from the generic link:

This way, you just have to provide the architecture, and Voilà. Some md5sum check would be of some use in order to not stop btsync for nothing.

This would mean:

- uncompress in some temporary directory

- md5sum of the newly downloaded btsync binary, compare it with the current one

- IF md5sum aren't the same, do the update

- ELSE discard the update, and try it again the next day.

That said… the best way would be to have distro packages (.deb, .rpm, .ebuild and so on) in order to get a fully system integrated update.



Link to comment
Share on other sites

You should update url like this:


I also did a similar script, I added a small test to check the url:

test_url=`curl -Is $url | head -n 1 | sed -r 's/.* ([0-9]*) .*/\1/'`
if [ "$test_url" = "200" ]; then
wget $url -O - | tar -xvz
echo version ${version} not found.

My script. I don't pass the arch because it never really changes, just edit the script.



if [ -z $# ]; then
echo ./btupdater [version]
exit 1

test_url=`curl --silent -Is $url | head -n 1 | sed -r 's/.* ([0-9]*) .*/\1/'`

if [ "$test_url" != "200" ]; then
echo version $1 not found.
exit 1

echo -e "killing process\c"
while [ `ps aux | grep btsync | wc -l` -ne 1 ]; do
echo -e ".\c"
killall btsync
sleep 1
echo .

wget --quiet $url -O - | tar -xz


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.