#!/bin/bash
[% c("var/set_default_env") -%]
# This script runs outside containers
distdir=/var/tmp/$(whoami)/dist/fonts
mkdir -p $distdir

mv noto-fonts-* noto-fonts

[% FOREACH family = c("var/noto_fonts_common");
    GET 'cp noto-fonts/' _ family _ '/*.ttf $distdir/' _ "\n";
  END; %]

[% IF c("var/linux");
     SET font_list = c("var/noto_fonts_linux");
  ELSIF c("var/macos");
    SET font_list = c("var/noto_fonts_mac");
  ELSIF c("var/windows");
    SET font_list = c("var/noto_fonts_windows");
  END;
  FOREACH family = font_list;
    GET 'cp noto-fonts/' _ family _ '/* $distdir/' _ "\n";
  END;
%]

[% IF c("var/have_stix") %]
  cp "$rootdir/[% c('input_files_by_name/stix') %]" $distdir/
[% END %]

[% IF c("var/linux") %]
  unzip "$rootdir/[% c('input_files_by_name/arimo') %]"
  cp Arimo-*/fonts/ttf/*.ttf Cousine-* Tinos-* NotoSans{JP,KR,SC,TC}-Regular.otf $distdir/
[% END %]

cp "$rootdir/[% c('input_files_by_name/Pyidaungsu') %]" $distdir/

cp README.txt "$distdir/000_README.txt"
cd $distdir/..
[% c('tar', {
        tar_src => [ 'fonts' ],
        tar_args => '-caf ' _ dest_dir _ '/' _ c('filename'),
    }) %]

# Additional cleanup since we are outside containers
rm -rf /var/tmp/$(whoami)
