summaryrefslogtreecommitdiff
path: root/scripts/pull_metadata.sh
blob: 0d6d0e1f48d5389bd525626acb335e9c4eb32266 (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
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
L10N_DIR="$(cd "$PROJECT_ROOT/../l10n" && pwd || echo Oops...)"
echo $L10N_DIR
if [ ! -d "$L10N_DIR" ]; then
  echo "L10N_DIR not found: you need to checkout https://0xacab.org/leap/l10n/ next to the bitmask_android repository.";
  exit 1
fi

MODE="${1:-normal}" # normal|custom
case "$MODE" in
  normal|custom) ;;
  *) echo "Usage: $0 [normal|custom]"; exit 1 ;;
esac

command -v jq >/dev/null 2>&1 || { echo "Missing jq"; exit 1; }

# ensure the right l10n branch is checked out
cd $L10N_DIR
if [ ${MODE} == "normal" ]; then
  git checkout bitmask-playstore
  git pull
  SRC_GLOB="$L10N_DIR/bitmask-playstore-metadata/*.json"
else
  git checkout bitmask.riseupvpn-playstore-metadata
  git pull
  SRC_GLOB="$L10N_DIR/bitmask.riseupvpn-playstore-metadata/*.json"
fi
cd -

OUT_BASE="$PROJECT_ROOT/src/${MODE}ProductionFat/fastlane/metadata/android"

# iterate through translations and parse them to fastlane files
for json in $SRC_GLOB; do
  [ -e "$json" ] || break
  lang="$(basename "$json" .json)"
  echo "updating meta data for language $lang"

  if [ ${lang} == "en" ]; then
    echo "moving default english localizations (en) to $OUT_BASE/en-US"
    lang="en-US"
  fi

  out_dir="$OUT_BASE/$lang"
  mkdir -p "$out_dir"

  jq -r '.full_description'  "$json" > "$out_dir/full_description.txt"
  jq -r '.short_description' "$json" > "$out_dir/short_description.txt"
  jq -r '.title'             "$json" > "$out_dir/title.txt"
done