Properly handle paths with spaces in shell scripts.

This commit is contained in:
Lucas Kolstad 2017-07-28 21:34:59 -07:00 committed by Sergio Benitez
parent 38895fce13
commit 634447b3b8
4 changed files with 34 additions and 36 deletions

View File

@ -1,11 +1,11 @@
#! /usr/bin/env bash #! /usr/bin/env bash
SCRIPT_PATH=$(cd "$(dirname "$0")" ; pwd -P) SCRIPT_PATH=$(cd "$(dirname "$0")" ; pwd -P)
DATABASE_URL=${SCRIPT_PATH}/db/db.sql DATABASE_URL="${SCRIPT_PATH}/db/db.sql"
pushd $SCRIPT_PATH > /dev/null pushd "${SCRIPT_PATH}" > /dev/null
# clear an existing database # clear an existing database
rm -f $DATABASE_URL rm -f "${DATABASE_URL}"
# install the diesel CLI tools if they're not installed # install the diesel CLI tools if they're not installed
if ! command -v diesel >/dev/null 2>&1; then if ! command -v diesel >/dev/null 2>&1; then
@ -13,7 +13,7 @@ pushd $SCRIPT_PATH > /dev/null
fi fi
# create db/db.sql # create db/db.sql
diesel migration --database-url=$DATABASE_URL run > /dev/null diesel migration --database-url="${DATABASE_URL}" run > /dev/null
popd > /dev/null popd > /dev/null
echo "export DATABASE_URL=$DATABASE_URL" echo "export DATABASE_URL=\"${DATABASE_URL}\""

View File

@ -7,12 +7,12 @@ set -e
# Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR # Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/config.sh source "${SCRIPT_DIR}/config.sh"
function mk_doc() { function mk_doc() {
local dir=$1 local dir=$1
local flag=$2 local flag=$2
pushd $dir > /dev/null 2>&1 pushd "${dir}" > /dev/null 2>&1
echo ":: Documenting '${dir}'..." echo ":: Documenting '${dir}'..."
cargo doc --no-deps --all-features cargo doc --no-deps --all-features
popd > /dev/null 2>&1 popd > /dev/null 2>&1
@ -22,9 +22,9 @@ function mk_doc() {
cargo clean cargo clean
cargo update cargo update
mk_doc $LIB_DIR mk_doc "${LIB_DIR}"
mk_doc $CODEGEN_DIR mk_doc "${CODEGEN_DIR}"
mk_doc $CONTRIB_DIR mk_doc "${CONTRIB_DIR}"
# Blank index, for redirection. # Blank index, for redirection.
touch ${DOC_DIR}/index.html touch "${DOC_DIR}/index.html"

View File

@ -7,7 +7,7 @@ set -e
# Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR # Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/config.sh source "${SCRIPT_DIR}/config.sh"
if ! [ -z "$(git status --porcelain)" ]; then if ! [ -z "$(git status --porcelain)" ]; then
echo "There are uncommited changes! Aborting." echo "There are uncommited changes! Aborting."
@ -17,14 +17,14 @@ fi
# Ensure everything passes before trying to publish. # Ensure everything passes before trying to publish.
echo ":::: Running test suite..." echo ":::: Running test suite..."
cargo clean cargo clean
${SCRIPT_DIR}/test.sh bash "${SCRIPT_DIR}/test.sh"
# Temporarily remove the dependency on codegen from core so crates.io verifies. # Temporarily remove the dependency on codegen from core so crates.io verifies.
sed -i.bak 's/rocket_codegen.*//' ${LIB_DIR}/Cargo.toml sed -i.bak 's/rocket_codegen.*//' "${LIB_DIR}/Cargo.toml"
# Publish all the things. # Publish all the things.
for dir in "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}"; do for dir in "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}"; do
pushd ${dir} pushd "${dir}"
echo ":::: Publishing '${dir}..." echo ":::: Publishing '${dir}..."
# We already checked things ourselves. Don't spend time reverifying. # We already checked things ourselves. Don't spend time reverifying.
cargo publish --no-verify --allow-dirty cargo publish --no-verify --allow-dirty
@ -32,4 +32,4 @@ for dir in "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}"; do
done done
# Restore the original core Cargo.toml. # Restore the original core Cargo.toml.
mv ${LIB_DIR}/Cargo.toml.bak ${LIB_DIR}/Cargo.toml mv "${LIB_DIR}/Cargo.toml.bak" "${LIB_DIR}/Cargo.toml"

View File

@ -3,7 +3,7 @@ set -e
# Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR # Brings in: ROOT_DIR, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/config.sh source "${SCRIPT_DIR}/config.sh"
# Add Cargo to PATH. # Add Cargo to PATH.
export PATH=${HOME}/.cargo/bin:${PATH} export PATH=${HOME}/.cargo/bin:${PATH}
@ -11,14 +11,14 @@ export PATH=${HOME}/.cargo/bin:${PATH}
# Checks that the versions for Cargo projects $@ all match # Checks that the versions for Cargo projects $@ all match
function check_versions_match() { function check_versions_match() {
local last_version="" local last_version=""
for dir in $@; do for dir in "${@}"; do
local cargo_toml="${dir}/Cargo.toml" local cargo_toml="${dir}/Cargo.toml"
if ! [ -f "${cargo_toml}" ]; then if ! [ -f "${cargo_toml}" ]; then
echo "Cargo configuration file '${cargo_toml}' does not exist." echo "Cargo configuration file '${cargo_toml}' does not exist."
exit 1 exit 1
fi fi
local version=$(grep version ${cargo_toml} | head -n 1 | cut -d' ' -f3) local version=$(grep version "${cargo_toml}" | head -n 1 | cut -d' ' -f3)
if [ -z "${last_version}" ]; then if [ -z "${last_version}" ]; then
last_version="${version}" last_version="${version}"
elif ! [ "${version}" = "${last_version}" ]; then elif ! [ "${version}" = "${last_version}" ]; then
@ -31,7 +31,7 @@ function check_versions_match() {
# Ensures there are no tabs in any file. # Ensures there are no tabs in any file.
function ensure_tab_free() { function ensure_tab_free() {
local tab=$(printf '\t') local tab=$(printf '\t')
local matches=$(grep -I -R "${tab}" $ROOT_DIR | egrep -v '/target|/.git|LICENSE') local matches=$(grep -I -R "${tab}" "${ROOT_DIR}" | egrep -v '/target|/.git|LICENSE')
if ! [ -z "${matches}" ]; then if ! [ -z "${matches}" ]; then
echo "Tab characters were found in the following:" echo "Tab characters were found in the following:"
echo "${matches}" echo "${matches}"
@ -41,7 +41,7 @@ function ensure_tab_free() {
# Ensures there are no files with trailing whitespace. # Ensures there are no files with trailing whitespace.
function ensure_trailing_whitespace_free() { function ensure_trailing_whitespace_free() {
local matches=$(egrep -I -R " +$" $ROOT_DIR | egrep -v "/target|/.git") local matches=$(egrep -I -R " +$" "${ROOT_DIR}" | egrep -v "/target|/.git")
if ! [ -z "${matches}" ]; then if ! [ -z "${matches}" ]; then
echo "Trailing whitespace was found in the following:" echo "Trailing whitespace was found in the following:"
echo "${matches}" echo "${matches}"
@ -50,13 +50,12 @@ function ensure_trailing_whitespace_free() {
} }
function bootstrap_examples() { function bootstrap_examples() {
for file in ${EXAMPLES_DIR}/*; do while read -r file; do
if [ -d "${file}" ]; then
bootstrap_script="${file}/bootstrap.sh" bootstrap_script="${file}/bootstrap.sh"
if [ -x "${bootstrap_script}" ]; then if [ -x "${bootstrap_script}" ]; then
echo " Bootstrapping ${file}..." echo " Bootstrapping ${file}..."
env_vars=$(${bootstrap_script}) env_vars=$(bash "${bootstrap_script}")
bootstrap_result=$? bootstrap_result=$?
if [ $bootstrap_result -ne 0 ]; then if [ $bootstrap_result -ne 0 ]; then
echo " Running bootstrap script (${bootstrap_script}) failed!" echo " Running bootstrap script (${bootstrap_script}) failed!"
@ -65,8 +64,7 @@ function bootstrap_examples() {
eval $env_vars eval $env_vars
fi fi
fi fi
fi done < <(find "${EXAMPLES_DIR}" -maxdepth 1 -type d)
done
} }
echo ":: Ensuring all crate versions match..." echo ":: Ensuring all crate versions match..."
@ -81,7 +79,7 @@ ensure_trailing_whitespace_free
echo ":: Updating dependencies..." echo ":: Updating dependencies..."
cargo update cargo update
echo ":: Boostrapping examples..." echo ":: Bootstrapping examples..."
bootstrap_examples bootstrap_examples
echo ":: Building and testing libraries..." echo ":: Building and testing libraries..."