Merge "Chinese Conversion Table Update 2016-1"
[lhc/web/wiklou.git] / maintenance / resources / update-oojs.sh
index d9e6fb9..b91cb28 100755 (executable)
@@ -1,6 +1,8 @@
-#!/usr/bin/env bash
+#!/bin/bash -eu
 
-if [ -n "$2" ]
+# This script generates a commit that updates our copy of OOjs
+
+if [ -n "${2:-}" ]
 then
        # Too many parameters
        echo >&2 "Usage: $0 [<version>]"
@@ -12,20 +14,22 @@ 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" &&
-git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
-git checkout -B upstream-oojs origin/master || exit 1
+cd "$REPO_DIR"
+git reset -- $TARGET_DIR
+git checkout -- $TARGET_DIR
+git fetch origin
+git checkout -B upstream-oojs origin/master
 
 # Fetch upstream version
 cd $NPM_DIR
-if [ -n "$1" ]
+if [ -n "${1:-}" ]
 then
-       npm install "oojs@$1" || exit 1
+       npm install "oojs@$1"
 else
-       npm install oojs || exit 1
+       npm install oojs
 fi
 
-OOJS_VERSION=$(node -e 'console.log(JSON.parse(require("fs").readFileSync("./node_modules/oojs/package.json")).version);')
+OOJS_VERSION=$(node -e 'console.log(require("./node_modules/oojs/package.json").version);')
 if [ "$OOJS_VERSION" == "" ]
 then
        echo 'Could not find OOjs version'
@@ -33,13 +37,13 @@ then
 fi
 
 # Copy file(s)
-rsync --force ./node_modules/oojs/dist/oojs.jquery.js "$REPO_DIR/$TARGET_DIR" || exit 1
+rsync --force ./node_modules/oojs/dist/oojs.jquery.js "$REPO_DIR/$TARGET_DIR"
 
 # Clean up temporary area
 rm -rf "$NPM_DIR"
 
 # Generate commit
-cd $REPO_DIR || exit 1
+cd $REPO_DIR
 
 COMMITMSG=$(cat <<END
 Update OOjs to v$OOJS_VERSION
@@ -50,4 +54,6 @@ END
 )
 
 # Stage deletion, modification and creation of files. Then commit.
-git add --update $TARGET_DIR && git add $TARGET_DIR && git commit -m "$COMMITMSG" || exit 1
+git add --update $TARGET_DIR
+git add $TARGET_DIR
+git commit -m "$COMMITMSG"