f7e2cb
#!/bin/bash
f7e2cb
#set -x
f7e2cb
set -e
f7e2cb
usage()
f7e2cb
{
f7e2cb
cat << EOF
f7e2cb
usage: $0 options
f7e2cb
f7e2cb
This script downloads calendar langpacks for Thunderbird.
f7e2cb
f7e2cb
OPTIONS:
f7e2cb
   -h      Show this message
f7e2cb
   -v      Version string (7.0.1)
f7e2cb
   -b      Build number (1, 2, 3)
f7e2cb
   -r      Reuse downloaded files (when you don't want to redownload)
f7e2cb
EOF
f7e2cb
}
f7e2cb
f7e2cb
VER=
f7e2cb
BUILDNUM=
f7e2cb
LANG_DATE=`date "+%Y%m%d"`
f7e2cb
while getopts “hv:b:r” OPTION
f7e2cb
do
f7e2cb
     case $OPTION in
f7e2cb
         h)
f7e2cb
             usage
f7e2cb
             exit 1
f7e2cb
             ;;
f7e2cb
         v)
f7e2cb
             VER=$OPTARG
f7e2cb
             ;;
f7e2cb
         b)
f7e2cb
             BUILDNUM=$OPTARG
f7e2cb
             ;;
f7e2cb
         ?)
f7e2cb
             usage
f7e2cb
             exit
f7e2cb
             ;;
f7e2cb
     esac
f7e2cb
done
f7e2cb
f7e2cb
if [ -z "$VER" -o -z "$BUILDNUM"  ]
f7e2cb
then
f7e2cb
     echo "Missing version or build number."
f7e2cb
     usage
f7e2cb
     exit 1
f7e2cb
fi
f7e2cb
f7e2cb
WHITE='\033[1;33m'
f7e2cb
NC='\033[0m' # No Color
f7e2cb
f7e2cb
LOCALES=`curl -f https://archive.mozilla.org/pub/thunderbird/candidates/$VER-candidates/build$BUILDNUM/linux-i686/ | grep "a href"|sed -e "s|.*/\([^/]*\)/\".*|\1|"|tail -n+2 |grep -v xpi`
f7e2cb
#echo $LOCALES
f7e2cb
rm -rf lightning-langpacks
f7e2cb
mkdir -p lightning-langpacks
f7e2cb
cd lightning-langpacks
f7e2cb
LOCALE_COUNT=`echo $LOCALES| tr ' ' '\n' | wc -l`
f7e2cb
LOCALE_NUM=0
f7e2cb
for lang in $LOCALES; do
f7e2cb
  LOCALE_NUM=$((LOCALE_NUM+1))
f7e2cb
  echo -e "${WHITE}Processing calendar locale: $lang ($LOCALE_NUM/$LOCALE_COUNT)${NC}"
f7e2cb
  mkdir -p extracted_lightning
f7e2cb
  mkdir -p calendar-locales
f7e2cb
  #echo Downloading TB binary for locale: $lang
f7e2cb
  wget --quiet https://archive.mozilla.org/pub/thunderbird/candidates/$VER-candidates/build$BUILDNUM/linux-i686/$lang/thunderbird-$VER.tar.bz2
f7e2cb
f7e2cb
  cd extracted_lightning
f7e2cb
  tar -xf ../thunderbird-$VER.tar.bz2 thunderbird/distribution/extensions/\{e2fda1a4-762b-4020-b5ad-a41df1933103\}.xpi
f7e2cb
  set +e
f7e2cb
  unzip -qq thunderbird/distribution/extensions/\{e2fda1a4-762b-4020-b5ad-a41df1933103\}.xpi
f7e2cb
  set -e
f7e2cb
  LIGHTNING_VERSION=`cat app.ini |grep "^Version="|sed -e 's/Version=//'`
f7e2cb
  BUILD_ID=`cat app.ini |grep "^BuildID="|sed -e 's/BuildID=//'`
f7e2cb
  MAX_VERSION=`cat app.ini |grep MaxVersion|sed -e s/MaxVersion=//`
f7e2cb
  MIN_VERSION=`cat app.ini |grep MinVersion|sed -e s/MinVersion=//`
f7e2cb
  rm -rf thunderbird
f7e2cb
  mkdir -p ../calendar-locales/chrome
f7e2cb
  cp -r chrome/calendar-$lang ../calendar-locales/chrome
f7e2cb
  cp -r chrome/lightning-$lang ../calendar-locales/chrome
f7e2cb
  cd -
f7e2cb
f7e2cb
  cd calendar-locales
f7e2cb
  # create manifest
f7e2cb
  cat > manifest.json <
f7e2cb
{
f7e2cb
  "languages": {
f7e2cb
    "$lang": {
f7e2cb
      "chrome_resources": {
f7e2cb
        "calendar": "chrome/calendar-$lang/locale/$lang/calendar/",
f7e2cb
        "lightning": "chrome/lightning-$lang/locale/$lang/lightning/"
f7e2cb
      },
f7e2cb
      "version": "$LIGHTNING_VERSION"
f7e2cb
    }
f7e2cb
  },
f7e2cb
  "applications": {
f7e2cb
    "gecko": {
f7e2cb
      "strict_min_version": "$MIN_VERSION",
f7e2cb
      "id": "langpack-cal-$lang@lightning.mozilla.org",
f7e2cb
      "strict_max_version": "$MAX_VERSION"
f7e2cb
    }
f7e2cb
  },
f7e2cb
  "langpack_id": "$lang",
f7e2cb
  "version": "7.$LIGHTNING_VERSION.$BUILD_ID",
f7e2cb
  "name": "$lang Language Pack Calendar",
f7e2cb
  "manifest_version": 2,
f7e2cb
  "sources": {
f7e2cb
    "browser": {
f7e2cb
      "base_path": "browser/"
f7e2cb
    }
f7e2cb
  },
f7e2cb
  "author": "Mozilla.cz (contributors: Pavel Cvrček, Pavel Franc, Michal Stanke, Michal Vašíček)",
f7e2cb
  "description": "Language pack for Thunderbird for $lang, this was repacked by Fedora/RHEL package maintainer from original binaries."
f7e2cb
}
f7e2cb
f7e2cb
EOL
f7e2cb
  zip --quiet -r ../langpack-cal-$lang@lightning.mozilla.org.xpi *
f7e2cb
  cd -
f7e2cb
  rm -rf calendar-locales
f7e2cb
  rm -rf extracted_lightning
f7e2cb
f7e2cb
  rm -f thunderbird-$VER.tar.bz2
f7e2cb
done
f7e2cb
echo "Creating lightning-langpacks-$VER.tar.xz..."
f7e2cb
tar cJf ../lightning-langpacks-$VER.tar.xz *.xpi
f7e2cb
cd ..
f7e2cb
rm -rf lightning-langpacks