1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

safety checks on output dir

This commit is contained in:
Kyle Spearrin 2017-09-18 12:11:03 -04:00
parent 934b2c535b
commit c924af2ade
2 changed files with 61 additions and 21 deletions

View File

@ -40,29 +40,30 @@ if($output -eq "") {
$output="${dir}\bitwarden" $output="${dir}\bitwarden"
} }
if(!(Test-Path -Path $output)) {
New-Item -ItemType directory -Path $output | Out-Null
}
$scriptsDir = "${output}\scripts" $scriptsDir = "${output}\scripts"
$dockerDir = "${output}\docker" $dockerDir = "${output}\docker"
$githubBaseUrl = "https://raw.githubusercontent.com/bitwarden/core/master" $githubBaseUrl = "https://raw.githubusercontent.com/bitwarden/core/master"
if(!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
# Functions # Functions
function Download-Self { function Download-Self {
if(!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
Invoke-RestMethod -OutFile $scriptPath -Uri "${githubBaseUrl}/scripts/bitwarden.ps1" Invoke-RestMethod -OutFile $scriptPath -Uri "${githubBaseUrl}/scripts/bitwarden.ps1"
} }
function Download-Install { function Download-Install {
if(!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
Invoke-RestMethod -OutFile $scriptsDir\install.ps1 ` -Uri "${githubBaseUrl}/scripts/install.ps1" Invoke-RestMethod -OutFile $scriptsDir\install.ps1 ` -Uri "${githubBaseUrl}/scripts/install.ps1"
} }
function Download-Run-File { function Download-Run-File {
if(!(Test-Path -Path $scriptsDir)) {
New-Item -ItemType directory -Path $scriptsDir | Out-Null
}
Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri "${githubBaseUrl}/scripts/run.ps1" Invoke-RestMethod -OutFile $scriptsDir\run.ps1 -Uri "${githubBaseUrl}/scripts/run.ps1"
} }
@ -73,18 +74,28 @@ function Download-Docker-Files {
Invoke-RestMethod -OutFile $dockerDir\mssql.env -Uri "${githubBaseUrl}/docker/mssql.env" Invoke-RestMethod -OutFile $dockerDir\mssql.env -Uri "${githubBaseUrl}/docker/mssql.env"
} }
function Download-All-Files { function Check-Output-Dir-Exists {
Download-Run-File if(!(Test-Path -Path $output)) {
Download-Docker-Files throw "Cannot find a bitwarden installation at $output."
}
}
function Check-Output-Dir-Not-Exists {
if(Test-Path -Path $output) {
throw "Looks like bitwarden is already installed at $output."
}
} }
# Commands # Commands
if($install) { if($install) {
Check-Output-Dir-Not-Exists
New-Item -ItemType directory -Path $output | Out-Null
Download-Install Download-Install
Invoke-Expression "$scriptsDir\install.ps1 -outputDir $output" Invoke-Expression "$scriptsDir\install.ps1 -outputDir $output"
} }
elseif($start -Or $restart) { elseif($start -Or $restart) {
Check-Output-Dir-Exists
if(!(Test-Path -Path $dockerDir)) { if(!(Test-Path -Path $dockerDir)) {
New-Item -ItemType directory -Path $dockerDir | Out-Null New-Item -ItemType directory -Path $dockerDir | Out-Null
Download-All-Files Download-All-Files
@ -93,6 +104,7 @@ elseif($start -Or $restart) {
Invoke-Expression "$scriptsDir\run.ps1 -restart -outputDir $output -dockerDir $dockerDir" Invoke-Expression "$scriptsDir\run.ps1 -restart -outputDir $output -dockerDir $dockerDir"
} }
elseif($update) { elseif($update) {
Check-Output-Dir-Exists
if(Test-Path -Path $dockerDir) { if(Test-Path -Path $dockerDir) {
Remove-Item -Recurse -Force $dockerDir | Out-Null Remove-Item -Recurse -Force $dockerDir | Out-Null
} }
@ -103,12 +115,15 @@ elseif($update) {
Invoke-Expression "$scriptsDir\run.ps1 -updatedb -outputDir $output -dockerDir $dockerDir" Invoke-Expression "$scriptsDir\run.ps1 -updatedb -outputDir $output -dockerDir $dockerDir"
} }
elseif($updatedb) { elseif($updatedb) {
Check-Output-Dir-Exists
Invoke-Expression "$scriptsDir\run.ps1 -updatedb -outputDir $output -dockerDir $dockerDir" Invoke-Expression "$scriptsDir\run.ps1 -updatedb -outputDir $output -dockerDir $dockerDir"
} }
elseif($stop) { elseif($stop) {
Check-Output-Dir-Exists
Invoke-Expression "$scriptsDir\run.ps1 -stop -outputDir $output -dockerDir $dockerDir" Invoke-Expression "$scriptsDir\run.ps1 -stop -outputDir $output -dockerDir $dockerDir"
} }
elseif($updateself) { elseif($updateself) {
Check-Output-Dir-Exists
Download-Self Download-Self
echo "Updated self." echo "Updated self."
} }

View File

@ -35,11 +35,6 @@ then
OUTPUT=$2 OUTPUT=$2
fi fi
if [ ! -d "$OUTPUT" ]
then
mkdir $OUTPUT
fi
OS="linux" OS="linux"
if [ "$(uname)" == "Darwin" ] if [ "$(uname)" == "Darwin" ]
then then
@ -50,24 +45,31 @@ SCRIPTS_DIR="$OUTPUT/scripts"
DOCKER_DIR="$OUTPUT/docker" DOCKER_DIR="$OUTPUT/docker"
GITHUB_BASE_URL="https://raw.githubusercontent.com/bitwarden/core/master" GITHUB_BASE_URL="https://raw.githubusercontent.com/bitwarden/core/master"
if [ ! -d "$SCRIPTS_DIR" ]
then
mkdir $SCRIPTS_DIR
fi
# Functions # Functions
function downloadSelf() { function downloadSelf() {
if [ ! -d "$SCRIPTS_DIR" ]
then
mkdir $SCRIPTS_DIR
fi
curl -s -o $SCRIPT_PATH $GITHUB_BASE_URL/scripts/bitwarden.sh curl -s -o $SCRIPT_PATH $GITHUB_BASE_URL/scripts/bitwarden.sh
chmod u+x $SCRIPT_PATH chmod u+x $SCRIPT_PATH
} }
function downloadInstall() { function downloadInstall() {
if [ ! -d "$SCRIPTS_DIR" ]
then
mkdir $SCRIPTS_DIR
fi
curl -s -o $SCRIPTS_DIR/install.sh $GITHUB_BASE_URL/scripts/install.sh curl -s -o $SCRIPTS_DIR/install.sh $GITHUB_BASE_URL/scripts/install.sh
chmod u+x $SCRIPTS_DIR/install.sh chmod u+x $SCRIPTS_DIR/install.sh
} }
function downloadRunFile() { function downloadRunFile() {
if [ ! -d "$SCRIPTS_DIR" ]
then
mkdir $SCRIPTS_DIR
fi
curl -s -o $SCRIPTS_DIR/run.sh $GITHUB_BASE_URL/scripts/run.sh curl -s -o $SCRIPTS_DIR/run.sh $GITHUB_BASE_URL/scripts/run.sh
chmod u+x $SCRIPTS_DIR/run.sh chmod u+x $SCRIPTS_DIR/run.sh
} }
@ -84,14 +86,33 @@ function downloadAllFiles() {
downloadDockerFiles downloadDockerFiles
} }
function checkOutputDirExists() {
if [ ! -d "$OUTPUT" ]
then
echo "Cannot find a bitwarden installation at $OUTPUT."
exit 1
fi
}
function checkOutputDirNotExists() {
if [ -d "$OUTPUT" ]
then
echo "Looks like bitwarden is already installed at $OUTPUT."
exit 1
fi
}
# Commands # Commands
if [ "$1" == "install" ] if [ "$1" == "install" ]
then then
checkOutputDirNotExists
mkdir $OUTPUT
downloadInstall downloadInstall
$SCRIPTS_DIR/install.sh $OUTPUT $SCRIPTS_DIR/install.sh $OUTPUT
elif [ "$1" == "start" -o "$1" == "restart" ] elif [ "$1" == "start" -o "$1" == "restart" ]
then then
checkOutputDirExists
if [ ! -d "$DOCKER_DIR" ] if [ ! -d "$DOCKER_DIR" ]
then then
mkdir $DOCKER_DIR mkdir $DOCKER_DIR
@ -101,6 +122,7 @@ then
$SCRIPTS_DIR/run.sh restart $OUTPUT $DOCKER_DIR $SCRIPTS_DIR/run.sh restart $OUTPUT $DOCKER_DIR
elif [ "$1" == "update" ] elif [ "$1" == "update" ]
then then
checkOutputDirExists
if [ -d "$DOCKER_DIR" ] if [ -d "$DOCKER_DIR" ]
then then
rm -rf $DOCKER_DIR rm -rf $DOCKER_DIR
@ -112,12 +134,15 @@ then
$SCRIPTS_DIR/run.sh updatedb $OUTPUT $DOCKER_DIR $SCRIPTS_DIR/run.sh updatedb $OUTPUT $DOCKER_DIR
elif [ "$1" == "updatedb" ] elif [ "$1" == "updatedb" ]
then then
checkOutputDirExists
$SCRIPTS_DIR/run.sh updatedb $OUTPUT $DOCKER_DIR $SCRIPTS_DIR/run.sh updatedb $OUTPUT $DOCKER_DIR
elif [ "$1" == "stop" ] elif [ "$1" == "stop" ]
then then
checkOutputDirExists
$SCRIPTS_DIR/run.sh stop $OUTPUT $DOCKER_DIR $SCRIPTS_DIR/run.sh stop $OUTPUT $DOCKER_DIR
elif [ "$1" == "updateself" ] elif [ "$1" == "updateself" ]
then then
checkOutputDirExists
downloadSelf downloadSelf
echo "Updated self." echo "Updated self."
else else