Comments + removing unnecessary declaraion

This commit is contained in:
Bandie 2018-11-01 00:53:11 +01:00
parent 3da339d647
commit cad19d4d6b
Signed by: Bandie
GPG Key ID: C1E133BC65A822DD

View File

@ -14,24 +14,31 @@ if [ $EUID -ne 0 ]; then
fi fi
# Call when using the Cancel button
function cancel(){ function cancel(){
clear clear
echo "Bye! :)" echo "Bye! :)"
exit 0 exit 0
} }
# Call when CTRL+C
trap "cancel" INT trap "cancel" INT
# Check, if $1 is a gpt formatted device
function checkGPT(){ function checkGPT(){
blkid $1 -t PTTYPE=gpt >> /dev/null blkid $1 -t PTTYPE=gpt >> /dev/null
return $? return $?
} }
# Get the GPT PartitionUUID
function getPARTUUID(){ function getPARTUUID(){
blkid $1 | awk '{print $4;}' | sed 's/PARTUUID="//;s/"//' blkid $1 | awk '{print $4;}' | sed 's/PARTUUID="//;s/"//'
} }
# Get the LUKS-Device's UUId
function getLUKSDevice(){ function getLUKSDevice(){
if [ "$1" = "UUID" ]; then if [ "$1" = "UUID" ]; then
blkid /dev/sda*[1-9] | grep "crypto_LUKS" | awk '{print $2;}' | sed 's/UUID="//;s/"//' blkid /dev/sda*[1-9] | grep "crypto_LUKS" | awk '{print $2;}' | sed 's/UUID="//;s/"//'
@ -41,6 +48,8 @@ function getLUKSDevice(){
fi fi
} }
# Generic dialog question
function ask(){ function ask(){
dialog --backtitle "pam_panic's Configuration Generator" --title "$1" --yesno "$2" 8 80 dialog --backtitle "pam_panic's Configuration Generator" --title "$1" --yesno "$2" 8 80
@ -48,10 +57,14 @@ function ask(){
} }
# Generic message box
msg() { msg() {
dialog --backtitle "pam_panic's Configuration Generator" --msgbox "$1" 8 80 dialog --backtitle "pam_panic's Configuration Generator" --msgbox "$1" 8 80
} }
# Generate a two dimensional flat array of all GPT devices from sdb-sdz
function getMediaDevice(){ function getMediaDevice(){
local i=0 local i=0
local uuid local uuid
@ -65,8 +78,8 @@ function getMediaDevice(){
done done
} }
declare -g -a mediaArray
# Hint for GPT formatted key before searching for it
function chooseMediumPre(){ function chooseMediumPre(){
local title="Removable media: $1 device" local title="Removable media: $1 device"
@ -74,8 +87,10 @@ function chooseMediumPre(){
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
cancel cancel
fi fi
} }
# Choosing a GPT formatted key
function chooseMedium(){ function chooseMedium(){
local ans local ans
local title="Removable media: $1 device" local title="Removable media: $1 device"
@ -92,6 +107,8 @@ function chooseMedium(){
return $ans return $ans
} }
# A "Detecting devices...", assures to use a more up to date device list
function showDetectDev(){ function showDetectDev(){
dialog --backtitle "pam_panic's Configuration Generator" \ dialog --backtitle "pam_panic's Configuration Generator" \
--title "$title" \ --title "$title" \
@ -100,6 +117,8 @@ function showDetectDev(){
sleep 2 sleep 2
} }
# Welcome
dialog --backtitle "pam_panic's Configuration Generator" \ dialog --backtitle "pam_panic's Configuration Generator" \
--title "Welcome" \ --title "Welcome" \
--ok-label "Yip!" \ --ok-label "Yip!" \
@ -108,6 +127,7 @@ dialog --backtitle "pam_panic's Configuration Generator" \
auth_mode=2 auth_mode=2
while [ $auth_mode -eq 2 ]; do while [ $auth_mode -eq 2 ]; do
# Authentication mode
dialog --backtitle "pam_panic's Configuration Generator" \ dialog --backtitle "pam_panic's Configuration Generator" \
--title "Authentication mode" \ --title "Authentication mode" \
--help-button \ --help-button \
@ -119,7 +139,8 @@ while [ $auth_mode -eq 2 ]; do
case $auth_mode in case $auth_mode in
"0") "0")
# Removable media
# Authentication
while [ -z $media ]; do while [ -z $media ]; do
chooseMediumPre Authentication chooseMediumPre Authentication
showDetectDev showDetectDev
@ -130,7 +151,7 @@ while [ $auth_mode -eq 2 ]; do
auth_dev=$(echo ${mediaArray[$?]} | sed 's/\/dev\/sd[b-z]*[0-1]\[//;s/\]//') auth_dev=$(echo ${mediaArray[$?]} | sed 's/\/dev\/sd[b-z]*[0-1]\[//;s/\]//')
msg "Authentication device chosen with UUID $auth_dev." msg "Authentication device chosen with UUID $auth_dev."
# Panic
unset media unset media
while [ -z $media ]; do while [ -z $media ]; do
chooseMediumPre Panic chooseMediumPre Panic
@ -144,6 +165,7 @@ while [ $auth_mode -eq 2 ]; do
;; ;;
"3") "3")
# Passwords
ask "Passwords" "Do you want to set the passwords now?" ask "Passwords" "Do you want to set the passwords now?"
setpw=$? setpw=$?
case $setpw in case $setpw in
@ -159,15 +181,17 @@ while [ $auth_mode -eq 2 ]; do
esac esac
;; ;;
"2") "2")
# Help
man pam_panic man pam_panic
;; ;;
"1") "1")
# Cancel
cancel cancel
;; ;;
esac esac
done done
# serious flag
ask "pam_panic's behaviour" "Do you wish to destroy your LUKS header in case of emergency?\nThis means that your encrypted device won't be readable anymore. After this question you will be asked to make a backup of this header." ask "pam_panic's behaviour" "Do you wish to destroy your LUKS header in case of emergency?\nThis means that your encrypted device won't be readable anymore. After this question you will be asked to make a backup of this header."
serious=$? serious=$?
@ -175,6 +199,7 @@ if [ $serious -eq 0 ]; then
serious_dev=$(getLUKSDevice UUID) serious_dev=$(getLUKSDevice UUID)
msg "We will destroy $(getLUKSDevice NAME) [$serious_dev] when you trigger the panic function." msg "We will destroy $(getLUKSDevice NAME) [$serious_dev] when you trigger the panic function."
# LUKS header backup
ask "LUKS Header backup" "Do you want to make a LUKS-Header backup now?\nIt will be saved at \"$LHBU\"." ask "LUKS Header backup" "Do you want to make a LUKS-Header backup now?\nIt will be saved at \"$LHBU\"."
bu=$? bu=$?
case $bu in case $bu in
@ -185,6 +210,7 @@ if [ $serious -eq 0 ]; then
esac esac
fi fi
# poweroff / reboot behaviour
dialog --backtitle "pam_panic's Configuration Generator" \ dialog --backtitle "pam_panic's Configuration Generator" \
--title "pam_panic's behaviour" \ --title "pam_panic's behaviour" \
--ok-label "Reboot" \ --ok-label "Reboot" \
@ -193,6 +219,8 @@ dialog --backtitle "pam_panic's Configuration Generator" \
--yesno "Do you wish a reboot or a shutdown after issuing the panic function? n for nothing of those? " 10 80 --yesno "Do you wish a reboot or a shutdown after issuing the panic function? n for nothing of those? " 10 80
power=$? power=$?
# Configuration generation
dialog --backtitle "pam_panic's Configuration Generator" \ dialog --backtitle "pam_panic's Configuration Generator" \
--infobox "Generating configuration..." 3 40 --infobox "Generating configuration..." 3 40
config="#%PAM-1.0\nauth requisite pam_panic.so" config="#%PAM-1.0\nauth requisite pam_panic.so"
@ -223,6 +251,8 @@ esac
config="$config\naccount requisite pam_panic.so" config="$config\naccount requisite pam_panic.so"
# Write config file
if [ -f $CONFIGFILE ]; then if [ -f $CONFIGFILE ]; then
ask "Configfile exist" "$CONFIGFILE exists. Overwrite it?" ask "Configfile exist" "$CONFIGFILE exists. Overwrite it?"
ov=$? ov=$?
@ -235,7 +265,7 @@ else
echo -e "$config" > $CONFIGFILE echo -e "$config" > $CONFIGFILE
fi fi
# Finished message
clear clear
[ $ov -eq 0 ] && echo "Done! <3" || echo "Nothing done! </3" [ $ov -eq 0 ] && echo "Done! <3" || echo "Nothing done! </3"