2018-03-28 03:14:52 +02:00
|
|
|
#!/bin/bash
|
2017-08-18 04:28:56 +02:00
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# Setup
|
|
|
|
|
|
|
|
GROUPNAME="bitwarden"
|
2018-03-28 04:57:30 +02:00
|
|
|
USERNAME="bitwarden"
|
2018-04-16 21:30:07 +02:00
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
LUID=${LOCAL_UID:-0}
|
|
|
|
LGID=${LOCAL_GID:-0}
|
2018-04-16 21:30:07 +02:00
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
# Step down from host root to well-known nobody/nogroup user
|
2018-03-28 04:57:30 +02:00
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
if [ $LUID -eq 0 ]
|
2018-04-16 21:30:07 +02:00
|
|
|
then
|
2018-05-31 18:05:26 +02:00
|
|
|
LUID=65534
|
2018-04-16 21:30:07 +02:00
|
|
|
fi
|
2018-05-31 18:05:26 +02:00
|
|
|
if [ $LGID -eq 0 ]
|
2018-03-28 04:57:30 +02:00
|
|
|
then
|
2018-05-31 18:05:26 +02:00
|
|
|
LGID=65534
|
2018-03-28 04:57:30 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
# Create user and group
|
2018-04-16 21:30:07 +02:00
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
|
|
|
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
|
|
|
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
|
|
|
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
|
|
|
mkhomedir_helper $USERNAME
|
2018-04-03 03:11:32 +02:00
|
|
|
|
2019-04-15 04:41:59 +02:00
|
|
|
# Read the SA_PASSWORD value from a file for swarm environments.
|
|
|
|
# See https://github.com/Microsoft/mssql-docker/issues/326
|
2019-04-15 04:46:11 +02:00
|
|
|
if [ ! -z "$SA_PASSWORD" ] && [ ! -z "$SA_PASSWORD_FILE" ]
|
|
|
|
then
|
2019-04-15 04:41:59 +02:00
|
|
|
echo "Provided both SA_PASSWORD and SA_PASSWORD_FILE environment variables. Please only use one."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-04-15 04:46:11 +02:00
|
|
|
if [ ! -z "$SA_PASSWORD_FILE" ]
|
|
|
|
then
|
2019-04-15 04:41:59 +02:00
|
|
|
# It should be exported, so it is available to the env command below.
|
|
|
|
export SA_PASSWORD=$(cat $SA_PASSWORD_FILE)
|
|
|
|
fi
|
|
|
|
|
2021-07-02 16:52:34 +02:00
|
|
|
# Replace database name in backup-db.sql
|
|
|
|
if [ ! -z "$DATABASE" ]
|
|
|
|
then
|
|
|
|
sed -i -e "/@DatabaseName /s/vault/$DATABASE/" backup-db.sql
|
|
|
|
sed -i -e "/@DatabaseNameSafe /s/vault/${DATABASE// /-}/" backup-db.sql
|
|
|
|
fi
|
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# The rest...
|
|
|
|
|
2018-03-27 20:55:33 +02:00
|
|
|
mkdir -p /etc/bitwarden/mssql/backups
|
2018-04-16 21:30:07 +02:00
|
|
|
chown -R $USERNAME:$GROUPNAME /etc/bitwarden
|
2018-03-27 20:55:33 +02:00
|
|
|
mkdir -p /var/opt/mssql/data
|
2018-04-16 21:30:07 +02:00
|
|
|
chown -R $USERNAME:$GROUPNAME /var/opt/mssql
|
|
|
|
chown $USERNAME:$GROUPNAME /backup-db.sh
|
|
|
|
chown $USERNAME:$GROUPNAME /backup-db.sql
|
2018-03-27 20:55:33 +02:00
|
|
|
|
2019-11-25 14:35:52 +01:00
|
|
|
# Launch a loop to backup database on a daily basis
|
|
|
|
if [ "$BACKUP_DB" != "0" ]
|
|
|
|
then
|
2019-11-25 15:25:11 +01:00
|
|
|
gosu $USERNAME:$GROUPNAME /bin/sh -c "/backup-db.sh loop >/dev/null 2>&1 &"
|
2019-11-25 14:35:52 +01:00
|
|
|
fi
|
2018-03-27 03:38:32 +02:00
|
|
|
|
2018-05-31 18:05:26 +02:00
|
|
|
exec gosu $USERNAME:$GROUPNAME /opt/mssql/bin/sqlservr
|