-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathentrypoint
47 lines (43 loc) · 1.34 KB
/
entrypoint
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
#!/bin/bash -e
export PASS=${PASS:-RANDOM}
export USER=${USER:-timemachine}
export USERID=${USERID:-1311}
export GROUPID=${GROUPID:-1311}
export TMSIZE=${TMSIZE:-0}
export SHARENAME=${SHARENAME:-Data}
createUser()
{
if groupadd -g ${GROUPID} timemachine_users; then
echo "Created group timemachine_users with ${GROUPID}"
fi
if [ $PASS == RANDOM ] ; then
PASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
fi
if useradd -u ${USERID} -g timemachine_users ${USER} ; then
echo Creating user ${USER} with a samba password of ${PASS}
printf "$PASS\n$PASS\n" | smbpasswd -s -a ${USER}
fi
}
backupConfig()
{
if [ ! -d ${BACKUPDIR} ] ; then
echo ${BACKUPDIR} not found did you forget to add the volume?
exit 1
else
echo "Granting permissions to ${USER}/${USERID} with timemachine_users/${GROUPID} on ${BACKUPDIR}"
chown -R ${USER}:${GROUPID} ${BACKUPDIR}
fi
}
makeOptions()
{
TMSIZE=$(($TMSIZE * 1000000))
sed "s#REPLACE_TM_SIZE#${TMSIZE}#" /tmp/template_quota > ${BACKUPDIR}/.com.apple.TimeMachine.quota.plist
sed -i "s#REPLACE_SHARENAME#${SHARENAME}#" /etc/samba/smb.conf
}
if [[ -z $1 ]] || [[ ${1:0:1} == '-' ]] ; then
createUser
backupConfig
makeOptions
exec /usr/sbin/smbd --no-process-group --foreground "$@"
exec "$@"
fi