You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.2 KiB
180 lines
4.2 KiB
#!/usr/bin/env bash |
|
set -e |
|
|
|
cat << "EOF" |
|
_ _ _ _ |
|
| |__ (_) |___ ____ _ _ __ __| | ___ _ __ |
|
| '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \ |
|
| |_) | | |_ \ V V / (_| | | | (_| | __/ | | | |
|
|_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_| |
|
|
|
EOF |
|
|
|
cat << EOF |
|
Open source password management solutions |
|
Copyright 2015-$(date +'%Y'), 8bit Solutions LLC |
|
https://bitwarden.com, https://github.com/bitwarden |
|
|
|
=================================================== |
|
|
|
EOF |
|
|
|
# Setup |
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|
SCRIPT_NAME=$(basename "$0") |
|
SCRIPT_PATH="$DIR/$SCRIPT_NAME" |
|
OUTPUT="$DIR/bwdata" |
|
if [ $# -eq 2 ] |
|
then |
|
OUTPUT=$2 |
|
fi |
|
if command -v docker-compose &> /dev/null |
|
then |
|
dccmd='docker-compose' |
|
else |
|
dccmd='docker compose' |
|
fi |
|
|
|
SCRIPTS_DIR="$OUTPUT/scripts" |
|
BITWARDEN_SCRIPT_URL="https://go.btwrdn.co/bw-sh" |
|
RUN_SCRIPT_URL="https://go.btwrdn.co/bw-sh-run" |
|
VERSION_ENDPOINT="https://go.btwrdn.co/bw-sh-versions" |
|
|
|
# Please do not create pull requests modifying the version numbers. |
|
function getVersion() { |
|
echo $(curl -sL $VERSION_ENDPOINT | grep '^ *"'${1}'":' | awk -F\: '{ print $2 }' | sed -e 's/,$//' -e 's/^"//' -e 's/"$//') |
|
} |
|
|
|
COREVERSION=$(getVersion coreVersion) |
|
WEBVERSION=$(getVersion webVersion) |
|
KEYCONNECTORVERSION=$(getVersion keyConnectorVersion) |
|
|
|
echo "bitwarden.sh version $COREVERSION" |
|
docker --version |
|
if [[ "$dccmd" == "docker compose" ]]; then |
|
$dccmd version |
|
else |
|
$dccmd --version |
|
fi |
|
|
|
echo "" |
|
|
|
# Functions |
|
|
|
function downloadSelf() { |
|
if curl -L -s -w "http_code %{http_code}" -o $SCRIPT_PATH.1 $BITWARDEN_SCRIPT_URL | grep -q "^http_code 20[0-9]" |
|
then |
|
mv $SCRIPT_PATH.1 $SCRIPT_PATH |
|
chmod u+x $SCRIPT_PATH |
|
else |
|
rm -f $SCRIPT_PATH.1 |
|
fi |
|
} |
|
|
|
function downloadRunFile() { |
|
if [ ! -d "$SCRIPTS_DIR" ] |
|
then |
|
mkdir $SCRIPTS_DIR |
|
fi |
|
curl -L -s -o $SCRIPTS_DIR/run.sh $RUN_SCRIPT_URL |
|
chmod u+x $SCRIPTS_DIR/run.sh |
|
rm -f $SCRIPTS_DIR/install.sh |
|
} |
|
|
|
function checkOutputDirExists() { |
|
if [ ! -d "$OUTPUT" ] |
|
then |
|
echo "Cannot find a Bitwarden installation at $OUTPUT." |
|
exit 1 |
|
fi |
|
} |
|
|
|
function checkOutputDirNotExists() { |
|
if [ -d "$OUTPUT/docker" ] |
|
then |
|
echo "Looks like Bitwarden is already installed at $OUTPUT." |
|
exit 1 |
|
fi |
|
} |
|
|
|
function listCommands() { |
|
cat << EOT |
|
Available commands: |
|
|
|
install |
|
start |
|
restart |
|
stop |
|
update |
|
updatedb |
|
updaterun |
|
updateself |
|
updateconf |
|
uninstall |
|
renewcert |
|
rebuild |
|
help |
|
|
|
See more at https://bitwarden.com/help/article/install-on-premise/#script-commands-reference |
|
|
|
EOT |
|
} |
|
|
|
# Commands |
|
|
|
case $1 in |
|
"install") |
|
checkOutputDirNotExists |
|
mkdir -p $OUTPUT |
|
downloadRunFile |
|
$SCRIPTS_DIR/run.sh install $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"start" | "restart") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh restart $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"update") |
|
checkOutputDirExists |
|
downloadRunFile |
|
$SCRIPTS_DIR/run.sh update $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"rebuild") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh rebuild $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"updateconf") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh updateconf $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"updatedb") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh updatedb $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"stop") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh stop $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"renewcert") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh renewcert $OUTPUT $COREVERSION $WEBVERSION $KEYCONNECTORVERSION |
|
;; |
|
"updaterun") |
|
checkOutputDirExists |
|
downloadRunFile |
|
;; |
|
"updateself") |
|
downloadSelf && echo "Updated self." && exit |
|
;; |
|
"uninstall") |
|
checkOutputDirExists |
|
$SCRIPTS_DIR/run.sh uninstall $OUTPUT |
|
;; |
|
"help") |
|
listCommands |
|
;; |
|
*) |
|
echo "No command found." |
|
echo |
|
listCommands |
|
esac
|
|
|