-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_assertion.sh
executable file
·53 lines (44 loc) · 1.35 KB
/
generate_assertion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "You need two arguments: file path, and assertion type (entrep, soft, tech)"
exit 1
elif [[ $2 -ne "entrep" && $2 -ne "soft" && $2 -ne "tech" ]]; then
echo "Second argument must be one of these (entrep, soft, tech)"
exit 1
fi
today=$(date +"%Y-%m-%d")
echo $2
email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
badge_file="https://badges.lilisfaxi.now.sh/json/entrep-badge.json"
if [[ "$2" = "soft" ]]; then
badge_file="https://badges.lilisfaxi.now.sh/json/soft-badge.json"
elif [[ "$2" = "tech" ]]; then
badge_file="https://badges.lilisfaxi.now.sh/json/tech-badge.json"
fi
echo $badge_file
mkdir json/generated/$today
while read line
do
name=$line
login="$(cut -d'@' -f1 <<<$name)"
id_assertion=$login"-"$2"-"$today
file="json/generated/"$today"/"$id_assertion".json"
if [[ $name =~ $email_regex ]] ; then
echo "{\"uid\": \""$id_assertion"\",
\"recipient\": {
\"type\": \"email\",
\"identity\": \""$name"\",
\"hashed\": false
},
\"issuedOn\": \""$today"\",
\"badge\": \""$badge_file"\",
\"verify\": {
\"type\": \"hosted\",
\"url\": \"https://badges.lilisfaxi.now.sh/json/generated/"$today"/"$id_assertion".json\"
}
}" > $file
echo "OK"
else
echo $name": this is not a valid email!"
fi
done < $1;