1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 13:08:17 -05:00

condense scripts into run script

This commit is contained in:
Kyle Spearrin 2017-08-23 16:15:42 -04:00
parent 7fb312bb48
commit a34e19206c
10 changed files with 206 additions and 140 deletions

View File

@ -5,6 +5,7 @@ param (
[switch] $stop,
[switch] $update,
[switch] $updatedb,
[switch] $updateself,
[string] $output = ""
)
@ -22,8 +23,13 @@ Write-Host "
Open source password management solutions
Copyright 2015-${year}, 8bit Solutions LLC
https://bitwarden.com, https://github.com/bitwarden
===================================================
"
# Setup
$scriptName = $MyInvocation.MyCommand.Name
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
if($output -eq "") {
$output="${dir}\bitwarden"
@ -41,26 +47,45 @@ if(!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
function Download-Run-Files {
Invoke-RestMethod -OutFile $scriptsDir\start.ps1 -Uri "${githubBaseUrl}/scripts/start.ps1"
Invoke-RestMethod -OutFile $scriptsDir\stop.ps1 -Uri "${githubBaseUrl}/scripts/stop.ps1"
# Functions
function Download-Self {
Invoke-RestMethod -OutFile $scriptsDir\$scriptName -Uri "${githubBaseUrl}/scripts/bitwarden.ps1"
}
function Download-Install {
Invoke-RestMethod -OutFile $scriptsDir\install.ps1 ` -Uri "${githubBaseUrl}/scripts/install.ps1"
}
function Download-Run-File {
Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri "${githubBaseUrl}/scripts/run.ps1"
}
function Download-Docker-Files {
Invoke-RestMethod -OutFile $dockerDir\docker-compose.yml -Uri "${githubBaseUrl}/docker/docker-compose.yml"
Invoke-RestMethod -OutFile $dockerDir\docker-compose.macwin.yml ` -Uri "${githubBaseUrl}/docker/docker-compose.macwin.yml"
Invoke-RestMethod -OutFile $dockerDir\global.env -Uri "${githubBaseUrl}/docker/global.env"
Invoke-RestMethod -OutFile $dockerDir\mssql.env -Uri "${githubBaseUrl}/docker/mssql.env"
}
function Download-All-Files {
Download-Run-File
Download-Docker-Files
}
# Commands
if($install) {
Invoke-RestMethod -OutFile $scriptsDir\install.ps1 ` -Uri "${githubBaseUrl}/scripts/install.ps1"
Download-Install
Invoke-Expression "$scriptsDir\install.ps1 -outputDir $output"
}
elseif($start -Or $restart) {
if(!(Test-Path -Path $dockerDir)) {
New-Item -ItemType directory -Path $dockerDir | Out-Null
Download-Run-Files
Download-All-Files
}
Invoke-Expression "$scriptsDir\start.ps1 -outputDir $output -dockerDir $dockerDir"
Invoke-Expression "$scriptsDir\run.ps1 -restart -outputDir $output -dockerDir $dockerDir"
}
elseif($update) {
if(Test-Path -Path $dockerDir) {
@ -68,15 +93,18 @@ elseif($update) {
}
New-Item -ItemType directory -Path $dockerDir | Out-Null
Download-Run-Files
Invoke-Expression "$scriptsDir\start.ps1 -outputDir $output -dockerDir $dockerDir"
Download-All-Files
Invoke-Expression "$scriptsDir\run.ps1 -restart -outputDir $output -dockerDir $dockerDir"
}
elseif($updatedb) {
Invoke-RestMethod -OutFile $scriptsDir\update-db.ps1 -Uri "${githubBaseUrl}/scripts/update-db.ps1"
Invoke-Expression "$scriptsDir\update-db.ps1 -outputDir $output"
Invoke-Expression "$scriptsDir\run.ps1 -updatedb -outputDir $output -dockerDir $dockerDir"
}
elseif($stop) {
Invoke-Expression "$scriptsDir\stop.ps1 -dockerDir $dockerDir"
Invoke-Expression "$scriptsDir\run.ps1 -stop -outputDir $output -dockerDir $dockerDir"
}
elseif($updateself) {
Download-Self
echo "Updated self."
}
else {
echo "No command found."

View File

@ -15,8 +15,13 @@ Open source password management solutions
Copyright 2015-$(date +'%Y'), 8bit Solutions LLC
https://bitwarden.com, https://github.com/bitwarden
===================================================
EOF
# Setup
SCRIPT_NAME=`basename "$0"`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTPUT="$DIR/bitwarden"
if [ $# -eq 2 ]
@ -44,30 +49,50 @@ then
mkdir $SCRIPTS_DIR
fi
function downloadRunFiles() {
curl -s -o $SCRIPTS_DIR/start.sh $GITHUB_BASE_URL/scripts/start.sh
chmod u+x $SCRIPTS_DIR/start.sh
curl -s -o $SCRIPTS_DIR/stop.sh $GITHUB_BASE_URL/scripts/stop.sh
chmod u+x $SCRIPTS_DIR/stop.sh
# Functions
function downloadSelf() {
curl -s -o $SCRIPTS_DIR/$SCRIPT_NAME $GITHUB_BASE_URL/scripts/bitwarden.sh
chmod u+x $SCRIPTS_DIR/$SCRIPT_NAME
}
function downloadInstall() {
curl -s -o $SCRIPTS_DIR/install.sh $GITHUB_BASE_URL/scripts/install.sh
chmod u+x $SCRIPTS_DIR/install.sh
}
function downloadRunFile() {
curl -s -o $SCRIPTS_DIR/run.sh $GITHUB_BASE_URL/scripts/run.sh
chmod u+x $SCRIPTS_DIR/run.sh
}
function downloadDockerFiles() {
curl -s -o $DOCKER_DIR/docker-compose.yml $GITHUB_BASE_URL/docker/docker-compose.yml
curl -s -o $DOCKER_DIR/docker-compose.$OS.yml $GITHUB_BASE_URL/docker/docker-compose.$OS.yml
curl -s -o $DOCKER_DIR/global.env $GITHUB_BASE_URL/docker/global.env
curl -s -o $DOCKER_DIR/mssql.env $GITHUB_BASE_URL/docker/mssql.env
}
function downloadAllFiles() {
downloadRunFile
downloadDockerFiles
}
# Commands
if [ "$1" == "install" ]
then
curl -s -o $SCRIPTS_DIR/install.sh $GITHUB_BASE_URL/scripts/install.sh
chmod u+x $SCRIPTS_DIR/install.sh
downloadInstall
$SCRIPTS_DIR/install.sh $OUTPUT
elif [ "$1" == "start" -o "$1" == "restart" ]
then
if [ ! -d "$DOCKER_DIR" ]
then
mkdir $DOCKER_DIR
downloadRunFiles
downloadAllFiles
fi
$SCRIPTS_DIR/start.sh $OUTPUT $DOCKER_DIR
$SCRIPTS_DIR/run.sh restart $OUTPUT $DOCKER_DIR
elif [ "$1" == "update" ]
then
if [ -d "$DOCKER_DIR" ]
@ -76,16 +101,18 @@ then
fi
mkdir $DOCKER_DIR
downloadRunFiles
$SCRIPTS_DIR/start.sh $OUTPUT $DOCKER_DIR
downloadAllFiles
$SCRIPTS_DIR/run.sh restart $OUTPUT $DOCKER_DIR
elif [ "$1" == "updatedb" ]
then
curl -s -o $SCRIPTS_DIR/update-db.sh $GITHUB_BASE_URL/scripts/update-db.sh
chmod u+x $SCRIPTS_DIR/update-db.sh
$SCRIPTS_DIR/update-db.sh $OUTPUT
$SCRIPTS_DIR/run.sh updatedb $OUTPUT $DOCKER_DIR
elif [ "$1" == "stop" ]
then
$SCRIPTS_DIR/stop.sh $DOCKER_DIR
$SCRIPTS_DIR/run.sh stop $OUTPUT $DOCKER_DIR
elif [ "$1" == "updateself" ]
then
downloadSelf
echo "Updated self."
else
echo "No command found."
fi

57
scripts/run.ps1 Normal file
View File

@ -0,0 +1,57 @@
param (
[string]$outputDir = "../.",
[string]$dockerDir = "",
[switch] $start,
[switch] $restart,
[switch] $stop,
[switch] $updatedb
)
# Setup
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
if($dockerDir -eq "") {
$dockerDir="${dir}\..\docker"
}
# Functions
function Docker-Compose-Up {
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml up -d
}
function Docker-Compose-Down {
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml down
}
function Docker-Prune {
docker image prune -f
}
function Update-Lets-Encrypt {
if(Test-Path -Path "${outputDir}/letsencrypt") {
docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot `
renew --logs-dir /etc/letsencrypt/logs
}
}
function Update-Database {
docker run -it --rm --name setup --network container:mssql -v ${outputDir}:/bitwarden bitwarden/setup `
dotnet Setup.dll -update 1 -db 1
echo "Database update complete"
}
# Commands
if($start -Or $restart) {
Docker-Compose-Down
Update-Lets-Encrypt
Docker-Compose-Up
Docker-Prune
}
elseif($stop) {
Docker-Compose-Down
}
elseif($updatedb) {
Update-Database
}

68
scripts/run.sh Normal file
View File

@ -0,0 +1,68 @@
#!/usr/bin/env bash
set -e
# Setup
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTPUT_DIR="../."
if [ $# -eq 2 ]
then
OUTPUT_DIR=$2
fi
DOCKER_DIR=$DIR/../docker
if [ $# -eq 3 ]
then
DOCKER_DIR=$3
fi
OS="linux"
if [ "$(uname)" == "Darwin" ]
then
OS="macwin"
fi
# Functions
function dockerComposeUp() {
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml up -d
}
function dockerComposeDown() {
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml down
}
function dockerPrune() {
docker image prune -f
}
function updateLetsEncrypt() {
if [ -d "${outputDir}/letsencrypt" ]
then
docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \
renew --logs-dir /etc/letsencrypt/logs
fi
}
function updateDatabase() {
docker run -it --rm --name setup --network container:mssql -v $OUTPUT_DIR:/bitwarden bitwarden/setup \
dotnet Setup.dll -update 1 -db 1
echo "Database update complete"
}
# Commands
if [ "$1" == "start" -o "$1" == "restart" ]
then
dockerComposeDown
updateLetsEncrypt
dockerComposeUp
dockerPrune
elif [ "$1" == "stop" ]
then
dockerComposeDown
elif [ "$1" == "upadtedb" ]
then
updateDatabase
fi

View File

@ -1,23 +0,0 @@
param (
[string]$outputDir = "../.",
[string]$dockerDir = ""
)
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
if($dockerDir -eq "") {
$dockerDir="${dir}\..\docker"
}
docker --version
docker-compose --version
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml down
$letsEncryptPath = "${outputDir}/letsencrypt"
if(Test-Path -Path $letsEncryptPath) {
docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $outputDir/letsencrypt:/etc/letsencrypt/ certbot/certbot `
renew --logs-dir /etc/letsencrypt/logs
}
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml up -d
docker image prune -f

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTPUT_DIR="../."
if [ $# -eq 1 ]
then
OUTPUT_DIR=$1
fi
DOCKER_DIR=$DIR/../docker
if [ $# -eq 2 ]
then
DOCKER_DIR=$2
fi
OS="linux"
if [ "$(uname)" == "Darwin" ]
then
OS="macwin"
fi
docker --version
docker-compose --version
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml down
LETS_ENCRYPT_PATH="${outputDir}/letsencrypt"
if [ -d "${LETS_ENCRYPT_PATH}" ]
then
docker run -it --rm --name certbot -p 443:443 -p 80:80 -v $OUTPUT_DIR/letsencrypt:/etc/letsencrypt/ certbot/certbot \
renew --logs-dir /etc/letsencrypt/logs
fi
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml up -d
docker image prune -f

View File

@ -1,13 +0,0 @@
param (
[string] $dockerDir = ""
)
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
if($dockerDir -eq "") {
$dockerDir="${dir}\..\docker"
}
docker --version
docker-compose --version
docker-compose -f ${dockerDir}\docker-compose.yml -f ${dockerDir}\docker-compose.macwin.yml down

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOCKER_DIR=$DIR/../docker
if [ $# -eq 1 ]
then
DOCKER_DIR=$1
fi
OS="linux"
if [ "$(uname)" == "Darwin" ]
then
OS="macwin"
fi
docker --version
docker-compose --version
docker-compose -f $DOCKER_DIR/docker-compose.yml -f $DOCKER_DIR/docker-compose.$OS.yml down

View File

@ -1,8 +0,0 @@
param (
[string]$outputDir = "../."
)
docker run -it --rm --name setup --network container:mssql -v ${outputDir}:/bitwarden bitwarden/setup `
dotnet Setup.dll -update 1 -db 1
echo "Database update complete"

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
set -e
OUTPUT_DIR="../."
if [ $# -eq 1 ]
then
OUTPUT_DIR=$1
fi
docker run -it --rm --name setup --network container:mssql -v $OUTPUT_DIR:/bitwarden bitwarden/setup \
dotnet Setup.dll -update 1 -db 1
echo "Database update complete"