#!/bin/bash
[% c("var/set_default_env") -%]
distdir=/var/tmp/dist/[% project %]
mkdir -p $distdir
cd $distdir

tar -xkf $rootdir/[% c('input_files_by_name/tor') %]

cd tor
mkdir pluggable_transports && cd pluggable_transports

tar -xkf $rootdir/[% c('input_files_by_name/obfs4') %]
tar -xkf $rootdir/[% c('input_files_by_name/snowflake') %]
tar -xkf $rootdir/[% c('input_files_by_name/webtunnel') %]
tar -xkf $rootdir/[% c('input_files_by_name/conjure') %]

# copy in bridge lines for each pluggable transport
mv $rootdir/bridges_list.obfs4.txt .
mv $rootdir/bridges_list.meek-azure.txt .
mv $rootdir/bridges_list.snowflake.txt .

# add per-platform pt extension
awk '{gsub(/\$\{pt_extension\}/, "[% c("var/pt_extension") %]"); print}' $rootdir/pt_config.json > pt_config.json

cd $distdir
[%
  SET tar_src = [ "tor", "data" ];
  IF c("var/linux");
   tar_src.push("debug");
  END;
  c('tar', {
    tar_src => tar_src,
    tar_args => '-czvf' _ dest_dir _ '/' _ c('filename'),
  });
%]
