Making Dropbox FHS compliant (Gentoo/Funtoo Installation)
Published on 2011-11-07
I’ve recently been introduced to the online storage service Dropbox. Now I don’t really use this system and I really do not like to use it either or want to use it. But many of my coworkers do rely on me being able to access the files they store on the service.
Rant
First of I’m going to complain about that you shouldn’t put company work, or research, material on to the service, and especially not if you haven’t encrypted the files first!
Secondly many people I work with use this as a retarded version control system, mostly because they are ignorant to the fact what a version control system is supposed to do. This in it self is a felony which should be punishable by death.
Custom Installation
You might not care about the FHS, if that is the case do not bother to read on, but do know that you are wrong!
My predicament is that I cannot use Dropbox’s init script. The reason for this is a story in itself, which I’ll write about in future posts, but it stems from the fact that Dropbox have decided, or the initial author for the init script, to break the FHS and use their own retarded scheme. The retarded scheme consists of the following ignorant assertions about a UNIX system installation.
- The program distribution default is to be installed inside the user $HOME
- The shared files are mounted inside the user $HOME
If you are asking yourself why this is wrong then I urge you to thoroughly read the FHS! I will anyway address both these issues here.
- The program distribution should be placed in “/opt” since you do not have the sources for it. The rationale for installing inside opt is that the distribution package isn’t specifically tailored towards your system installation, it just happen to work anyway since it bundles it’s own, perhaps conflicting libraries. This is exactly the same as if you would install sun-jdk, or skype, or any other external software.
- The files on dropbox are synced to your disk and then synced back and forth using the dropbox servers as a mediator. This is a server client relationship and is equivalent with mounting the files, only that we do not use the “mount” and “umount” system calls in order to access the files. This means that they should have a mount target in “/mnt”.
Installation
Now we know where we can, or should, install the program distribution:
# As root
cd /opt
wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.`uname -m`"
tar xvzf dropbox.tar.gz
mv .dropbox-dist dropbox
You should now find a big messy distribution under “/opt/dropbox”
Prepare a user
Now we need to do is to make sure that we have all of the user directories present. We’ll create a script named dropbox-prepare-user in our $PATH, with the following contents:
#!/bin/sh
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
[ ! -d /var/log/dropbox ] && mkdir /var/log/dropbox
[ ! -d /var/run/dropbox ] && mkdir /var/run/dropbox
[ ! -d /mnt/dropbox ] && mkdir /mnt/dropbox
[ -z $1 ] && echo "Please specify a user" && exit 1
grep -q "^$1:" /etc/passwd || exit 1
gid=`grep $1 /etc/passwd | awk -F':' '{print $4}'`
[ ! -d /mnt/dropbox/$1 ] && mkdir /mnt/dropbox/$1
chown $1:$gid /mnt/dropbox/$1
touch /var/log/dropbox/$1-{stdout,stderr}.log
chown $1:$gid /var/log/dropbox/$1-{stdout,stderr}.log
ln -s /mnt/dropbox/$1/Dropbox /home/$1/Dropbox
echo $1 >> /etc/dropbox-users
And lets prepare myself for dropbox usage..
dropbox-prepare-user edwtjo
Ok, fine.
A better init script
Below I’ve updated the init script to be FHS compliant, this script assumes any user put into the DROPBOX_USERS variable has been prepared by the dropbox-prepare-user script:
DROPBOX_USERS=`cat /etc/dropbox-users | sort -u | xargs`
NICENESS=5
depend() {
need localmount net
after bootmisc
}
start() {
ebegin "Starting dropbox..."
for dbuser in $DROPBOX_USERS; do
start-stop-daemon -1 /var/log/dropbox/$dbuser-stdout.log -2 /var/log/dropbox/$dbuser-stderr.log -S -b -m --pidfile /var/run/dropbox/$dbuser.pid -N $NICENESS -u $dbuser -v -e HOME="/mnt/dropbox/$dbuser" -x /opt/dropbox/dropboxd
done
eend $?
}
stop() {
ebegin "Stopping dropbox..."
for dbuser in $DROPBOX_USERS; do
start-stop-daemon --stop --pidfile /var/run/dropbox/$dbuser.pid
done
eend $?
}
status() {
for dbuser in $DROPBOX_USERS; do
if [ -e /var/run/dropbox/$dbuser.pid ] ; then
echo "dropboxd for USER $dbuser: running."
else
echo "dropboxd for USER $dbuser: not running."
fi
done
eend $?
}