<commit_before>#!/bin/bash

set -e

# Prevent cordova prompting us to opt-in to telemetry on first use
cordova telemetry off >/dev/null 2>&1

WEBFILES_REPO="https://github.com/greenaddress/GreenAddressWebFiles.git"
WEBFILES_BRANCH=$(git symbolic-ref HEAD || echo $TRAVIS_BRANCH)
WEBFILES_BRANCH=${WEBFILES_BRANCH##refs/heads/}

TESTNET_CHAINCODE=<KEY>
TESTNET_PUBKEY=<KEY>

function build_env {
    SED=sed
    if [ "$(uname)" == "Darwin" ]; then
        SED=gsed
    fi
    $SED -e "s/TEMPLATE_COIN/$1/g" network_template.js > www/greenaddress.it/static/wallet/network.js
    $SED -e "s/TEMPLATE_CHAINCODE/$2/g" -e "s/TEMPLATE_PUBKEY/$3/g" -e "s|TEMPLATE_WS|$4|g" \
         -e "s|TEMPLATE_ROOT|$5|g" config_template.js > www/greenaddress.it/static/wallet/config.js
}

function rename_env {
    declare -a filenames=(".cordova/config.json"
                          "plugins-src/cordova-plugin-greenaddress/BTChip.java"
                          "plugins-src/cordova-plugin-greenaddress/GreenAddressIt.java"
                          "plugins-src/cordova-plugin-greenaddress/PINInput.java"
                          "plugins-src/cordova-plugin-greenaddress/PINInputActivity.java"
                          "plugins-src/cordova-plugin-greenaddress/SettingsActivity.java"
                          "plugins-src/cordova-plugin-greenaddress/WalletBalanceWidgetProvider.java"
                          "plugins-src/cordova-plugin-greenaddress/WalletClient.java"
                          "plugins-src/cordova-plugin-greenaddress/plugin.xml")
    for name in "${filenames[@]}"
    do
      $SED -i -e "s/it\.greenaddress\.cordova/it\.greenaddress\.cordova_$1/g" "$name"
    done

    $SED -i -e "s/<widget id=\"it.greenaddress.cordova\"/<widget id=\"it.greenaddress.cordova_$1\"/" \
         -e "s/<name>GreenAddress/<name>GreenAddress_$2/" \
        www/config.xml
}

while [ $# -gt 0 ]; do
key="$1"

case $key in
    -h|--help)
    HELP=1
    ;;
    -r|--webfiles-repo)
    WEBFILES_REPO="$2"
    shift # past argument
    ;;
    # There used to be a typo so support both spellings
    -b|--webfile-branch|--webfiles-branch)
    WEBFILES_BRANCH="$2"
    shift # past argument
    ;;
    --testnet)
    build_env testnet ${TESTNET_CHAINCODE} ${TESTNET_PUBKEY} wss://testwss.greenaddress.it https://test.greenaddress.it
    rename_env testnet TestNet
    ;;
    --regtest)
    build_env testnet ${TESTNET_CHAINCODE} ${TESTNET_PUBKEY} ws://"$2":8080 http://"$2":9908
    rename_env regtest RegTest
    shift
    ;;
    *)
    # unknown option
    ;;
esac
shift # past argument or value
done

if [ "$HELP" == "1" ];
then
    cat <<EOF
Usage: ./prepare.sh [-h] [--webfiles-repo WEBFILES_REPO]
                         [--webfiles-branch WEBFILES_BRANCH]

Prepares the Cordova app. Requires npm and Python 2.x with virtualenv.

optional arguments:
  -h, --help                       show this help message and exit
  --webfiles-repo WEBFILES_REPO, -r WEBFILES_REPO
                                   Optional non-default git URL to clone web
                                   files from. (Default: $WEBFILES_REPO)
  --webfiles-branch WEBFILES_BRANCH, -b WEBFILES_BRANCH
                                   Optional non-default git URL to clone web
                                   files from. (Default: $WEBFILES_BRANCH)
EOF
    exit 1
fi

if [ \! -e webfiles ]; then
    git clone --depth 1 https://github.com/glslang/GreenAddressWebFiles.git -b electron_rebased webfiles # FIXME: Undo
    rm webfiles/package-lock.json
    #git clone --depth 1 $WEBFILES_REPO -b $WEBFILES_BRANCH webfiles
fi
<commit_msg>update for latest webfiles changes<commit_after>#!/bin/bash

set -e

# Prevent cordova prompting us to opt-in to telemetry on first use
cordova telemetry off >/dev/null 2>&1

WEBFILES_REPO="https://github.com/greenaddress/GreenAddressWebFiles.git"
WEBFILES_BRANCH=$(git symbolic-ref HEAD || echo $TRAVIS_BRANCH)
WEBFILES_BRANCH=${WEBFILES_BRANCH##refs/heads/}

TESTNET_CHAINCODE=b60befcc619bb1c212732770fe181f2f1aa824ab89f8aab49f2e13e3a56f0f04
TESTNET_PUBKEY=<KEY>

function build_env {
    SED=sed
    if [ "$(uname)" == "Darwin" ]; then
        SED=gsed
    fi
    $SED -e "s/TEMPLATE_COIN/$1/g" network_template.js > www/greenaddress.it/static/wallet/network.js
    $SED -e "s/TEMPLATE_CHAINCODE/$2/g" -e "s/TEMPLATE_PUBKEY/$3/g" -e "s|TEMPLATE_WS|$4|g" \
         -e "s|TEMPLATE_ROOT|$5|g" config_template.js > www/greenaddress.it/static/wallet/config.js
}

function rename_env {
    declare -a filenames=(".cordova/config.json"
                          "plugins-src/cordova-plugin-greenaddress/BTChip.java"
                          "plugins-src/cordova-plugin-greenaddress/GreenAddressIt.java"
                          "plugins-src/cordova-plugin-greenaddress/PINInput.java"
                          "plugins-src/cordova-plugin-greenaddress/PINInputActivity.java"
                          "plugins-src/cordova-plugin-greenaddress/SettingsActivity.java"
                          "plugins-src/cordova-plugin-greenaddress/WalletBalanceWidgetProvider.java"
                          "plugins-src/cordova-plugin-greenaddress/WalletClient.java"
                          "plugins-src/cordova-plugin-greenaddress/plugin.xml")
    for name in "${filenames[@]}"
    do
      $SED -i -e "s/it\.greenaddress\.cordova/it\.greenaddress\.cordova_$1/g" "$name"
    done

    $SED -i -e "s/<widget id=\"it.greenaddress.cordova\"/<widget id=\"it.greenaddress.cordova_$1\"/" \
         -e "s/<name>GreenAddress/<name>GreenAddress_$2/" \
        www/config.xml
}

while [ $# -gt 0 ]; do
key="$1"

case $key in
    -h|--help)
    HELP=1
    ;;
    -r|--webfiles-repo)
    WEBFILES_REPO="$2"
    shift # past argument
    ;;
    # There used to be a typo so support both spellings
    -b|--webfile-branch|--webfiles-branch)
    WEBFILES_BRANCH="$2"
    shift # past argument
    ;;
    --testnet)
    build_env testnet ${TESTNET_CHAINCODE} ${TESTNET_PUBKEY} wss://testwss.greenaddress.it https://test.greenaddress.it
    rename_env testnet TestNet
    ;;
    --regtest)
    build_env testnet ${TESTNET_CHAINCODE} ${TESTNET_PUBKEY} ws://"$2":8080 http://"$2":9908
    rename_env regtest RegTest
    shift
    ;;
    *)
    # unknown option
    ;;
esac
shift # past argument or value
done

if [ "$HELP" == "1" ];
then
    cat <<EOF
Usage: ./prepare.sh [-h] [--webfiles-repo WEBFILES_REPO]
                         [--webfiles-branch WEBFILES_BRANCH]

Prepares the Cordova app. Requires npm and Python 2.x with virtualenv.

optional arguments:
  -h, --help                       show this help message and exit
  --webfiles-repo WEBFILES_REPO, -r WEBFILES_REPO
                                   Optional non-default git URL to clone web
                                   files from. (Default: $WEBFILES_REPO)
  --webfiles-branch WEBFILES_BRANCH, -b WEBFILES_BRANCH
                                   Optional non-default git URL to clone web
                                   files from. (Default: $WEBFILES_BRANCH)
EOF
    exit 1
fi

if [ \! -e webfiles ]; then
    git clone --depth 1 https://github.com/glslang/GreenAddressWebFiles.git -b electron_rebased webfiles # FIXME: Undo
    $SED -i -e "/wallyjs/d" -e "/cordova-plugin-wally/d" webfiles/package.json
    rm -rf webfiles/package-lock.json
    #git clone --depth 1 $WEBFILES_REPO -b $WEBFILES_BRANCH webfiles
fi

{'fraction_non_alphanumeric': 0.1237939937491507, 'fraction_numerical': 0.013181138741676859, 'mean_word_length': 2.3288104929895974, 'pattern_counts': {'":': 4, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1003670', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2565, 'n_words': 490}