c3Reg/start

244 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
export EVENT=DiVOC
TMP=/tmp/$RANDOM
BT="Galactic Registration Office - v0.1"
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() {
text="Please choose a free field on the passport.\n
------------------\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() {
jhpAskForField
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
./JunghackerPass "$FNAME" "$SNAME" "$PLANET"
cd ..
return 0
}
function jhpGROStamp() {
jhpAskForField
if [ $? -eq 0 ]; then
diaBox "Insert Passport" "Please insert passport (Archivements) into the printer."
cd jhp
./gro $FIELD
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"
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" \
2 "GPG" \
3 "GRO Stamp" \
9 "Back" 2> $TMP
choice=$(cat $TMP)
case $choice in
1) jhpReg
if [ $? -eq 0 ]; then
jhpPrintReg
if [ -n "$FP" ]; then
jhpPrintGPG
fi
fi
;;
2) jhpGPG
if [ $? -eq 0 ]; then
jhpPrintGPG
fi
;;
3) jhpGROStamp
esac
unset FNAME
unset SNAME
unset PLANET
unset FP
unset FIELD
}
while [ true ]; do
dialog --backtitle "$BT" \
--menu "Select ID type:" 10 40 3 \
1 "Junghackerpass" \
2 "Usual" 2> $TMP
if [ $? -eq 1 ]; then
break
fi
TYPE=$(cat $TMP)
case $TYPE in
1) jhpmenu
;;
2) exit 0
;;
esac
done
rm $TMP
clear