2020-06-01 15:02:43 +00:00
|
|
|
#!/bin/bash
|
2020-06-01 15:05:42 +00:00
|
|
|
export EVENT=DiVOC
|
2020-06-01 15:02:43 +00:00
|
|
|
|
|
|
|
TMP=/tmp/$RANDOM
|
2020-06-02 17:42:09 +00:00
|
|
|
BT="Intergalactic Registration Office - v0.1"
|
2020-06-01 15:02:43 +00:00
|
|
|
|
|
|
|
function diaBox() {
|
|
|
|
h=8
|
|
|
|
w=60
|
|
|
|
if [ -n "$3" ]; then
|
|
|
|
h=$3
|
|
|
|
fi
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
w=$4
|
|
|
|
fi
|
|
|
|
dialog --title "$1" \
|
|
|
|
--backtitle "$BT" \
|
|
|
|
--msgbox "$2" $h $w
|
|
|
|
}
|
|
|
|
|
|
|
|
function ynBox() {
|
|
|
|
h=8
|
|
|
|
w=60
|
|
|
|
if [ -n "$3" ]; then
|
|
|
|
h=$3
|
|
|
|
fi
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
w=$4
|
|
|
|
fi
|
|
|
|
|
|
|
|
dialog --title "$1" \
|
|
|
|
--backtitle "$BT" \
|
|
|
|
--yesno "$2" $h $w
|
|
|
|
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function askStr() {
|
|
|
|
h=12
|
|
|
|
w=60
|
|
|
|
if [ -n "$5" ]; then
|
|
|
|
h=$5
|
|
|
|
fi
|
|
|
|
if [ -n "$6" ]; then
|
|
|
|
w=$6
|
|
|
|
fi
|
|
|
|
|
|
|
|
dialog --title "$2" \
|
|
|
|
--backtitle "$BT" \
|
|
|
|
--max-input $1 \
|
|
|
|
--inputbox "$3" $h $w "$4" 2> $TMP
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirm() {
|
|
|
|
h=12
|
|
|
|
w=60
|
|
|
|
if [ -n "$3" ]; then
|
|
|
|
h=$3
|
|
|
|
fi
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
w=$4
|
|
|
|
fi
|
|
|
|
|
|
|
|
dialog --title "Confirm: $1" \
|
|
|
|
--backtitle "$BT" \
|
|
|
|
--yesno "Please confirm those information:\n$2" $h $w
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
function jhpAskForField() {
|
2020-06-01 16:04:30 +00:00
|
|
|
text="$1: Please choose a free field on the passport.\n
|
2020-06-01 15:02:43 +00:00
|
|
|
------------------\n
|
|
|
|
| Archievements |\n
|
|
|
|
==================\n
|
|
|
|
| 0 | 1 || 6 | 7 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 2 | 3 || 8 | 9 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 4 | 5 || 10| 11|\n
|
|
|
|
==================\n
|
|
|
|
"
|
|
|
|
askStr 2 "Select a field" "$text" "" 18
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
FIELD=$(cat $TMP)
|
|
|
|
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt 11 ]; then
|
|
|
|
jhpAskForField
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function jhpPrintGPG() {
|
2020-06-01 16:04:30 +00:00
|
|
|
jhpAskForField "GPG fingerprint"
|
2020-06-01 15:02:43 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
diaBox "Insert Passport" "Please insert passport (Archivements) into the printer."
|
|
|
|
cd jhp
|
|
|
|
./gpgkey $FIELD $FP
|
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function jhpPrintReg() {
|
|
|
|
diaBox "Insert Passport" "Please insert passport (First page, name, planet, date) into the printer."
|
|
|
|
cd jhp
|
2020-06-11 15:54:10 +00:00
|
|
|
./reg "$FNAME" "$SNAME" "$PLANET"
|
2020-06-01 15:02:43 +00:00
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-06-02 17:42:09 +00:00
|
|
|
function jhpIROStamp() {
|
|
|
|
jhpAskForField "IRO stamp"
|
2020-06-01 15:02:43 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
diaBox "Insert Passport" "Please insert passport (Archivements) into the printer."
|
|
|
|
cd jhp
|
2020-06-03 17:23:36 +00:00
|
|
|
./iro $FIELD
|
2020-06-01 15:02:43 +00:00
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function jhpGPG() {
|
|
|
|
askStr 49 "GPG Fingerprint" "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
FP=$(cat $TMP)
|
|
|
|
rm $TMP
|
|
|
|
if ! [[ $FP =~ ^([[:xdigit:]]{4} ){9}[[:xdigit:]]{4}$ ]]; then
|
|
|
|
diaBox "GPG Fingerprint" "This does not match the RegEx of a GPG fingerprint.\nPlease type in the whole fingerprint."
|
|
|
|
jhpGPG
|
|
|
|
fi
|
|
|
|
FP=$(echo "$FP" | tr [a-f] [A-F])
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ "$1" == "no-confirm" ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
confirm "GPG Fingerprint" " GPG:\n $FP"
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function jhpReg() {
|
|
|
|
askStr 25 "Forename/Nickname" "Enter forename/nickname"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
FNAME=$(cat $TMP)
|
|
|
|
|
|
|
|
askStr 25 "Surename" "Enter surename"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
SNAME=$(cat $TMP)
|
|
|
|
|
|
|
|
askStr 25 "Planet" "Enter planet" "Earth, Chaospott"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
PLANET=$(cat $TMP)
|
|
|
|
|
|
|
|
confirm=" Forename: $FNAME\n Surename: $SNAME\n Planet: $PLANET"
|
|
|
|
|
2020-06-11 10:13:23 +00:00
|
|
|
ynBox "IRO Stamp" "Does this being want to have a IRO stamp?"
|
2020-06-01 16:04:30 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
STAMP=true
|
|
|
|
else
|
|
|
|
STAMP=false
|
|
|
|
fi
|
2020-06-01 15:02:43 +00:00
|
|
|
|
|
|
|
ynBox "GPG" "Does the being have a GPG key to register?"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
jhpGPG no-confirm
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
confirm="$confirm\n GPG:\n $FP"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
confirm "Everything" "$confirm"
|
|
|
|
return $?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function jhpmenu() {
|
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--menu "Select ID type:" 14 40 3 \
|
|
|
|
1 "Registration" \
|
2020-06-02 17:42:09 +00:00
|
|
|
2 "IRO Stamp" \
|
2020-06-01 16:04:30 +00:00
|
|
|
3 "GPG" \
|
2020-06-01 15:02:43 +00:00
|
|
|
9 "Back" 2> $TMP
|
|
|
|
|
|
|
|
choice=$(cat $TMP)
|
|
|
|
|
|
|
|
case $choice in
|
|
|
|
1) jhpReg
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
jhpPrintReg
|
2020-06-01 16:04:30 +00:00
|
|
|
if [ "$STAMP" == "true" ]; then
|
2020-06-02 17:42:09 +00:00
|
|
|
jhpIROStamp
|
2020-06-01 16:04:30 +00:00
|
|
|
fi
|
2020-06-01 15:02:43 +00:00
|
|
|
if [ -n "$FP" ]; then
|
|
|
|
jhpPrintGPG
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2020-06-02 17:42:09 +00:00
|
|
|
2) jhpIROStamp
|
2020-06-01 16:04:30 +00:00
|
|
|
;;
|
|
|
|
3) jhpGPG
|
2020-06-01 15:02:43 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
jhpPrintGPG
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
unset FNAME
|
|
|
|
unset SNAME
|
|
|
|
unset PLANET
|
|
|
|
unset FP
|
|
|
|
unset FIELD
|
|
|
|
}
|
|
|
|
|
2020-06-11 15:54:10 +00:00
|
|
|
|
|
|
|
function adaAskForField() {
|
|
|
|
text="$1: Please choose a free field on the passport.\n
|
|
|
|
------------------\n
|
|
|
|
| VISAS || VISAS |\n
|
|
|
|
==================\n
|
|
|
|
| 0 | 1 || 4 | 5 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 2 | 3 || 6 | 7 |\n
|
|
|
|
==================\n
|
|
|
|
"
|
|
|
|
askStr 2 "Select a field" "$text" "" 18
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
FIELD=$(cat $TMP)
|
|
|
|
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt 7 ]; then
|
|
|
|
adaAskForField
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function adaPrintGPG() {
|
|
|
|
adaAskForField "GPG fingerprint"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
|
|
|
cd adafruit
|
|
|
|
./gpgkey $FIELD $FP
|
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function adaPrintReg() {
|
|
|
|
diaBox "Insert Passport" "Please insert passport (First page, name, place) into the printer."
|
|
|
|
cd adafruit
|
|
|
|
./reg "$FNAME" "$SNAME" "$PLANET"
|
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function adaIROStamp() {
|
|
|
|
adaAskForField "IRO stamp"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
|
|
|
cd adafruit
|
|
|
|
./iro $FIELD
|
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function adaGPG() {
|
|
|
|
askStr 49 "GPG Fingerprint" "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
FP=$(cat $TMP)
|
|
|
|
rm $TMP
|
|
|
|
if ! [[ $FP =~ ^([[:xdigit:]]{4} ){9}[[:xdigit:]]{4}$ ]]; then
|
|
|
|
diaBox "GPG Fingerprint" "This does not match the RegEx of a GPG fingerprint.\nPlease type in the whole fingerprint."
|
|
|
|
adaGPG
|
|
|
|
fi
|
|
|
|
FP=$(echo "$FP" | tr [a-f] [A-F])
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ "$1" == "no-confirm" ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
confirm "GPG Fingerprint" " GPG:\n $FP"
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function adaReg() {
|
|
|
|
askStr 25 "Forename/Nickname" "Enter forename/nickname"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
FNAME=$(cat $TMP)
|
|
|
|
|
|
|
|
askStr 25 "Surename" "Enter surename"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
SNAME=$(cat $TMP)
|
|
|
|
|
|
|
|
askStr 25 "Place" "Enter place" "Earth, Chaospott"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
PLANET=$(cat $TMP)
|
|
|
|
|
|
|
|
confirm=" Forename: $FNAME\n Surename: $SNAME\n Place: $PLANET"
|
|
|
|
|
|
|
|
ynBox "IRO Stamp" "Does this being want to have a IRO stamp?"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
STAMP=true
|
|
|
|
else
|
|
|
|
STAMP=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
ynBox "GPG" "Does the being have a GPG key to register?"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
adaGPG no-confirm
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
confirm="$confirm\n GPG:\n $FP"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
confirm "Everything" "$confirm"
|
|
|
|
return $?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function adamenu() {
|
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--menu "Select ID type:" 14 40 3 \
|
|
|
|
1 "Registration" \
|
|
|
|
2 "IRO Stamp" \
|
|
|
|
3 "GPG" \
|
|
|
|
9 "Back" 2> $TMP
|
|
|
|
|
|
|
|
choice=$(cat $TMP)
|
|
|
|
|
|
|
|
case $choice in
|
|
|
|
1) adaReg
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
adaPrintReg
|
|
|
|
if [ "$STAMP" == "true" ]; then
|
|
|
|
adaIROStamp
|
|
|
|
fi
|
|
|
|
if [ -n "$FP" ]; then
|
|
|
|
adaPrintGPG
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
2) adaIROStamp
|
|
|
|
;;
|
|
|
|
3) adaGPG
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
adaPrintGPG
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
unset FNAME
|
|
|
|
unset SNAME
|
|
|
|
unset PLANET
|
|
|
|
unset FP
|
|
|
|
unset FIELD
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-06-01 15:02:43 +00:00
|
|
|
while [ true ]; do
|
|
|
|
|
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--menu "Select ID type:" 10 40 3 \
|
|
|
|
1 "Junghackerpass" \
|
2020-06-11 15:54:10 +00:00
|
|
|
2 "New Adafruit passport" \
|
|
|
|
9 "Usual" 2> $TMP
|
2020-06-01 15:02:43 +00:00
|
|
|
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 9 ]; then
|
2020-06-01 15:02:43 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
TYPE=$(cat $TMP)
|
|
|
|
|
|
|
|
|
|
|
|
case $TYPE in
|
|
|
|
1) jhpmenu
|
|
|
|
;;
|
2020-06-11 15:54:10 +00:00
|
|
|
2) adamenu
|
|
|
|
;;
|
|
|
|
9) exit 0
|
2020-06-01 15:02:43 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
rm $TMP
|
|
|
|
clear
|