#!/bin/bash

editions=(\
Y2016E0001 \
Y2016E0002 \
Y2017E0001 \
Y2017E0002 \
Y2017E0003 \
)

copyrights=(\
Y2016CR0001 \
Y2016CR0002 \
Y2016CR0003 \
Y2016CR0004 \
Y2016CR0005 \
)

function create_all_key() {
  e=$1
  cr=$2
  user=$3

  echo $1
  f="$e-$cr"
  ./bin/license_issuer -t key -c $cr -e $e -v 15 -n 1 -f keys/$f.txt
  ./bin/license_issuer -u $user \
              -a ACBVLYHFML \
              -p 深度操作系统桌面版软件V15（标准） \
              -n 100 \
              -b 1459468800 \
              -d 1661974400 \
              -t file \
              -c $cr \
              -e $e \
              -v 15 \
              -k ./license_rsa \
              -f keys/$f-100.key
}

function create_server_key() {
  e=$1
  cr=$2
  mc=$3
  user=$4

  echo $1
  f="$e-$cr-$mc"
  ./bin/license_issuer -u $user \
                   -a TESTCODE \
                   -p 深度操作系统桌面版软件V15（标准） \
                   -m $mc \
                   -b 1459468800 \
                   -d 1661974400 \
                   -t file \
                   -c $cr \
                   -e $e \
                   -v 15 \
                   -k ./license_rsa \
                   -f keys/$f.key
}

user=$1
mc=$2
# mc=b913-7153-4aa9-1c8e

for e in "${editions[@]}";
do
  for cr in "${copyrights[@]}";
  do
    create_all_key $e $cr $user
  done
done

for cr in "${copyrights[@]}";
do
  create_server_key Y2016E0002 $cr $mc $user
done
