2013年6月1日 星期六

Running Dropbox at Startup on QNAP NAS

* Model              : SS-439 Pro
* Version            : 3.8.3 build0426
* Date               : 2013/04/26

Make a new share on QNAP NAS and called Dropbox

Declaring a Dropbox QPKG which launches script at startup.
§  Log into QNAP device using SSH or Telnet, for instance by using Putty
§  Edit QPKG config file:
# vi /etc/config/qpkg.conf
§  Declare a new Dropbox package by adding contents like that in this file:
[Dropbox]
Name = Dropbox
Version = 2.0.22
Author = Dropbox
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/Dropbox /Dropbox.sh
Install_Path = /share/MD0_DATA/.qpkg/Dropbox
Enable = TRUE
Note: if NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables.
§  Create the Dropbox package directory:
# mkdir -p /share/MD0_DATA/.qpkg/Dropbox
§  Extract the contents of the Dropbox package to the new directory. Run the following command in Linux terminal.
# cd /share/MD0_DATA/.qpkg/Dropbox
# wget https://www.dropbox.com/download?plat=lnx.x86 --no-check-certificate
# tar -xzf dropbox-lnx.x86-2.0.22.tar.gz
§  Create the Dropbox symbolic link:
# ln -sf /share/MD0_DATA/Dropbox /share/MD0_DATA/.qpkg/Dropbox/Dropbox
§  Create the .dropbox directory:
# mkdir -p /share/MD0_DATA/.qpkg/Dropbox/.dropbox
§  Create the Dropbox script with the contents:
# vi /share/MD0_DATA/.qpkg/Dropbox/Dropbox.sh
§  To be able to enable and disable the Dropbox feature edit the script
#!/bin/sh

CONF=/etc/config/qpkg.conf
QPKG_NAME="Dropbox"

RETVAL=0
QPKG_BASE=
HOME=

DROPBOX_USER="admin"
DAEMON=.dropbox-dist/dropbox

LOCALE=en_US.UTF-8

HOMEDIR=`getent passwd $DROPBOX_USER | cut -d: -f6`

case "$1" in
  start)
 if [ `/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF` = UNKNOWN ]; then
       /sbin/setcfg $QPKG_NAME Enable TRUE -f $CONF
 elif [ `/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF` != TRUE ]; then
       echo "Dropbox is disabled."
       exit 1
 fi
                 PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
        if [ -z $PID ] ; then
            echo "Starting Dropbox..."
        else
            echo "Dropbox is running. (PID $PID)"
                          exit 1
        fi
         HOME=$(/sbin/getcfg $QPKG_NAME Install_Path -d "" -f $CONF) 
         [ -d $HOMEDIR ] || /bin/mkdir -p $HOMEDIR
#create symbolic links                                    
         [ -d $HOMEDIR/.dropbox ] || ln -sf $HOME/.dropbox $HOMEDIR/.dropbox
         [ -d $HOMEDIR/Dropbox ] || ln -sf $HOME/Dropbox $HOMEDIR/Dropbox
         [ -d /root/.dropbox-dist ] || ln -sf $HOME/.dropbox-dist /root/.dropbox-dist
         [ -d /root/.dropbox ] || ln -sf $HOME/.dropbox /root/.dropbox
         echo 100000 > /proc/sys/fs/inotify/max_user_watches
         OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
         LD_LIBRARY_PATH=$HOME:$LD_LIBRARY_PATH
         export LANG=$LOCALE
         $HOME/$DAEMON > $HOME/Dropbox_status.txt 2>&1 &
         RETVAL=$?
         /bin/sleep 5
         ;;
  stop) 
    PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
         if [ -z $PID ] ; then
        /bin/echo "Dropbox isn't running!"
        exit 1
         fi
         kill -9 $PID
         echo "Dropbox daemon stopped."
         RETVAL=$?
         sleep 3
         ;;
  restart)
         sh $0 stop
         sh $0 start
         RETVAL=$?
         ;;
  status)
    PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
    if [ -z $PID ] ; then
        echo "Dropbox isn't running!"
    else
        echo "Dropbox is running. (PID $PID)"
    fi
         ;;
  *)
         /bin/echo "Usage: $0 {start|stop|restart|status}"
         exit 1
esac

exit $RETVAL
§  Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/Dropbox/Dropbox.sh
§  Reboot
References:

沒有留言:

張貼留言