Files
meteor/scripts/admin/build-tools-tree.sh
Felix Rabe 3431c66c16 Fix occurrences of "cd dirname $0"
They are not safe for spaces in paths. There might be other places to look for trouble.

I've run the following command to produce this commit: (on OS X, copy-and-pasting the below exactly)

    find . -type f -name '*.sh' -print0  |  # Find all .sh files
        xargs -0 fgrep -H -- '`'         |  # See all places with backticks in them
        fgrep 'cd `dirname $0'           |  # I deemed these problematic (variable assignments are safe)
        cut -d ':' -f 1                  |  # Take the <file> from <file>:<line> produced by "grep -H"
        tr '\n' '\0'                     |  # Also here, spaces can be problematic - always do "xargs -0"!
        xargs -0 -- sed -i '' 's/cd `dirname $0`/cd "`dirname "$0"`"/g'

The significance of adding the two levels of "'s can be verified by running the following in your Terminal:

    $ node -e 'console.log(process.argv.splice(1))' -- `echo 1   2`
    [ '1', '2' ]

    $ node -e 'console.log(process.argv.splice(1))' -- "`echo 1   2`"
    [ '1 2' ]

    $ node -e 'console.log(process.argv.splice(1))' -- "`echo "1   2"`"
    [ '1   2' ]
2014-05-07 17:51:09 -07:00

64 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# This script fills TARGET_DIR with what should go into
# ~/.meteor/tools/VERSION
# It does not set up the top-level springboard file in
# ~/.meteor/tools or the ~/.meteor/meteor symlink.
set -e
set -u
cd "`dirname "$0"`"/../..
if [ "$TARGET_DIR" == "" ] ; then
echo 'Must set $TARGET_DIR'
exit 1
fi
# Make sure that the entire contents $TARGET_DIR is what we placed
# there
if [ -e "$TARGET_DIR" ] ; then
echo "$TARGET_DIR already exists"
exit 1
fi
echo "Setting up tools tree in $TARGET_DIR"
# make sure dev bundle exists before trying to install
./meteor --get-ready
function CPR {
tar -c --exclude .meteor/local "$1" | tar -x -C "$2"
}
# The tools starts as a copy of the dev bundle.
cp -a dev_bundle "$TARGET_DIR"
# Copy over files and directories that we want in the tarball. Keep this list
# synchronized with the files used in the $TOOLS_VERSION calculation below. The
# "meteor" script file contains the version number of the dev bundle, so we
# include that instead of the (arch-specific) bundle itself in sha calculation.
cp LICENSE.txt "$TARGET_DIR"
cp meteor "$TARGET_DIR/bin"
CPR tools "$TARGET_DIR"
CPR examples "$TARGET_DIR"
# Script is not actually used, but it's nice to distribute it for users.
cp scripts/admin/launch-meteor "$TARGET_DIR"
# Trim unfinished examples.
rm -rf "$TARGET_DIR"/examples/unfinished
rm -rf "$TARGET_DIR"/examples/other
# mark directory with current git sha
git rev-parse HEAD > "$TARGET_DIR/.git_version.txt"
# generate tools version: directory hash that depends only on file contents and
# permissions but nothing else, eg modification time or build outputs. This
# version is treated fully opaquely, so to make it a little more attractive we
# just use the first ten characters.
echo -n "Computing tools version... "
TOOLS_VERSION=$(git ls-tree HEAD \
LICENSE.txt meteor tools examples scripts/admin/launch-meteor \
| shasum | cut -c 1-10) # shasum's output looks like: 'SHA -'
echo $TOOLS_VERSION
echo -n "$TOOLS_VERSION" > "$TARGET_DIR/.tools_version.txt"