Btsync Installer Script For Linux

Recommended Posts

BTSync Installer Script for Linux
I'm posting here an installer script for Bittorrent Sync for linux. There are several out there, but this one was created for a few specific reasons:
  • This script would work on multiple linux distros. Packages have been made for debian/ubuntu by tuxpoldo, however there isn't a very good solution for Fedora, OpenSUSE (I believe an rpm exists for OpenSUSE, but I can't remember for sure), or other distros.
  • No automatic solution currently creates a systemd service for autmomatically starting BTSync on startup.
  • Few solutions allows for an easy install, uninstall, or upgrade (a notable exception is tuxpoldo's work, and it only works on debian/ubuntu based distros).
This script was created to be generic, and run on any distro that supports systemd (the only reason it only supports systemd is that I don't yet have an idea about making an rc script and detecting between normal init and systemd. Contributions for that are very welcome).
How to use the script:
  • Ensure you are running a Linux Distro which is using systemd!
  • Execute the script using the following command as a normal user.
    sh ./
  • Ensure that no other instances of btsync are present on the system. There could be conflicts.

    Use the script as a normal user. Do not run the script as root unless you have a very specific reason to do so.
  • The script creates a shortcut under either "Internet" or "Applications" depending on your system. It will load the default browser to check on the BTSync instance.
  • The script automatically starts BTSync on startup by creating a service (using the user who installed it), and starting it up immediately.
  • There is no password for using the web interface, you can set one up though.
  • Ensure that you install, upgrade, or remove BTSync with the same user who performed any other operations with this script. Don't run the script as a user, and use the remove function as root. It will not work.
Technical Detail of the Script:
  • Install Mode: Checks to see if BTSync exists already. If it does not, it will get the BTsync tarball from the web, install it in /usr/local/bin, create a systemd service and run it, and create a configuration in ~/.sync/sync.conf in your home folder. It will also create a shortcut and icon in your application menu (shortcut and icon is taken from tuxpoldo's work on Github, see here:
  • Upgrade Mode: It only gets a version of BTSync specified in the URL fields, and replaces the version in /usr/local/bin. It doesn't do anything else.
  • Remove Mode: It stops and removes the systemd service, removes the binary in /usr/local/bin, removes the shortcuts and icons, and at your discretion will remove your configuration.
  • Currently the script only works with a computer that has systemd. I tested the script on Fedora, OpenSUSE, and Debian (specifically the Siduction distribution, which had systemd running on it). It wouldn't be a tremendous effort to get it to run on sysvinit, but I'd need some help with the script in order to implement that. I can also have it run on other init systems (like Upstart), if I get some hints about how to make a service.
  • The script runs as a normal user. This is to make the permissions of using and accessing locations through BTSync the same as the user's permissions. This can lead to odd behavior on mounted drives, which may need root permissions to access the contents. Make sure mounted drives are owned by your user, or at least give permissions for your user to read and write.
  • Right now the URL's this script uses are hardcoded to a specific version of BTSync. Can anyone provide links to the linux versions which always point to the latest version of BTSync? Either that or some hints about how to detect the version number and insert it into the url would be helpful. Otherwise, you'll have to manually replace the URL when a new version comes out.
The readme (much the same as this post) can be seen here:
Enjoy! Any feedback is appreciated.

Share this post

Link to post
Share on other sites


BTSync Installer Script for Linux
  • Right now the URL's this script uses are hardcoded to a specific version of BTSync. Can anyone provide links to the linux versions which always point to the latest version of BTSync? Either that or some hints about how to detect the version number and insert it into the url would be helpful.

As tuxpoldo said, Great work!


I have been using a free program called Ketarin to look at web pages that point to software installers and find which ones have new version numbers. Ketarin lets me set a regular expression that will match a pattern within the web page and extract the version number with something like this:

Latest Stable Version: ([_\.\d-]+)

(For those less familiar with regular expressions, the [_\.\d-]+ matches any string of digits, dots, underscores and hyphens,

and the () around the square brackets returns that into a variable for the version number.)

Ketarin then compares the version number with what it saw last time, and if they are different, downloads the installer. 


This gave me the idea to look up the standard download page for BTSync, ( and I found that the entry for i386 Linux contains this line:


<a href="/sync/downloads/complete/os/i386_glibc" class="dl-link" onclick="_gaq.push(['_trackEvent','BT-Production', 'btsync-downloads-Click-i386GlibcClientLink', 'DEFAULT']);">Linux i386(glibc 2.3)</a>


Could your script use wget to download that page into a file, perhaps called source.html.

Then you could run that file through perl with a program on the command line that includes a pattern like this to extract the version number and put it in the variable "version":

version=$(perl -ne 'print $1 if s/.*Linux i386.glibc 2.3.<.a>.*<span>([\.\d]+)<.span>.*/\1/;' source.html)

On my system, this puts 1.2.82 into the variable "version".


Your download version variables could then be set with

You could do similar searches for the other kinds of Linux systems, in case any of them lag behind in version number.


This should work while just the version numbers in the download page change. But if the structure of the page changes, then you will have to change the patterns that you search for in setting the "version" variable.


Hope that helps, Jim

Share this post

Link to post
Share on other sites

Thanks guys for your feedback!


JimH44, thanks for your suggestion. I used Ketarin for a long time, but I never really pieced together how people used it to check versions of programs on the web. Now that you mention this process, it seems obvious  :) . I myself am still coming to grips with regular expressions, so the pattern recognition you've given helps tremendously...


In any case, I've implemented your idea in my script, and updated it on github. I did end up using wget to snag a copy of the html, and used your one-line perl script to dump the version number into the URL (pretty much the way you have it). I'll play around with the regular expression later, since I'm sure the Linux i386 glibc 2.3 version might not always be the same as the others. Also as you say, if they change the webpage in any way, I can easily see this script breaking. But until a better method comes around, this will do  :D .



Share this post

Link to post
Share on other sites

I wonder if this has been updated to include the new DL URL btsyncdownurl= ?


Otherwise would it be OK if I edited your work and reposted?


I haven't updated the script to be modern (I admit, I haven't been enthused lately to use btsync on Linux). Definitely feel free to go ahead and edit the script and repost. In fact, if you do modify the script, I would also appreciate if you sent me a pull request on GitHub to incorporate any changes you make into my original script.

Share this post

Link to post
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.