Fixes for an issue with entrypoint.sh

This commit is contained in:
Bradley Bickford 2024-12-06 18:27:53 -05:00
parent 00992e16c0
commit 31d9a027bb
5 changed files with 12 additions and 12 deletions

View File

@ -69,6 +69,6 @@ EXPOSE 8080
USER coder USER coder
ENV USER=coder ENV USER=coder
WORKDIR /home/coder WORKDIR /home/coder
ENTRYPOINT ["/usr/bin/entrypoint.sh"] ENTRYPOINT ["/usr/bin/entrypoint.sh", "coder"]

View File

@ -75,6 +75,6 @@ EXPOSE 8080
USER coder USER coder
ENV USER=coder ENV USER=coder
WORKDIR /home/coder WORKDIR /home/coder
ENTRYPOINT ["/usr/bin/entrypoint.sh"] ENTRYPOINT ["/usr/bin/entrypoint.sh", "coder"]

View File

@ -76,6 +76,6 @@ EXPOSE 8080
USER ubuntu USER ubuntu
ENV USER=ubuntu ENV USER=ubuntu
WORKDIR /home/ubuntu WORKDIR /home/ubuntu
ENTRYPOINT ["/usr/bin/entrypoint.sh"] ENTRYPOINT ["/usr/bin/entrypoint.sh", "ubuntu"]

View File

@ -67,6 +67,6 @@ EXPOSE 8080
USER ubuntu USER ubuntu
ENV USER=ubuntu ENV USER=ubuntu
WORKDIR /home/ubuntu WORKDIR /home/ubuntu
ENTRYPOINT ["/usr/bin/entrypoint.sh"] ENTRYPOINT ["/usr/bin/entrypoint.sh", "ubuntu"]

View File

@ -1,27 +1,27 @@
#!/bin/bash #!/bin/bash
CURRENT_GID="$(id -g coder)" CURRENT_GID="$(id -g $1)"
if [ -n "${USER_GID}" ] && [ "${USER_GID}" != "${CURRENT_GID}" ]; then if [ -n "${USER_GID}" ] && [ "${USER_GID}" != "${CURRENT_GID}" ]; then
groupmod -g $USER_GID coder groupmod -g $USER_GID $1
find / -group $CURRENT_GID -exec chgrp -h coder {} \; find / -group $CURRENT_GID -exec chgrp -h $1 {} \;
fi fi
CURRENT_UID="$(id -u coder)" CURRENT_UID="$(id -u $1)"
if [ -n "${USER_UID}" ] && [ "${USER_UID}" != "${CURRENT_UID}" ]; then if [ -n "${USER_UID}" ] && [ "${USER_UID}" != "${CURRENT_UID}" ]; then
usermod -u $USER_UID coder usermod -u $USER_UID $1
find / -user $CURRENT_UID -exec chown -h coder {} \; find / -user $CURRENT_UID -exec chown -h $1 {} \;
fi fi
CURRENT_PASSWD=$(grep -E "^Password: .*$" /home/coder/.config/code-server/config.yaml | cut -d ":" -f 2 | awk '{$1=$1;print}') CURRENT_PASSWD=$(grep -E "^password: .*$" /home/$1/.config/code-server/config.yaml | cut -d ":" -f 2 | awk '{$1=$1;print}')
if [ -n "${USER_PASSWD}" ] && [ "${CURRENT_PASSWD}" != "${USER_PASSWD}" ] || [ "${CURRENT_PASSWD}" == "PASSWORD"]; then if [ -n "${USER_PASSWD}" ] && [ "${CURRENT_PASSWD}" != "${USER_PASSWD}" ] || [ "${CURRENT_PASSWD}" == "PASSWORD"]; then
if [ -n "${USER_PASSWD}" ]; then if [ -n "${USER_PASSWD}" ]; then
USER_PASSWD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)" USER_PASSWD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)"
fi fi
sed -i "s/^PASSWORD: .*$/PASSWORD: ${USER_PASSWD}/g" /home/coder/.config/code-server/config.yaml sed -i "s/^PASSWORD: .*$/PASSWORD: ${USER_PASSWD}/g" /home/$1/.config/code-server/config.yaml
fi fi
/usr/bin/code-server --bind-addr 0.0.0.0:8080 . /usr/bin/code-server --bind-addr 0.0.0.0:8080 .