forked from DyonR/docker-nextcloudcmd-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
48 lines (38 loc) · 2.05 KB
/
docker-entrypoint.sh
File metadata and controls
48 lines (38 loc) · 2.05 KB
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
#!/bin/bash
# Check if the PGID exists, if not create the group with the name 'nextcloudclient'
/usr/bin/getent group "$RUN_GID" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[INFO] A group with PGID $RUN_GID already exists in /etc/group, nothing to do." | /usr/bin/ts '%Y-%m-%d %H:%M:%.S'
else
echo "[INFO] A group with PGID $RUN_GID does not exist, adding a group called 'nextcloudclient' with PGID $RUN_GID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S'
/usr/sbin/groupadd -g $RUN_GID nextcloudclient
fi
# Check if the PUID exists, if not create the user with the name 'nextcloudclient', with the correct group
/usr/bin/getent passwd "$RUN_UID" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[INFO] An user with PUID $RUN_UID already exists in /etc/passwd, nothing to do." | /usr/bin/ts '%Y-%m-%d %H:%M:%.S'
else
echo "[INFO] An user with PUID $RUN_UID does not exist, adding an user called 'nextcloudclient user' with PUID $RUN_UID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S'
/usr/sbin/useradd --comment "nextcloudclient user" --gid $RUN_GID --uid $RUN_UID --create-home --shell /bin/bash nextcloudclient
fi
# If we end up with a \n in the file it will complain
netrc_tmp="/home/nextcloudclient/.netrctmp"
netrc_file="/home/nextcloudclient/.netrc"
nextcloud_server_without_port=$(echo $NEXTCLOUD_SERVER | /usr/bin/sed 's/\(.*\):.*/\1/')
/usr/sbin/cat <<EOF > $netrc_tmp
machine $nextcloud_server_without_port login $NEXTCLOUD_USER password $NEXTCLOUD_PASS
EOF
/usr/sbin/tr -d "\n" < $netrc_tmp > $netrc_file
/usr/bin/rm $netrc_tmp
/usr/bin/sed -i '1s/^/LANG="en_GB.utf8"\nexport "LANG"\n/' /home/nextcloudclient/.bashrc
/usr/sbin/chown $RUN_UID:$RUN_GID $netrc_file
/usr/sbin/chmod 600 $netrc_file
echo "[INFO] Changing ownership of all files and directories in /nextclouddata and /opt/Nextcloud/log to $RUN_UID:$RUN_GID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S'
#SETUP PATHS
PATH=(${NEXTCLOUD_FILEPATH})
for ((i = 0; i <= COUNT; i++)); do
FILEPATH=${PATH[${i}]}
/usr/bin/chgrp -R $RUN_GID /nextclouddata/$FILEPATH/
done
/usr/bin/chown -R $RUN_UID:$RUN_GID /opt/Nextcloud/log
exec $@