11#! /bin/bash
22
3- # Set up user group
4- PGID=" ${PGID:- 1000} "
5- addgroup --gid $PGID bitwarden
3+ if [[ " $( id -u) " == " 0" ]]; then
4+ # Set up user group
5+ PGID=" ${PGID:- 911} "
6+ addgroup --gid " $PGID " bitwarden
67
7- # Set up user
8- PUID=" ${PUID:- 1000} "
9- adduser --no-create-home --shell /bin/bash --disabled-password --uid $PUID --gid $PGID --gecos " " bitwarden
8+ # Set up user
9+ PUID=" ${PUID:- 911} "
10+ adduser --no-create-home --shell /bin/bash --disabled-password --uid " $PUID " --gid " $PGID " --gecos " " bitwarden
11+ fi
1012
1113# Translate environment variables for application settings
1214VAULT_SERVICE_URI=https://$BW_DOMAIN
@@ -49,60 +51,55 @@ if [ ! -f /etc/bitwarden/identity.pfx ]; then
4951 -subj " /CN=Bitwarden IdentityServer" \
5052 -days 36500
5153
54+ # identity.pfx is soft linked to the necessary locations in the Dockerfile
5255 openssl pkcs12 \
5356 -export \
5457 -out /etc/bitwarden/identity.pfx \
5558 -inkey /etc/bitwarden/identity.key \
5659 -in /etc/bitwarden/identity.crt \
57- -passout pass:$globalSettings__identityServer__certificatePassword
60+ -passout " pass:$globalSettings__identityServer__certificatePassword "
5861
5962 rm /etc/bitwarden/identity.crt
6063 rm /etc/bitwarden/identity.key
6164fi
6265
63- cp /etc/bitwarden/identity.pfx /app/Identity/identity.pfx
64- cp /etc/bitwarden/identity.pfx /app/Sso/identity.pfx
65-
6666# Generate SSL certificates
67- if [ " $BW_ENABLE_SSL " = " true" -a ! -f /etc/bitwarden/${BW_SSL_KEY:- ssl.key} ]; then
67+ if [ " $BW_ENABLE_SSL " = " true" ] && [ ! -f " /etc/bitwarden/${BW_SSL_KEY:- ssl.key} " ]; then
6868 openssl req \
6969 -x509 \
7070 -newkey rsa:4096 \
7171 -sha256 \
7272 -nodes \
7373 -days 36500 \
74- -keyout /etc/bitwarden/${BW_SSL_KEY:- ssl.key} \
75- -out /etc/bitwarden/${BW_SSL_CERT:- ssl.crt} \
74+ -keyout /etc/bitwarden/" ${BW_SSL_KEY:- ssl.key} " \
75+ -out /etc/bitwarden/" ${BW_SSL_CERT:- ssl.crt} " \
7676 -reqexts SAN \
7777 -extensions SAN \
78- -config <( cat /usr/lib/ssl/openssl.cnf <( printf " [SAN]\nsubjectAltName=DNS:${BW_DOMAIN:- localhost} \nbasicConstraints=CA:true " ) ) \
78+ -config <( cat /usr/lib/ssl/openssl.cnf <( printf ' [SAN]\nsubjectAltName=DNS:%s\nbasicConstraints=CA:true ' " ${BW_DOMAIN:- localhost} " ) ) \
7979 -subj " /C=US/ST=California/L=Santa Barbara/O=Bitwarden Inc./OU=Bitwarden/CN=${BW_DOMAIN:- localhost} "
8080fi
8181
8282# Launch a loop to rotate nginx logs on a daily basis
8383/bin/sh -c " /logrotate.sh loop >/dev/null 2>&1 &"
8484
85- /usr/local/bin/hbs
85+ # Create necessary directories
86+ mkdir -p /etc/bitwarden/logs/supervisord
87+ mkdir -p /etc/bitwarden/logs/nginx
88+ mkdir -p /etc/bitwarden/nginx
89+ mkdir -p /tmp/bitwarden
8690
87- # Enable/Disable services
88- sed -i " s/autostart=true/autostart=${BW_ENABLE_ADMIN} /" /etc/supervisor.d/admin.ini
89- sed -i " s/autostart=true/autostart=${BW_ENABLE_API} /" /etc/supervisor.d/api.ini
90- sed -i " s/autostart=true/autostart=${BW_ENABLE_EVENTS} /" /etc/supervisor.d/events.ini
91- sed -i " s/autostart=true/autostart=${BW_ENABLE_ICONS} /" /etc/supervisor.d/icons.ini
92- sed -i " s/autostart=true/autostart=${BW_ENABLE_IDENTITY} /" /etc/supervisor.d/identity.ini
93- sed -i " s/autostart=true/autostart=${BW_ENABLE_NOTIFICATIONS} /" /etc/supervisor.d/notifications.ini
94- sed -i " s/autostart=true/autostart=${BW_ENABLE_SCIM} /" /etc/supervisor.d/scim.ini
95- sed -i " s/autostart=true/autostart=${BW_ENABLE_SSO} /" /etc/supervisor.d/sso.ini
91+ /usr/local/bin/hbs
9692
97- chown -R $PUID : $PGID \
98- /app \
99- /etc/bitwarden \
100- /etc/nginx/http.d \
101- /etc/supervisor \
102- /etc/supervisor.d \
103- /var/lib/nginx \
104- /var/log \
105- /var/run/nginx \
106- /run
93+ if [[ " $( id -u ) " == 0 ]] ; then
94+ find /etc/bitwarden ! -xtype l \( ! -gid " $PGID " -o ! -uid " $PUID " \) -exec chown " ${PUID} : ${PGID} " {} +
95+
96+ exec setpriv --reuid= " $PUID " --regid= " $PGID " --init-groups /usr/bin/supervisord
97+ else
98+ FILES= " $( find /etc/bitwarden ! -xtype l \( ! -gid " $( id -g ) " -o ! -uid " $( id -u ) " \) ) "
99+ if [[ -n " $FILES " ]] ; then
100+ echo " The following files are not owned by the running user and may cause errors: " >&2
101+ echo " $FILES " >&2
102+ fi
107103
108- exec setpriv --reuid=$PUID --regid=$PGID --init-groups /usr/bin/supervisord
104+ exec /usr/bin/supervisord
105+ fi
0 commit comments