Skip to content

Commit 70fcf46

Browse files
committed
Added the option to add PGID and PUID
1 parent a2d7f4a commit 70fcf46

File tree

18 files changed

+167
-69
lines changed

18 files changed

+167
-69
lines changed

Dockerfile

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@ MAINTAINER [email protected] <[email protected]>
1111
####################
1212
RUN apt-get update && apt-get install -y \
1313
curl \
14+
fuse \
1415
unionfs-fuse \
1516
bc \
1617
screen \
1718
unzip \
18-
fuse \
1919
wget
2020

21+
RUN sed -i 's/#user_allow_other/user_allow_other/' /etc/fuse.conf
22+
23+
RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates && apt-get install -y openssl
24+
25+
RUN chmod 777 /var/run/screen
26+
2127
# MongoDB 3.4
22-
RUN \
28+
RUN \
2329
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \
2430
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list && \
2531
apt-get update && \
2632
apt-get install -y mongodb-org
2733

2834

35+
# S6 overlay
36+
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
37+
ENV S6_KEEP_ENV=1
38+
39+
RUN \
40+
OVERLAY_VERSION=$(curl -sX GET "https://api.github.com/repos/just-containers/s6-overlay/releases/latest" \
41+
| awk '/tag_name/{print $4;exit}' FS='[""]') && \
42+
curl -o \
43+
/tmp/s6-overlay.tar.gz -L \
44+
"https://github.com/just-containers/s6-overlay/releases/download/${OVERLAY_VERSION}/s6-overlay-amd64.tar.gz" && \
45+
tar xfz \
46+
/tmp/s6-overlay.tar.gz -C /
47+
48+
2949
####################
3050
# ENVIRONMENT VARIABLES
3151
####################
@@ -36,15 +56,13 @@ ENV ENCRYPT_MEDIA "1"
3656
ENV BUFFER_SIZE "500M"
3757
ENV MAX_READ_AHEAD "30G"
3858
ENV CHECKERS "16"
39-
4059
ENV RCLONE_CLOUD_ENDPOINT "gd-crypt:"
4160
ENV RCLONE_LOCAL_ENDPOINT "local-crypt:"
4261

4362
# Plexdrive
4463
ENV CHUNK_SIZE "10M"
4564
ENV CLEAR_CHUNK_MAX_SIZE ""
4665
ENV CLEAR_CHUNK_AGE "24h"
47-
4866
ENV MONGO_DATABASE "plexdrive"
4967

5068
# Time format
@@ -57,23 +75,35 @@ ENV FREEUP_ATLEAST_GB "80"
5775
ENV REMOVE_LOCAL_FILES_AFTER_DAYS "30"
5876

5977

78+
6079
####################
6180
# SCRIPTS
6281
####################
63-
COPY setup/* /usr/local/bin/
82+
COPY setup/* /usr/bin/
6483

6584
COPY install.sh /
85+
86+
COPY scripts/* /usr/bin/
87+
88+
RUN chmod a+x /install.sh
6689
RUN sh /install.sh
90+
RUN chmod a+x /usr/bin/*
6791

68-
COPY scripts/* /usr/local/bin/
92+
COPY root /
6993

94+
# Create abc user
95+
RUN groupmod -g 1000 users && \
96+
useradd -u 911 -U -d / -s /bin/false abc && \
97+
usermod -G users abc
7098

7199
####################
72100
# VOLUMES
73101
####################
74102
# Define mountable directories.
75103
VOLUME /data/db /config /cloud-encrypt /cloud-decrypt /local-decrypt /local-media /chunks /log
76104

105+
RUN chmod -R 777 /data
106+
RUN chmod -R 777 /log
77107

78108
####################
79109
# WORKING DIRECTORY
@@ -82,6 +112,6 @@ WORKDIR /data
82112

83113

84114
####################
85-
# COMMANDS
115+
# ENTRYPOINT
86116
####################
87-
CMD init
117+
ENTRYPOINT ["/init"]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Environment variables:
7070
* `-e REMOVE_LOCAL_FILES_WHEN_SPACE_EXCEEDS_GB` - Remove local files when local storage exceeds this value in GB (default **100**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time
7171
* `-e FREEUP_ATLEAST_GB` - Remove atleast this value in GB on removal (default **80**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to time
7272
* `-e REMOVE_LOCAL_FILES_AFTER_DAYS` Remove local files older than this value in days (default **10**) - this is ignored if `REMOVE_LOCAL_FILES_BASED_ON` is set to space
73+
* `-e PGID` Group id
74+
* `-e PUID` User id
75+
7376

7477
`--privileged --cap-add=MKNOD --cap-add=SYS_ADMIN --device=/dev/fuse` must be there for fuse to work within the container.
7578

install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ plexdrive_url="https://github.com/dweidenfeld/plexdrive/releases/download/4.0.0/
1010
wget "$rclone_url"
1111
unzip "$rclone_zip"
1212
chmod a+x "${rclone_release}/rclone"
13-
cp -rf "${rclone_release}/rclone" "/usr/local/bin/rclone"
13+
cp -rf "${rclone_release}/rclone" "/usr/bin/rclone"
1414
rm -rf "$rclone_zip"
1515
rm -rf "$rclone_release"
1616
# Plexdrive
1717
wget "$plexdrive_url"
1818
chmod a+x "$plexdrive_bin"
19-
cp -rf "$plexdrive_bin" "/usr/local/bin/plexdrive"
19+
cp -rf "$plexdrive_bin" "/usr/bin/plexdrive"
2020
rm -rf "$plexdrive_bin"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/with-contenv sh
2+
. "/usr/bin/variables"
3+
4+
# unmount fuse
5+
fusermount -uz "${cloud_encrypt_dir}"
6+
fusermount -uz "${cloud_decrypt_dir}"
7+
fusermount -uz "${local_decrypt_dir}"
8+
fusermount -uz "${local_media_dir}"

root/etc/cont-init.d/10-adduser

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/with-contenv sh
2+
3+
PUID=${PUID:-911}
4+
PGID=${PGID:-911}
5+
6+
if [ ! "$(id -u abc)" -eq "$PUID" ]; then usermod -o -u "$PUID" abc ; fi
7+
if [ ! "$(id -g abc)" -eq "$PGID" ]; then groupmod -o -g "$PGID" abc ; fi
8+
9+
. "/usr/bin/variables"
10+
11+
echo "
12+
GID/UID
13+
-------------------------------------
14+
User uid: $(id -u abc)
15+
User gid: $(id -g abc)
16+
-------------------------------------
17+
"
18+
chmod -R 777 \
19+
/var/lock \
20+
$log_dir \
21+
/data/db
22+
23+
chown -R abc:abc \
24+
/config \
25+
/usr/bin/* \
26+
$cloud_encrypt_dir \
27+
$cloud_decrypt_dir \
28+
$local_decrypt_dir \
29+
$local_media_dir
30+

root/etc/services.d/mount/run

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/with-contenv sh
2+
. "/usr/bin/variables"
3+
4+
umask 022
5+
6+
mount_command="mount"
7+
8+
echo "Executing ${mongo_command}"
9+
mongod --fork --logpath ${log_dir}/mongod.log
10+
11+
echo "Executing ${mount_command}"
12+
exec s6-setuidgid abc $mount_command
13+
14+
while /bin/true; do
15+
sleep 60
16+
done

scripts/cloudupload

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
. "/usr/local/bin/config"
2+
. "/usr/bin/variables"
33

44
cloudupload.script "$@" 2>&1 | tee "${log_dir}/cloudupload.log"

scripts/cloudupload.script

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
###############################################################################
55
# shellcheck source=config
66

7-
. "/usr/local/bin/variables"
7+
. "/usr/bin/config"
88
##############################################################################
99

1010
# If script is already running; abort.
@@ -13,6 +13,9 @@ if pidof -o %PPID -x "$(basename "$0")"; then
1313
exit 3
1414
fi
1515

16+
check_rclone_cloud
17+
18+
1619
# Generate filelist and iterate through it...
1720
find "${local_decrypt_dir}" -type f |
1821
while read -r n; do

scripts/config

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
#!/bin/bash
2-
. "/usr/local/bin/variables"
3-
4-
5-
if [[ ! "$(printenv RCLONE_LOCAL_ENDPOINT)" == *: ]]; then
6-
printf "\n\n"
7-
echo "Missing colon (:) in RCLONE_LOCAL_ENDPOINT ($(printenv RCLONE_LOCAL_ENDPOINT))"
8-
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
9-
printf "\n\n"
10-
11-
exit 02
12-
elif [[ ! "$(printenv RCLONE_CLOUD_ENDPOINT)" == *: ]]; then
13-
printf "\n\n"
14-
echo "Missing colon (:) in RCLONE_CLOUD_ENDPOINT ($(printenv RCLONE_CLOUD_ENDPOINT))"
15-
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
16-
printf "\n\n"
17-
18-
exit 02
19-
elif [ "$(rclone listremotes $rclone_config | grep $(printenv RCLONE_LOCAL_ENDPOINT) | wc -l)" == "0" ]; then
20-
printf "\n\n"
21-
echo "RCLONE_LOCAL_ENDPOINT ($(printenv RCLONE_LOCAL_ENDPOINT)) endpoint has not been created within rclone"
22-
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
23-
printf "\n\n"
24-
25-
exit 02
26-
elif [ "$(rclone listremotes $rclone_config | grep $(printenv RCLONE_CLOUD_ENDPOINT) | wc -l)" == "0" ]; then
27-
printf "\n\n"
28-
echo "RCLONE_CLOUD_ENDPOINT ($(printenv RCLONE_CLOUD_ENDPOINT)) endpoint has not been created within rclone"
29-
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
30-
printf "\n\n"
31-
32-
exit 02
33-
fi
2+
. "/usr/bin/variables"
3+
4+
check_rclone_cloud () {
5+
if [[ ! "$(printenv RCLONE_CLOUD_ENDPOINT)" == *: ]]; then
6+
printf "\n\n"
7+
echo "Missing colon (:) in RCLONE_CLOUD_ENDPOINT ($(printenv RCLONE_CLOUD_ENDPOINT))"
8+
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
9+
printf "\n\n"
10+
11+
exit 02
12+
fi
13+
14+
if [ "$(rclone listremotes $rclone_config | grep $(printenv RCLONE_CLOUD_ENDPOINT) | wc -l)" == "0" ]; then
15+
printf "\n\n"
16+
echo "RCLONE_CLOUD_ENDPOINT ($(printenv RCLONE_CLOUD_ENDPOINT)) endpoint has not been created within rclone"
17+
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
18+
printf "\n\n"
19+
20+
exit 02
21+
fi
22+
}
23+
24+
check_rclone_local () {
25+
if [ "$(printenv ENCRYPT_MEDIA)" != "0" ]; then
26+
if [[ ! "$(printenv RCLONE_LOCAL_ENDPOINT)" == *: ]]; then
27+
printf "\n\n"
28+
echo "Missing colon (:) in RCLONE_LOCAL_ENDPOINT ($(printenv RCLONE_LOCAL_ENDPOINT))"
29+
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
30+
printf "\n\n"
31+
32+
exit 02
33+
fi
34+
35+
if [ "$(rclone listremotes $rclone_config | grep $(printenv RCLONE_LOCAL_ENDPOINT) | wc -l)" == "0" ]; then
36+
printf "\n\n"
37+
echo "RCLONE_LOCAL_ENDPOINT ($(printenv RCLONE_LOCAL_ENDPOINT)) endpoint has not been created within rclone"
38+
echo "Run: docker exec -ti <DOCKER_CONTAINER> rclone_setup"
39+
printf "\n\n"
40+
41+
exit 02
42+
fi
43+
fi
44+
}

scripts/mount

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
. "/usr/local/bin/config"
2+
. "/usr/bin/variables"
33

44
mount.script "$@" 2>&1 | tee "${log_dir}/mount.log"

scripts/mount.script

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
###############################################################################
77
# shellcheck source=config
88

9-
. "/usr/local/bin/variables"
9+
. "/usr/bin/config"
1010
###############################################################################
1111
# FUNCTIONS
1212
###############################################################################
@@ -36,6 +36,8 @@ mount_gdrive () {
3636
}
3737

3838
mount_local_media () {
39+
check_rclone_local
40+
3941
# Make sure decrypted GD directory exists.
4042
if [ ! -d "${cloud_decrypt_dir}" ]; then
4143
mkdir -p "${cloud_decrypt_dir}"

scripts/rmlocal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
. "/usr/local/bin/config"
2+
. "/usr/bin/variables"
33

44
rmlocal.script "$@" 2>&1 | tee "${log_dir}/rmlocal.log"

scripts/rmlocal.script

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
###############################################################################
55
# shellcheck source=config
66

7-
. "/usr/local/bin/variables"
7+
. "/usr/bin/variables"
88
##############################################################################
99

1010
rm_time () {
@@ -99,6 +99,8 @@ if pidof -o %PPID -x "$(basename "$0")"; then
9999
exit 3
100100
fi
101101

102+
check_rclone_cloud
103+
102104
if [ "$REMOVE_LOCAL_FILES_BASED_ON" = "space" ]; then
103105
rm_space
104106
elif [ "$REMOVE_LOCAL_FILES_BASED_ON" = "time" ]; then

scripts/variables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rclone_mount_options="${rclone_options} --read-only --allow-non-empty --allow-ot
1212

1313
plexdrive_temp_dir="/chunks"
1414
plexdrive_options="--config=/config --temp=${plexdrive_temp_dir} -o allow_other --chunk-size=$(printenv CHUNK_SIZE) --clear-chunk-age=$(printenv CLEAR_CHUNK_AGE)"
15-
if [ -n $(printenv CLEAR_CHUNK_MAX_SIZE) ]; then
15+
if [ ! -z $(printenv CLEAR_CHUNK_MAX_SIZE) ]; then
1616
plexdrive_options="${plexdrive_options} --clear-chunk-max-size=$(printenv CLEAR_CHUNK_MAX_SIZE)"
1717
fi
1818
mongo="--mongo-database=$(printenv MONGO_DATABASE) --mongo-host=localhost"

setup/check

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/bin/bash
2-
. "/usr/local/bin/config"
2+
. "/usr/bin/config"
33

44
all_good=1
55

6+
check_rclone_cloud
7+
check_rclone_local
8+
9+
10+
611
if [ $(ps -ef | grep "plexdrive" | grep -v "grep" | wc -l) == "0" ]; then
712
printf "\n\nPlexdrive is not running\n\n"
813
all_good=0
914
fi
1015

11-
if [ $(ps -ef | grep "rclone" | grep -v "grep" | wc -l) == "0" ]; then
12-
printf "\n\nRclone is not running\n\n"
13-
all_good=0
16+
if [ "$(printenv ENCRYPT_MEDIA)" != "0" ]; then
17+
if [ $(ps -ef | grep "rclone" | grep -v "grep" | wc -l) == "0" ]; then
18+
printf "\n\nRclone is not running\n\n"
19+
all_good=0
20+
fi
1421
fi
1522

1623
if [ $(ps -ef | grep "unionfs" | grep -v "grep" | wc -l) == "0" ]; then

0 commit comments

Comments
 (0)