Linux 下 Dropbox 的通用更新脚本修改版 – 支持代理
Felix Yan | 2010-08-06 | 576 views
源脚本来自 http://forums.dropbox.com/topic.php?id=12153, 但是不能支持代理服务器, 主要问题是它的”联网检测”用的是ping, Felix将其改成了wget然后判断页面上是否有forums
Patch 如下:
--- a/dbupdate +++ b/dbupdate @@ -37,7 +37,7 @@ declare -r useCount="http://bit.ly/dbupdate_count"; declare -r nIcon="/usr/share/icons/hicolor/64x64/apps/dropbox.png"; declare -r userAgent="Mozilla/5.0 (X11; U; Linux i686; $LANG; rv:1.9.1.3) Gecko/20090924 Ubuntu/9.10 (karmic) Firefox/3.5.3"; -declare -r internetTest="ping -c3 -w10 www.dropbox.com | grep -c '64 bytes'" ; +declare -r internetTest="wget -qO - http://www.dropbox.com | grep -c 'forums'" ; bit="auto"; testing=0; q="-q"; @@ -292,7 +292,7 @@ #test connectivity printf "Checking for connectivity to Dropbox servers..."; -if [ `eval $internetTest` -lt 3 ]; then { +if [ `eval $internetTest` -lt 1 ]; then { echo " FAIL."; echo "Failed to connect to \"www.dropbox.com\""; exit 1;
以下是修改后完整的 0.2.17 版的脚本:
#!/bin/bash #Originally authored by Dusten Barker. Originally created on 07sep09. #Thanks to contributions by Herbert S., Udi M., Olivier G., Darren S., and Luke S. of #the Dropbox Forums, and to Andy Piper of http://andypiper.co.uk! # GNU LGPL Notice # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Dropbox <http://www.dropbox.com> is a proprietary cross-platform backup and # syncing software, currently available for Linux, Mac OSX, and MS Windows. # # dbupdate <http://forums.dropbox.com/topic.php?id=12153> is a script written # to automatically upgrade the experimental build of Dropbox, which does not # provide a software upgrade option such as found within the stable builds. # # dbupdate makes use of portions of the Dropbox project to function, such as the # dropbox executable binary and its graphics. # Please feel free to leave comments, bug reports, suggestions, and polite # criticisms about this script in the Dropbox Forums thread pertaining to # this script. #init declare -r ver="0.2.17"; declare -r verdate="25jul10"; declare -r useCount="http://bit.ly/dbupdate_count"; declare -r nIcon="/usr/share/icons/hicolor/64x64/apps/dropbox.png"; declare -r userAgent="Mozilla/5.0 (X11; U; Linux i686; $LANG; rv:1.9.1.3) Gecko/20090924 Ubuntu/9.10 (karmic) Firefox/3.5.3"; declare -r internetTest="wget -qO - http://www.dropbox.com | grep -c 'forums'" ; bit="auto"; testing=0; q="-q"; unset altInst; unset tmpDir; unset bitVer; unset curVer; unset newVer; unset newFile; unset getFile; unset fVer; unset delay; unset pstring; unset noUseCheck; unset pstring; unset tmpStr; unset root; unset notifier; unset check; unset upgrade; unset overwriteIcons; unset limit; unset iscript; unset lock; _displayOpt () #help screen { echo; echo "Dropbox Updater v"$ver"-"$verdate", written by Dusten Barker."; echo "USAGE: dbupdate OPTION..."; echo "Option \"-b auto\" is implied by default unless otherwise specified."; echo "ex: \"dbupdate -gb32 -f0.7.28\""; echo "ex: \"dbupdate -nud 45s\""; echo; echo " Options:"; echo " -b 32, 64, or auto"; echo " 32 use 32 bit Dropbox version"; echo " 64 use 64 bit Dropbox version"; echo " auto automatically determine 32 or 64 bit; default"; echo " -c check if update is available"; echo " -d TIME delay for TIME; ex: 30s, 2m, &c..."; echo " -f force version, implies -u"; echo " -g use graphical download progress indicator"; echo " -h display this screen"; echo " -i HOURS install, requires su/sudo/root"; echo " 0 remove cronjob and install, place dbupdate in path"; echo " #>0 number of hours to wait between update checks"; echo " -l RATE limit bandwidth to RATE; ex: 320k, 1.2m, &c..."; echo " -n use notifier, if installed (/usr/bin/notify-send)"; echo " -o overwrite icons, do not preserve"; echo " -r allow use as root user"; echo " -u perform update. implies -c unless -f"; echo " -x do not send use count"; echo; } _checkExit () #check exit status { if [ ! $? -eq 0 ]; then { echo "Error $? returned."; echo "Aborting."; exit 2; } fi; } _compareVer () #two-dot comparator script-foo { unset _compareVerGT; unset _compareVerLT; unset ver1Maj; unset ver1Min; unset ver1Pat; unset ver2Maj; unset ver2Min; unset ver2Pat; ver1Maj="$(echo $1 | cut -d'.' -f1)"; ver1Min="$(echo $1 | cut -d'.' -f2)"; ver1Pat="$(echo $1 | cut -d'.' -f3)"; ver2Maj="$(echo $2 | cut -d'.' -f1)"; ver2Min="$(echo $2 | cut -d'.' -f2)"; ver2Pat="$(echo $2 | cut -d'.' -f3)"; if [ $ver1Pat -ne $ver2Pat ]; then if [ $ver1Pat -gt $ver2Pat ]; then { _compareVerGT=$1; _compareVerLT=$2; } else { _compareVerGT=$2; _compareVerLT=$1; } fi; fi; if [ $ver1Min -ne $ver2Min ]; then if [ $ver1Min -gt $ver2Min ]; then { _compareVerGT=$1; _compareVerLT=$2; } else { _compareVerGT=$2; _compareVerLT=$1; } fi; fi; if [ $ver1Maj -ne $ver2Maj ]; then if [ $ver1Maj -gt $ver2Maj ]; then { _compareVerGT=$1; _compareVerLT=$2; } else { _compareVerGT=$2; _compareVerLT=$1; } fi; fi; if [ $1 = $2 ]; then { _compareVerGT=$1; _compareVerLT=0; }; fi; } _installdbupdate () #install script to path and control cron job { tmpStr="dbupdate" if [ $iscript -eq 0 ]; then { if [ ! -d "/usr/share/dbupdate" ]; then { mkdir /usr/share/dbupdate ; _checkExit; } fi; if [ ! -d "/usr/share/dbupdate/dbupdate$ver" ]; then { mkdir /usr/share/dbupdate/dbupdate$ver ; _checkExit; } fi; cp $0 /usr/share/dbupdate/dbupdate$ver/ ; _checkExit; chmod +x /usr/share/dbupdate/dbupdate$ver/$(basename $0) ; _checkExit; ln -fs /usr/share/dbupdate/dbupdate$ver/$(basename $0) /usr/bin/dbupdate ; _checkExit; sed -i "/$tmpStr/d" /etc/crontab; } fi; if [ $iscript -ne 0 ]; then { if [ ! $SUDO_USER ]; then SUDO_USER=root; fi; sed -i "/$tmpStr/d" /etc/crontab; echo "0 */$1 * * * $SUDO_USER if [ -e /usr/bin/dbupdate ]; then export DISPLAY=:0.0; dbupdate -nu; fi;" >> /etc/crontab } fi; } _dbVer () #get version of current dropbox install { if [ ! -f ~/.dropbox-dist/VERSION ]; then { echo "FAIL!"; echo "Dropbox version not detected. Aborting."; exit 1; } else { read curVer < ~/.dropbox-dist/VERSION ; } fi; } _notify () #notify-osd, if present { if [ $notifier ]; then { if [ -e "/usr/bin/notify-send" -a -e $nIcon ]; then { if [ "$1" = "upgrade" ]; then { eval "/usr/bin/notify-send -i $nIcon 'Upgrade complete.' 'dbupdate has upgraded Dropbox on this computer to v"$newVer"'" ; _checkExit; } fi; if [ "$1" = "check" ]; then { eval "/usr/bin/notify-send -i $nIcon 'Upgrade available.' 'dbupdate has found an available Dropbox upgrade to v"$newVer"'" ; _checkExit; } fi; if [ "$1" = "checkupgrade" ]; then { eval "/usr/bin/notify-send -i $nIcon 'Upgrade available.' 'dbupdate has found an available Dropbox upgrade to v"$newVer" and is downloading it now.'" ; _checkExit; } fi; } fi; } fi; } _bitAutodetect () #detect for 64bit or 32bit installed dropbox { if [ -d ~/.dropbox-dist/ncrypt*linux-x86_64.egg/ ]; then { bit=64; } else if [ -d ~/.dropbox-dist/ncrypt*linux-i686.egg/ ]; then { bit=32; } else if [ $(uname -m) == "i386" ] || [ $(uname -m) == "i586" ] || [ $(uname -m) == "i686" ]; then { bit=32; } else if [ $(uname -m) == "x86_64" ]; then { bit=64; } else { echo " FAIL."; echo "Try forcing architecture with \"-b\"."; exit 1; } fi; fi; fi; fi; } # ------------------------- main ------------------------------ if [ "$1" == "moo" ]; then { echo "You're wrong if you think I have super cow powers."; exit 0; } fi; #check if already running printf "Getting file lock..."; lock="/tmp/$(basename $0).LCK"; exec 8>$lock; #send to handler 8 if flock -n -e 8; then : else { echo " FAIL."; echo "Cannot lock $0. Aborting."; exit 1; } fi; echo " Done."; #gather options from command line and set flags if [ $# -eq 0 ]; then echo "Use \"$0 -h\" for usage and help."; exit 0; fi; #display message and quit if no command line arguments found while getopts uchxnrgoi:f:t:d:b:l: opt do { case "$opt" in b) if [ "$OPTARG" = "32" ]; then bit=$OPTARG; else if [ "$OPTARG" = "64" ]; then bit=$OPTARG; else if [ "$OPTARG" = "auto" ]; then bit=$OPTARG; else { echo "The -b option argument \"$OPTARG\" is invalid."; echo "Use \"$0 -h\" for usage and help."; exit 1; } fi; fi; fi;; d) delay=$OPTARG;; u) upgrade=1; check=1;; c) check=1;; h) _displayOpt; exit 0;; t) notifier=1; #test option for notifier - hidden flag _notify $OPTARG; exit 0;; x) noUseCheck=1;; n) notifier=1;; f) fVer=$OPTARG; upgrade=1;; l) limit="--limit-rate="$OPTARG;; i) iscript=$OPTARG;; o) overwriteIcons=1;; g) if [ -e "/usr/bin/zenity" ]; then pstring="2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --auto-close --title='dbupdate - Dropbox...' "; unset q; else echo "Cannot use progress indicator."; fi;; r) root=1;; \?) echo "Use \"$0 -h\" for usage and help."; exit 1;; esac; } done; shift `expr $OPTIND - 1`; #check root; if [ ! $iscript ] && [ ! $root ]; then { if [ $EUID -eq 0 ]; then { echo "dbupdate only requires root during install-type procedures."; echo "If you require use by root user, force with the \"-r\" option."; exit 1; } fi; } fi; if [ $root ] && [ $EUID -ne 0 ]; then { echo "You can not use \"-r\" flag unless you are root."; exit 1; } fi; #delay, if any if [ $delay ]; then { printf "Waiting for $delay..."; sleep $delay; _checkExit; echo " Done."; } fi; #test for or create temporary space if [ $check ] || [ $fVer ]; then { printf "Looking for temporary space..."; tmpDir=`mktemp -d` ; _checkExit; if [ -d $tmpDir ]; then { echo " Created."; } else { echo "FAIL."; echo; echo "Could not create $tmpDir"; exit 1; } fi; } fi; #self-install if [ $iscript ] && [ ! $EUID -eq 0 ]; then { echo "You must be root to use the \"-i\" option."; exit 1; } fi; if [ $iscript ]; then { printf "Installing dbupdate..."; _installdbupdate $iscript; echo " Done."; exit 0; } fi; #check for alternate install printf "Checking for alternate install..."; if [ -e ~/.dropbox-alt/dropbox ]; then { echo " Found."; altInst=1; } else { echo " Not found."; } fi; #test connectivity printf "Checking for connectivity to Dropbox servers..."; if [ `eval $internetTest` -lt 1 ]; then { echo " FAIL."; echo "Failed to connect to \"www.dropbox.com\""; exit 1; } fi; echo " Done."; #autodetect 32 or 64 bit dropbox install if [ "$bit" = "auto" ]; then { printf "Detecting Dropbox architecture..."; _bitAutodetect; printf " Done."; } else { printf "Forcing Dropbox architechture... Done."; } fi; if [ $bit = 32 ]; then { bitVer=""; echo " (32bit)"; } fi; if [ $bit = 64 ]; then { bitVer="_64"; echo " (64bit)"; } fi; #determine currently installed version if [ $check ] && [ ! $fVer ]; then { printf "Checking currently installed version..."; _dbVer; echo " Done. ($curVer)"; } fi; #see if forced version if [ $fVer ]; then newVer=$fVer; curVer="0.0.0"; else { #if not forced version, CHECK for latest version if [ $check ]; then { printf "Checking for update..."; newVer1=`wget -q --tries=3 -O - www.dropbox.com/release_notes/rss.xml | xpath -q -e "//channel/item[1]/title" | sed "s@<\([^<>][^<>]*\)>\([^<>]*\)</\1>@\2@g" | sed -e "y/\t/ /;s/ *$//;s/^.* //"`; #sanity test; check for expected output format if [ ! $(echo $newVer1 | tr -dc '.' | wc -c) -eq 2 ] || [ $(echo $newVer1 | awk '{print gsub("[0-9]", "")}') -le 3 ]; then { echo " FAIL."; exit 1; } fi; echo " Done."; if [ ! $noUseCheck ]; then { eval "wget -q $limit --referer='http://dbupdate_use_count/$ver' --user-agent='$userAgent' -O /dev/null $useCount"; } fi; _compareVer $newVer1 $curVer; newVer=$_compareVerGT; if [ $_compareVerLT = 0 ]; then { echo "$curVer is the latest available version. Update not required."; exit 0; } fi; if [ ! $upgrade ]; then { echo "Dropbox v$curVer can be updated to v$newVer"; _notify check; exit 0; } fi; _notify checkupgrade; } fi; } fi; #preserve icons if [ ! $overwriteIcons ]; then { _compareVer $curVer 0.8.55; if [ $_compareVerGT = $curVer ]; then { printf "Backing up icons..."; mkdir $tmpDir/backupIcons ; _checkExit; if [ -d ~/.dropbox-dist/icons/ ]; then { cp -r ~/.dropbox-dist/icons/* $tmpDir/backupIcons ; _checkExit; echo " Done."; } else { echo "Does not exist. Skipping."; unset overwriteIcons; } fi; } fi; } fi; #download upgrade if [ $upgrade ]; then { printf "Downloading update. This may take a few minutes..."; newFile="dropbox-lnx.x86"$bitVer"-"$newVer".tar.gz" ; getFile="http://dl.dropbox.com/u/17/"$newFile ; eval "wget $q $limit --referer='http://dbupdate' --user-agent='$userAgent' -O $tmpDir/$newFile $getFile $pstring &" ; _checkExit; i=1 sp="/-\|" echo -n ' '; while pgrep wget &>/dev/null; do { printf "\b${sp:i++%${#sp}:1}" ; sleep 0.25; } done; echo -e "\b Done"; while [ $testing -eq 0 ]; do { sleep 0.5s; if [ -z "$(pidof zenity)" ]; then { pkill wget; testing=1; if [ ! $? -eq 0 ]; then { echo "Operation cancelled."; exit 1; } fi; } fi; } done; #check download #printf "Verify download..."; if [ ! -e $tmpDir/$newFile ] || [ $(stat -c%s "$tmpDir/$newFile") -le 10000 ]; then { echo " Verify download FAIL."; exit 1; } fi; #echo " Done."; #install upgrade if [ -e /usr/bin/dropbox ]; then { printf "Stopping Dropbox..."; killall -q dropbox; #_checkExit; sleep 1; killall -q dropbox; #_checkExit; sleep 1; echo " Done."; } fi; printf "Installing Dropbox $newVer..."; rm -fr ~/.dropbox-dist ; _checkExit; tar xzf $tmpDir/$newFile -C ~/ ; _checkExit; echo " Done."; #restore icons if [ ! $overwriteIcons ] && [ -d $tmpDir/backupIcons ]; then { printf "Restoring previous icons..."; cp -r $tmpDir/backupIcons/* ~/.dropbox-dist/icons ; _checkExit; echo " Done."; } fi; #install alternate if [ $altInst ]; then { printf "Updating alternate install..."; cp -r ~/.dropbox-dist ~/.dropbox-alt ; _checkExit; echo " Done."; } fi; #start Dropbox printf "Starting Dropbox..."; if [ -e /usr/bin/dropbox ]; then { ~/.dropbox-dist/dropbox start & echo " Done."; } else { ~/.dropbox-dist/dropboxd start -i & echo " Done."; } fi; if [ $altInst ]; then { #start alt printf "Starting alternate Dropbox..."; ~/.dropbox-alt/dropbox start & echo " Done."; } fi; #finish _notify upgrade; echo "Complete."; } fi; rm $lock




请问楼主脚本是更新dropbox用的吗?如何使用,我刚安装dropbox for linux 不太懂
是更新到最新测试版用的..因此您可以不用尝试….
推介各位嘗試SugarSync,功能跟Dropbox一樣。
而且沒有被大陸封鎖。(Dropbox已被大陸封鎖了)
注冊及安裝鏈接,可直接增加500MB空間。
https://www.sugarsync.com/referral?rf=d776qx56sv3nx
SugarSync貌似没有Linux下的客户端,所以我就不考虑了:)
另外请问,SugarSync有保存文件每次修改的版本的功能吗?