arashster Posted July 13, 2013 Report Share Posted July 13, 2013 #/bin/shkillall -9 btsyncrm btsyncwget $1 -O download.tar.gztar -xzvf download.tar.gzrm download.tar.gz./btsyncSave the file as btupdater in the same directory as your btsync executableRunchmod +x btupdater to allow executionTo use, pass of the location of the latest btsync tar.gz file as the first argument.ex../btupdater http://syncapp.bittorrent.com/1.1.33/btsync_x64-1.1.33.tar.gzI 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. Quote Link to comment Share on other sites More sharing options...
sts Posted July 13, 2013 Report Share Posted July 13, 2013 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". Quote Link to comment Share on other sites More sharing options...
arashster Posted July 14, 2013 Author Report Share Posted July 14, 2013 Good point. Quote Link to comment Share on other sites More sharing options...
arashster Posted July 14, 2013 Author Report Share Posted July 14, 2013 Maybe I'll add a sleep timer, i.e. wait 5 seconds after "killall btsync" and then do a "killall -9 btsync". How long does btsync usually take to shut down gracefully? Quote Link to comment Share on other sites More sharing options...
sts Posted July 14, 2013 Report Share Posted July 14, 2013 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 -lIf thats =1 btsync has been shutdown. Quote Link to comment Share on other sites More sharing options...
arashster Posted July 14, 2013 Author Report Share Posted July 14, 2013 What if btsync becomes a zombie? Quote Link to comment Share on other sites More sharing options...
sts Posted July 15, 2013 Report Share Posted July 15, 2013 Did that ever happen to you ? But ps tells you if it's a zombie or not. You can check it if you want it, but I doubt that it will be neccessary. Quote Link to comment Share on other sites More sharing options...
Swisstengu Posted July 15, 2013 Report Share Posted July 15, 2013 Hello,Instead of the killall, it may be better to use some init-script. I did this one on my Debian computers/servers:#!/bin/sh# Largely adapted from xdm's init script:# Copyright 1998-2002, 2004, 2005 Branden Robinson <branden@debian.org>.# Copyright 2006 Eugene Konev <ejka@imfi.kspu.ru>### BEGIN INIT INFO# 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.### END INIT INFODAEMON=/usr/local/bin/btsyncCONFIG=/etc/default/btsyncDAEMON_OPTS="--config ${CONFIG}"STARTAS=<username>case $1 instart)su -c "${DAEMON} ${DAEMON_OPTS}" $STARTAS;;stop)kill $(cat /tmp/btsync.pid);;*)echo 'Usage: start|stop';;esac# End of fileSmarter, and this allows Sync to start on boot .The equivalent for Gentoo computer:#!/sbin/runscriptdepend() {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/btsync.pid)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:#/bin/shif [ $# -ne 2 ]; thenecho 'Please provide architecture and version'exit 1fiarch=$1version=$2url="http://syncapp.bittorrent.com/1.1.33/btsync_${arch}-${version}.tar.gz"wget $url -O /tmp/download.tar.gztar -xzvf /tmp/download.tar.gz -C /usr/local/bin/ || (echo 'ERROR: unable to download' && exit 2)service btsync stoprm -f /tmp/download.tar.gzservice btsync startCheers,C. Quote Link to comment Share on other sites More sharing options...
Swisstengu Posted July 15, 2013 Report Share Posted July 15, 2013 By the way, it's maybe even better to download from the generic link:http://btsync.s3-website-us-east-1.amazonaws.com/btsync_x64.tar.gzThis 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.Cheers,C. Quote Link to comment Share on other sites More sharing options...
Syl Posted July 15, 2013 Report Share Posted July 15, 2013 You should update url like this:url="http://syncapp.bittorrent.com/${version}/btsync_${arch}-${version}.tar.gz"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 else echo version ${version} not found. fiMy script. I don't pass the arch because it never really changes, just edit the script.#/bin/sharch="i386"if [ -z $# ]; then echo ./btupdater [version] exit 1fiurl="http://syncapp.bittorrent.com/$1/btsync_$arch-$1.tar.gz"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 1fiecho -e "killing process\c"while [ `ps aux | grep btsync | wc -l` -ne 1 ]; do echo -e ".\c" killall btsync sleep 1doneecho .wget --quiet $url -O - | tar -xz./btsync Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.