#!/bin/bash
# usage: sign.sh [pem file]
[[ $# ==  1 ]] || { echo "USAGE: $0 [pem file]"; exit 1; }
[[ -f $1 ]] || { echo "Private key not found"; exit 1; }

pem=$1
ppk=${pem%.pem}.ppk

# copy pem and ppk to s3
aws s3 cp $pem s3://tidb-workshop-pcta-2023-ec2/
aws s3 cp $ppk s3://tidb-workshop-pcta-2023-ec2/

# sign pem and ppk
aws --profile workshop-sign s3 presign s3://tidb-workshop-pcta-2023-ec2/`basename $pem` --expires-in 600000 --region ap-northeast-1 --endpoint-url https://s3.ap-northeast-1.amazonaws.com >> pemsigned.txt
aws --profile workshop-sign s3 presign s3://tidb-workshop-pcta-2023-ec2/`basename $ppk` --expires-in 600000 --region ap-northeast-1 --endpoint-url https://s3.ap-northeast-1.amazonaws.com >> ppksigned.txt
