summaryrefslogtreecommitdiff
path: root/build.sh
blob: 8663a44e8f235e890fed9671441d178b7deed002 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
BASE="$PWD"
SRC="$BASE/src"
BUILD="$BASE/build"
MANIFEST_IN="$SRC/manifest.json"
MANIFEST_OUT="$BUILD/manifest.json"

VER=$(grep '"version":' "$MANIFEST_IN" | sed -re 's/.*": "(.*?)".*/\1/')
if [ "$1" == "tag" ]; then
  echo "Tagging at $VER"
  git tag -a "$VER" && git push origin "$VER"
  exit 0
fi
if [ "$1" == "rel" ]; then
  perl -pi -e 's/("version":.*)rc\d+/$1/' "$MANIFEST_IN" && rm "$MANIFEST_IN".bak
  "$0" && "$0" bump
  exit
fi
if [ "$1" == "bump" ]; then
  if [ "$2" ]; then
    NEW_VER="$2"
    if [[ "$2" == *.* ]]; then # full dotted version number
      pattern='"\d+.*?'
      NEW_VER='"'"$2"
    elif [[ "$2" == *rc* ]]; then # new RC after release
      if [[ "$2" == rc* ]]; then
        echo >&2 "Please specify next release version (like 12rc1). Current is $VER"
        exit 1
      fi
      pattern='\b(?:\d+rc)?\d+'
    else # incremental version
      pattern='\b\d+'
    fi
    REPLACE_EXPR='s/(?<PREAMBLE>"version":.*)'"$pattern"'"/$+{PREAMBLE}'"$NEW_VER"'"/'
    perl -pi -e $REPLACE_EXPR "$MANIFEST_IN" && rm "$MANIFEST_IN".bak && "$0" bump
    exit
  fi
  echo "Bumping to $VER"
  git add "$MANIFEST_IN"
  git commit -m "Version bump: $VER."
  [[ $VER == *rc* ]] || "$0" tag 
  exit
fi
XPI_DIR="$BASE/xpi"
XPI="$XPI_DIR/noscript-$VER"
LIB="$SRC/lib"
TLD="$BASE/TLD"

if ! [ $(date -r "$LIB/tld.js"  +'%Y%m%d') -ge $(date +'%Y%m%d') ] && "$TLD/generate.sh" "$LIB/tld.js"; then
  cp -u "$TLD/tld.js" "$LIB"
fi

./html5_events/html5_events.pl

rm -rf "$BUILD" "$XPI"
cp -pR "$SRC" "$BUILD"
cp -p LICENSE.txt GPL.txt "$BUILD"/

BUILD_CMD="web-ext"
BUILD_OPTS="build"
  
if [[ $VER == *rc* ]]; then
  sed -re 's/^(\s+)"strict_min_version":.*$/\1"update_url": "https:\/\/secure.informaction.com\/update\/?v='$VER'",\n\0/' \
    "$MANIFEST_IN" > "$MANIFEST_OUT"
  if [ "$1" == "sign" ]; then
    BUILD_CMD="$BASE/../../we-sign"
    BUILD_OPTS=""
  fi
else
  grep -v '"update_url":' "$MANIFEST_IN" > "$MANIFEST_OUT"
  if [ "$1" == "sign" ]; then
    echo >&2 "WARNING: won't auto-sign a release version, please manually upload to AMO."
  fi
fi
if ! grep '"id":' "$MANIFEST_OUT" >/dev/null; then
  echo >&2 "Cannot build manifest.json"
  exit 1
fi

for file in "$SRC"/content/*.js; do
  if grep -P '\/\/\s(REL|DEV)_ONLY' "$file" >/dev/null; then
    sed -re 's/\s*\/\/\s*(\S.*)\s*\/\/\s*REL_ONLY.*/\1/' -e 's/.*\/\/\s*DEV_ONLY.*//' "$file" > "$BUILD/content/$(basename "$file")"
  fi
done

echo "Creating $XPI.xpi..."
mkdir -p "$XPI_DIR"

"$BUILD_CMD" $BUILD_OPTS --source-dir=$(cygpath -w "$BUILD") --artifacts-dir=$(cygpath -w "$XPI_DIR") --ignore-files=test/XSS_test.js
SIGNED="$XPI_DIR/noscript_security_suite-$VER-an+fx.xpi"
if [ -f "$SIGNED" ]; then
  mv "$SIGNED" "$XPI.xpi"
elif [ -f "$XPI.zip" ]; then
  mv "$XPI.zip" "$XPI.xpi"
else
  echo >&2 "ERROR: Could not create $XPI.xpi!"
  exit 3
fi
echo "Created $XPI.xpi"
rm -rf "$BUILD"