Skip to content

Commit

Permalink
oem-factory-reset: remove duplicates and add proper error redirection…
Browse files Browse the repository at this point in the history
… to file

- Trace calls need to happen after sourcing /etc/functions not before
- Move sourcing of external files at beginning of file, remove /etc/functions sourcing duplicate
- gpg error redirection was sent to /dev/null where expected to be added to whiptail in case of error (2>&1 instead and redirection to file)
  • Loading branch information
tlaurion committed Mar 28, 2023
1 parent 1ecc785 commit 0ff323a
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions initrd/bin/oem-factory-reset
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash
# Automated setup of TPM, GPG keys, and disk

TRACE "Under /bin/oem-factory-reset"

set -o pipefail

## External files sourced
. /etc/functions
. /etc/luks-functions
. /tmp/config

TRACE "Under /bin/oem-factory-reset"

# use TERM to exit on error
trap "exit 1" TERM
Expand Down Expand Up @@ -39,12 +43,6 @@ GPG_USER_MAIL="oem-${GPG_KEY_NAME}@example.com"
GPG_USER_COMMENT="OEM-generated key"
SKIP_BOOT="n"

## External files sourced

. /etc/functions
. /etc/luks-functions
. /tmp/config

## functions

die() {
Expand Down Expand Up @@ -81,7 +79,7 @@ gpg_key_reset()
echo y
echo yes
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit \
> /tmp/gpg_card_edit_output 2>/dev/null
> /tmp/gpg_card_edit_output 2>&1
if [ $? -ne 0 ]; then
ERROR=`cat /tmp/gpg_card_edit_output`
whiptail_error_die "GPG Key factory reset failed!\n\n$ERROR"
Expand All @@ -97,7 +95,7 @@ gpg_key_reset()
echo forcesig
echo ${ADMIN_PIN_DEF}
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit \
> /tmp/gpg_card_edit_output 2>/dev/null
> /tmp/gpg_card_edit_output 2>&1
if [ $? -ne 0 ]; then
ERROR=`cat /tmp/gpg_card_edit_output`
whiptail_error_die "GPG Key forcesig toggle on failed!\n\n$ERROR"
Expand All @@ -117,7 +115,7 @@ gpg_key_reset()
echo ${RSA_KEY_LENGTH} #Authentication key size set to RSA_KEY_LENGTH
echo ${ADMIN_PIN_DEF}
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit \
> /tmp/gpg_card_edit_output 2>/dev/null
> /tmp/gpg_card_edit_output 2>&1
if [ $? -ne 0 ]; then
ERROR=`cat /tmp/gpg_card_edit_output`
whiptail_error_die "Setting key attributed to RSA ${RSA_KEY_LENGTH} bits in USB security dongle failed."
Expand All @@ -135,7 +133,7 @@ gpg_key_reset()
echo ${GPG_USER_MAIL}
echo ${GPG_USER_COMMENT}
} | gpg --command-fd=0 --status-fd=2 --pinentry-mode=loopback --card-edit \
> /tmp/gpg_card_edit_output 2>/dev/null
> /tmp/gpg_card_edit_output 2>&1
if [ $? -ne 0 ]; then
ERROR=`cat /tmp/gpg_card_edit_output`
whiptail_error_die "GPG Key automatic keygen failed!\n\n$ERROR"
Expand All @@ -159,7 +157,7 @@ gpg_key_change_pin()
echo q
echo q
} | gpg --command-fd=0 --status-fd=2 --pinentry-mode=loopback --card-edit \
> /tmp/gpg_card_edit_output 2>/dev/null
> /tmp/gpg_card_edit_output 2>&1
if [ $? -ne 0 ]; then
ERROR=`cat /tmp/gpg_card_edit_output | fold -s`
whiptail_error_die "GPG Key PIN change failed!\n\n$ERROR"
Expand Down

0 comments on commit 0ff323a

Please sign in to comment.