1
0
mirror of https://github.com/bitwarden/server synced 2025-12-22 03:03:33 +00:00

Use user primary group if not root (#292)

* Use user primary group if not root

* Do not run getent on MacOS

* Simplify UID/GID management

* Create uid.env if it does not exist

* Populate uid.env if it's empty
This commit is contained in:
Mart124
2018-05-29 23:18:48 +02:00
committed by Kyle Spearrin
parent 1ead0af77e
commit ec89c36ca0
11 changed files with 165 additions and 394 deletions

View File

@@ -5,7 +5,7 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTPUT_DIR="../."
OUTPUT_DIR=".."
if [ $# -gt 1 ]
then
OUTPUT_DIR=$2
@@ -23,16 +23,17 @@ then
WEBVERSION=$4
fi
OS="lin"
if [ "$(uname)" == "Darwin" ]
then
OS="mac"
fi
DOCKER_DIR="$OUTPUT_DIR/docker"
ENV_DIR="$OUTPUT_DIR/env"
LUID="LOCAL_UID=`id -u $USER`"
LGID="LOCAL_GID=`getent group docker | cut -d: -f3`"
DOCKER_DIR="$OUTPUT_DIR/docker"
# As in install.sh, save the running UID/GID, they could not exist yet, during an update for example
if ! grep -q "^LOCAL_UID=" $ENV_DIR/uid.env 2>/dev/null || ! grep -q "^LOCAL_GID=" $ENV_DIR/uid.env 2>/dev/null
then
LUID="LOCAL_UID=`id -u $USER`"
LGID="LOCAL_GID=`id -g $USER`"
mkdir -p $ENV_DIR
(echo $LUID; echo $LGID) > $ENV_DIR/uid.env
fi
# Functions
@@ -79,58 +80,30 @@ function updateLetsEncrypt() {
function updateDatabase() {
pullSetup
if [ $OS == "lin" ]
then
docker run -i --rm --name setup --network container:bitwarden-mssql \
-v $OUTPUT_DIR:/bitwarden -e $LUID -e $LGID bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
else
docker run -i --rm --name setup --network container:bitwarden-mssql \
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
fi
docker run -i --rm --name setup --network container:bitwarden-mssql \
-v $OUTPUT_DIR:/bitwarden --env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
echo "Database update complete"
}
function update() {
pullSetup
if [ $OS == "lin" ]
then
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
-e $LUID -e $LGID bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
else
docker run -i --rm --name setup \
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
fi
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
--env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
}
function printEnvironment() {
pullSetup
if [ $OS == "lin" ]
then
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
-e $LUID -e $LGID bitwarden/setup:$COREVERSION \
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
else
docker run -i --rm --name setup \
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
fi
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
--env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
}
function restart() {
dockerComposeDown
dockerComposePull
updateLetsEncrypt
if [ $OS == "lin" ]
then
mkdir -p $ENV_DIR
(echo $LUID; echo $LGID) > $ENV_DIR/uid.env
fi
dockerComposeUp
dockerPrune
printEnvironment