oojs update scripts: Use quotes to prevent globbing and word splitting
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 20 Jul 2014 19:54:00 +0000 (21:54 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 20 Jul 2014 19:56:07 +0000 (21:56 +0200)
Change-Id: I69a0782fafbf2e8ce943ab819ccba83ac3e92f71

maintenance/resources/update-oojs-ui.sh
maintenance/resources/update-oojs.sh

index e1ccb46..1b35292 100755 (executable)
@@ -9,12 +9,12 @@ then
        exit 1
 fi
 
-TARGET_REPO=$(cd $(dirname $0)/../..; pwd)
+TARGET_REPO=$(cd "$(dirname $0)/../.."; pwd)
 TARGET_DIR=resources/lib/oojs-ui
 UI_REPO=$1
 
 function oojsuihash() {
-       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+       grep "OOjs UI v" "$TARGET_REPO/$TARGET_DIR/oojs-ui.js" \
                | head -n 1 \
                | grep -Eo '\([a-z0-9]+\)' \
                | sed 's/^(//' \
@@ -22,19 +22,19 @@ function oojsuihash() {
 }
 
 function oojsuitag() {
-       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+       grep "OOjs UI v" "$TARGET_REPO/$TARGET_DIR/oojs-ui.js" \
                | head -n 1 \
                | grep -Eo '\bv[0-9a-z.-]+\b'
 }
 
 function oojsuiversion() {
-       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+       grep "OOjs UI v" "$TARGET_REPO/$TARGET_DIR/oojs-ui.js" \
                | head -n 1 \
                | grep -Eo '\bv[0-9a-z.-]+\b.*$'
 }
 
 # Prepare working tree
-cd $TARGET_REPO &&
+cd "$TARGET_REPO" &&
 git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
 git checkout -B upstream-oojsui origin/master || exit 1
 
@@ -48,10 +48,10 @@ then
 fi
 if [ "$OLDHASH" == "" ]
 then
-       OLDHASH=$(git rev-parse $OLDTAG)
+       OLDHASH=$(git rev-parse "$OLDTAG")
        if [ $? != 0 ]
        then
-               echo Could not find OOjs UI version
+               echo "Could not find OOjs UI version"
                cd -
                exit 1
        fi
@@ -72,13 +72,13 @@ NEWCHANGESDISPLAY=$(git log $OLDHASH.. --oneline --no-merges --reverse --color=a
 
 # Copy files
 # - Exclude the default non-svg stylesheet
-rsync --recursive --delete --force --exclude 'oojs-ui.css' --exclude 'oojs-ui*.rtl.css' ./dist/ $TARGET_REPO/$TARGET_DIR || exit 1
+rsync --recursive --delete --force --exclude 'oojs-ui.css' --exclude 'oojs-ui*.rtl.css' ./dist/ "$TARGET_REPO/$TARGET_DIR" || exit 1
 
 # Read the new version
 NEWVERSION=$(oojsuiversion)
 
 # Generate commit
-cd $TARGET_REPO
+cd "$TARGET_REPO"
 COMMITMSG=$(cat <<END
 Update OOjs UI to $NEWVERSION
 
index 2c50002..21e847b 100755 (executable)
@@ -7,12 +7,12 @@ then
        exit 1
 fi
 
-REPO_DIR=$(cd $(dirname $0)/../..; pwd) # Root dir of the git repo working tree
-TARGET_DIR=resources/lib/oojs # Destination relative to the root of the repo
-NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs'` # e.g. /tmp/update-oojs.rI0I5Vir
+REPO_DIR=$(cd "$(dirname $0)/../.."; pwd) # Root dir of the git repo working tree
+TARGET_DIR="resources/lib/oojs" # Destination relative to the root of the repo
+NPM_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs') # e.g. /tmp/update-oojs.rI0I5Vir
 
 # Prepare working tree
-cd $REPO_DIR &&
+cd "$REPO_DIR" &&
 git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
 git checkout -B upstream-oojs origin/master || exit 1
 
@@ -20,7 +20,7 @@ git checkout -B upstream-oojs origin/master || exit 1
 cd $NPM_DIR
 if [ -n "$1" ]
 then
-       npm install oojs@$1 || exit 1
+       npm install "oojs@$1" || exit 1
 else
        npm install oojs || exit 1
 fi
@@ -33,10 +33,10 @@ then
 fi
 
 # Copy file(s)
-rsync --recursive --delete --force ./node_modules/oojs/dist $REPO_DIR/$TARGET_DIR || exit 1
+rsync --recursive --delete --force ./node_modules/oojs/dist "$REPO_DIR/$TARGET_DIR" || exit 1
 
 # Clean up temporary area
-rm -rf $NPM_DIR
+rm -rf "$NPM_DIR"
 
 # Generate commit
 cd $REPO_DIR || exit 1