Friday, November 14, 2014

Install Dropbox On CentOS (No GUI required)

This guide is designed for VPS owners who use CentOS 32-bit, or 64-bit.

Prerequisites

  • Architecture x86 (32-bit) or x86_64 (64-bit)
  • wget
  • vi (text editor)
  • Python 2.x
  • a web browser (on a PC you have access to)

Setup process

Install the latest dropbox linux distro

This ONLY installs for the current user. I would recommend root. But you are free to choose whatever user you want to have the dropbox user on the VPS.
  1. Check the version of CentOS you have:
    uname -m
  2. If you are on 32-bit CentOS: (i686)
    cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -
  3. If you are on 64-bit CentOS: (x86_64)
    cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

Run & Link your Dropbox Account

  1. Run the dropboxd application.
    ~/.dropbox-dist/dropboxd
  2. It will return repeatedly:
    "This computer isn't linked to any Dropbox account...
    Please visit https://www.dropbox.com/cli_link?host_id=(some code)" to link this device.
  3. Go to a browser window. (Doesn’t matter if it’s the same computer, can be your Windows PC.) Copy the link, paste it, and log into the dropbox account you want the account to be linked to.
  4. After your done logging in, a new folder will appear on the server’s user directory called “Dropbox”. Use ctrl+c to stop dropboxd for the next step.

Downloading the CLI interface from Dropbox

  1. If you do not have python (2.x) installed, you can do so with:
    yum install python
  2. Type the following to download & install the official dropbox.py script:
    mkdir -p ~/bin && wget -O ~/bin/dropbox.py "https://www.dropbox.com/download?dl=packages/dropbox.py" && chmod +x ~/bin/dropbox.py
  3. First you need to turn on dropbox:
    ~/bin/dropbox.py start
  4. If this is a server, you want to prevent lan broadcasting so you don’t get in trouble with your VPS provider:
    ~/bin/dropbox.py lansync n
  5. From here, you have to wait.. you can type this to see when dropbox is finished synchronizing all the data.
    ~/bin/dropbox.py status
    "Up to date"
  6. The steps below explain how to sync a specific folder(s), if you dont care about this, you can go straight to step 10. Before moving to the next step, it is important to know that putting files in your root directory of dropbox will clutter things, create a folder like “unsorted”, and put your files in there. (Note: Someone could add white list functionality to dropbox.py via github)
  7. After it says it’s up to date, you want to exclude everything:
    cd ~/Dropbox && ~/bin/dropbox.py exclude add *
  8. This will show all the files excluded.
    ~/bin/dropbox.py exclude list
  9. Then you can remove files from exclusion (the ones you want the server to have), by typing this:
    ~/bin/dropbox.py exclude remove 'a folder with spaces' my_homework etc
  10. Give it a few seconds.. then turn off the dropbox sync like this:
    ~/bin/dropbox.py stop

Creating soft links outside of ~/Dropbox

The first argument is the path to the folder you want to sync, like your log files.
The second argument is the path to the new dropbox folder/file you want to keep updated in ~/Dropbox.
  1. Ensure that dropbox is stopped by typing:
    ~/bin/dropbox.py stop
  2. Remove the synced file/folder
    rm -rf ~/Dropbox/my_server_log
    ln -s /path/to/(server log) ~/Dropbox/my_server_log
  3. (Optionally) This may be the /path/to/(server log) might be out of date. You can make dropbox OVERWRITE the server file by setting the date below the last modified date shown on dropbox. I highly recommend that you backup the dropbox folder before you start syncing.
  4. Start dropbox:
    ~/bin/dropbox.py start
  5. You can “watch” the sync by typing this:
    ~/bin/dropbox.py status
  6. When uploading new content, it will say files uploaded, when downloading, it will say files are downloading. When deleting, you don’t get any messages on what’s being deleted using status.
  7. Repeat steps 1-6 until you have soft linked all files/folders you wanted to have synced with ~/Dropbox.

Create a linux service daemon (Automatic sync after reboot)

  1. Ensure that dropbox is not running, by typing this:
    ~/bin/dropbox.py stop
  2. On CentOS, type the following:
    touch /etc/init.d/dropbox && chmod 755 /etc/init.d/dropbox && vi /etc/init.d/dropbox
  3. Press “i” without quotes to enter edit mode. Then paste the following code:
    # chkconfig: 345 85 15
    # description: Startup script for dropbox daemon
    #
    # processname: dropboxd
    # pidfile: /var/run/dropbox.pid
    # config: /etc/sysconfig/dropbox
    #
    
    ### BEGIN INIT INFO
    # Provides: dropboxd
    # Required-Start: $local_fs $network $syslog
    # Required-Stop: $local_fs $syslog
    # Should-Start: $syslog
    # Should-Stop: $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start up the Dropbox file syncing daemon
    # Description:       Dropbox is a filesyncing sevice provided by dropbox.com
    #                    This service starts up the dropbox daemon.
    ### END INIT INFO
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # To configure, add line with DROPBOX_USERS="user1 user2" to /etc/sysconfig/dropbox
    # Probably should use a dropbox group in /etc/groups instead.
    
    [ -f /etc/sysconfig/dropbox ] && . /etc/sysconfig/dropbox
    prog=dropboxd
    lockfile=${LOCKFILE-/var/lock/subsys/$prog}
    config=${CONFIG-/etc/sysconfig/dropbox}
    RETVAL=0
    
    start() {
        echo -n $"Starting $prog"
        if [ -z $DROPBOX_USERS ] ; then
            echo -n ": unconfigured: $config"
            echo_failure
            echo
            rm -f ${lockfile} ${pidfile}
            RETURN=6
            return $RETVAL
        fi
        for dbuser in $DROPBOX_USERS; do
            dbuser_home=`cat /etc/passwd | grep "^$dbuser:" | cut -d":" -f6`
            daemon --user $dbuser /bin/sh -c "$dbuser_home/.dropbox-dist/dropboxd&"
        done
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
    }
    
    status() {
        for dbuser in $DROPBOX_USERS; do
            dbpid=`pgrep -u $dbuser dropbox | grep -v grep`
            if [ -z $dbpid ] ; then
                echo "dropboxd for USER $dbuser: not running."
            else
                echo "dropboxd for USER $dbuser: running (pid $dbpid)"
            fi
        done
    }
    
    stop() {
        echo -n $"Stopping $prog"
        for dbuser in $DROPBOX_USERS; do
            dbuser_home=`cat /etc/passwd | grep "^$dbuser:" | cut -d":" -f6`
            killproc $dbuser_home/.dropbox-dist/dropbox
        done
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }
    
    # See how we were called.
    case "$1" in
        start)
            start
            ;;
        status)
            status
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            start
            ;;
        *)
            echo $"Usage: $prog {start|status|stop|restart}"
            RETVAL=3
    esac
    exit $RETVAL
  4. Save the pasted contents by pressing escape key, then typing “:wq” without quotes, then press the enter key.
  5. Type this to manually assign which user(s) have dropbox installed:
    vi /etc/sysconfig/dropbox
  6. Typing “i” for edit mode, and then paste this: (“linux_user_name(s)” being the user(s) you are installing with dropbox, example: DROPBOX_USERS=”jdoe”))
    DROPBOX_USERS="linux_user_name(s)"
  7. Save the file by pressing escape key. Then typing “:wq” without quotes, then pressing the enter key.
  8. Then type this to add to chkconfig, and start the newly created dropbox service:
    service dropbox start && chkconfig dropbox on

Curious what version of the dropbox client your running?

Type this:
echo 'Dropbox '`cat ~/.dropbox-dist/VERSION`

http://www.dropboxwiki.com/tips-and-tricks/install-dropbox-centos-gui-required

No comments: