forked from ManuelLR/docker-netatalk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
executable file
·70 lines (59 loc) · 1.91 KB
/
docker-entrypoint.sh
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
70
#!/bin/bash
set -e
function createUser {
echo
local VARIABLE_NAME=$1
local C_USER="$VARIABLE_NAME"
local C_USER_UID="${VARIABLE_NAME}_UID"
local C_USER_GID="${VARIABLE_NAME}_GID"
local C_USER_PASSWORD="${VARIABLE_NAME}_PASSWORD"
local cmd
echo "Creating user: " ${!VARIABLE_NAME}
if [ ! -z "${!C_USER}" ]; then
if [ ! -z "${!C_USER_UID}" ]; then
cmd="$cmd --uid ${!C_USER_UID}"
fi
if [ ! -z "${!C_USER_GID}" ]; then
cmd="$cmd --gid ${!C_USER_GID}"
groupadd --gid ${!C_USER_GID} "${!C_USER}"
fi
adduser $cmd --no-create-home --disabled-password --gecos '' "${!C_USER}"
usermod -a -G netatalk-files "${!C_USER}"
if [ ! -z "${!C_USER_PASSWORD}" ]; then
echo "${!C_USER}:${!C_USER_PASSWORD}" | chpasswd
fi
fi
echo
}
if [ ! -e ".NotFirstRun" ]; then
groupadd --gid 9934 netatalk-files
while IFS='=' read -r name value ; do
if [[ $name =~ ^AFP_USER_[0-9]+$ ]] || [[ $name =~ ^AFP_USER$ ]] ; then
createUser $name
fi
done < <(env|sort -h)
touch .NotFirstRun
fi
if [ ! -d /media/share ]; then
mkdir -p /media/share
echo "use -v /my/dir/to/share:/media/share" > readme.txt
fi
chgrp netatalk-files /media/share
chmod g+rwx /media/share
if [ ! -d /media/timemachine ]; then
mkdir -p /media/timemachine
echo "use -v /my/dir/to/timemachine:/media/timemachine" > readme.txt
fi
chgrp netatalk-files /media/timemachine
chmod g+rwx /media/timemachine
sed -i'' -e "s,%AFP_NAME%,${AFP_NAME:-},g" /etc/netatalk/afp.conf
sed -i'' -e "s,%AFP_SPOTLIGHT%,${AFP_SPOTLIGHT:-},g" /etc/netatalk/afp.conf
sed -i'' -e "s,%AFP_ZEROCONF%,${AFP_ZEROCONF:-},g" /etc/netatalk/afp.conf
# Start dbus
mkdir -p /var/run/dbus
rm -f /var/run/dbus/pid
dbus-daemon --system
# Start avahi
sed -i '/rlimit-nproc/d' /etc/avahi/avahi-daemon.conf
avahi-daemon -D
exec netatalk -d