forked from janeczku/docker-dropbox
-
Notifications
You must be signed in to change notification settings - Fork 5
/
run
executable file
·69 lines (59 loc) · 2.43 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# This script is a fork of https://github.com/excelsiord/docker-dropbox
# Set UID/GID if not provided with enviromental variable(s).
if [ -z "$DBOX_UID" ]; then
DBOX_UID=$(cat /etc/passwd | grep dropbox | cut -d: -f3)
echo "DBOX_UID variable not specified, defaulting to dropbox user id ($DBOX_UID)"
fi
if [ -z "$DBOX_GID" ]; then
DBOX_GID=$(cat /etc/group | grep dropbox | cut -d: -f3)
echo "DBOX_GID variable not specified, defaulting to dropbox user group id ($DBOX_GID)"
fi
# Look for existing group, if not found create dropbox with specified GID.
FIND_GROUP=$(grep ":$DBOX_GID:" /etc/group)
if [ -z "$FIND_GROUP" ]; then
usermod -g users dropbox
groupdel dropbox
groupadd -g $DBOX_GID dropbox
fi
# Set dropbox account's UID.
usermod -u $DBOX_UID -g $DBOX_GID --non-unique dropbox > /dev/null 2>&1
# Change ownership to dropbox account on all working folders.
chown -R $DBOX_UID:$DBOX_GID /dbox
# Change permissions on Dropbox folder
chmod 755 /dbox/Dropbox
# Dropbox did not shutdown properly? Remove files.
[ ! -e "/dbox/.dropbox/command_socket" ] || rm /dbox/.dropbox/command_socket
[ ! -e "/dbox/.dropbox/iface_socket" ] || rm /dbox/.dropbox/iface_socket
[ ! -e "/dbox/.dropbox/unlink.db" ] || rm /dbox/.dropbox/unlink.db
[ ! -e "/dbox/.dropbox/dropbox.pid" ] || rm /dbox/.dropbox/dropbox.pid
# Update Dropbox to latest version unless DBOX_SKIP_UPDATE is set
if [[ -z "$DBOX_SKIP_UPDATE" ]]; then
echo "Checking for latest Dropbox version..."
sleep 1
# Get download link for latest dropbox version
DL=$(curl -I -s https://www.dropbox.com/download/\?plat\=lnx.x86_64 | grep ocation | awk -F'ocation: ' '{print $2}')
# Strip CRLF
DL=${DL//[$'\t\r\n ']}
# Extract version string
Latest=$(echo $DL | sed 's/.*x86_64-\([0-9]*\.[0-9]*\.[0-9]*\)\.tar\.gz/\1/')
# Get current Version
Current=$(cat /opt/dropbox/VERSION)
echo "Latest :" $Latest
echo "Installed:" $Current
if [ ! -z "${Latest}" ] && [ ! -z "${Current}" ] && [ $Current != $Latest ]; then
echo "Downloading Dropbox v$Latest..."
tmpdir=`mktemp -d`
curl -# -L $DL | tar xzf - -C $tmpdir
echo "Installing new version..."
rm -rf /opt/dropbox/*
mv $tmpdir/.dropbox-dist/* /opt/dropbox/
rm -rf $tmpdir
echo "Dropbox updated to v$Latest"
else
echo "Dropbox is up-to-date"
fi
fi
echo "Starting dropboxd ($(cat /opt/dropbox/VERSION))..."
umask 002
exec su dropbox -s /bin/bash -c /opt/dropbox/dropboxd