Skip to content

Commit

Permalink
Add --alert option (bell on interactive prompt)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakaki- committed Aug 10, 2015
1 parent aea30eb commit 8fde4b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
39 changes: 30 additions & 9 deletions buildkernel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ shopt -s nullglob
# ********************** variables *********************
PROGNAME="$(basename "${0}")"
CONFFILE="/etc/${PROGNAME}.conf"
VERSION="1.0.11"
VERSION="1.0.12"
ETCPROFILE="/etc/profile"
DEFAULTEFIBOOTFILE="bootx64.efi"
EFIBOOTFILE="${DEFAULTEFIBOOTFILE}"
Expand Down Expand Up @@ -77,12 +77,13 @@ export EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS---jobs=${NUMCPUSPLUSONE} --loa
# below silently updates an old config, auto-choosing defaults for new values
CONFIGUPDATETYPE="olddefconfig"
SILENTUPDATETYPE="olddefconfig"
RED_TEXT="" GREEN_TEXT="" YELLOW_TEXT="" RESET_ATTS=""
RED_TEXT="" GREEN_TEXT="" YELLOW_TEXT="" RESET_ATTS="" ALERT_TEXT=""
if [[ -v TERM && -n "${TERM}" && "${TERM}" != "dumb" ]]; then
RED_TEXT="$(tput setaf 1)$(tput bold)"
GREEN_TEXT="$(tput setaf 2)$(tput bold)"
YELLOW_TEXT="$(tput setaf 3)$(tput bold)"
RESET_ATTS="$(tput sgr0)"
ALERT_TEXT="$(tput bel)"
fi
# used in subshells
UNCOMPRESSEDINITRAMFS="${BOOTDIR}/initramfs.cpio"
Expand Down Expand Up @@ -114,6 +115,7 @@ INITSYSTEM="${DEFAULTINITSYSTEM}"
USE_PLYMOUTH=true
VERBOSITYFLAG=""
ASKFLAG=""
ALERTFLAG=""
# following array variables set by find_all_gpg_keyfile_partitions function
declare -a GPGUUIDS GPGPARTNAMES GPGDEVNAMES GPGPARTNUMS
# following array variables set by find_all_luks_partitions function
Expand Down Expand Up @@ -156,7 +158,7 @@ declare -i ARG_ASK=0 ARG_CLEAN=0 ARG_COPYFROMSTAGING=0 ARG_HELP=0
declare -i ARG_STAGEONLY=0 ARG_UNMOUNTATEND=0 ARG_VERBOSE=0 ARG_VERSION=0
declare -i ARG_POSTCLEAR=0 ARG_MENUCONFIG=0 ARG_SNAPSHOTBACKUP=0
declare -i ARG_EASYSETUP=0 ARG_IS_NEW_KERNEL_AVAILABLE=0
declare -i ARG_REBUILD_EXTERNAL_MODULES=0
declare -i ARG_REBUILD_EXTERNAL_MODULES=0 ARG_ALERT=0

# ***************** various functions ******************
cleanup_and_exit_with_code() {
Expand All @@ -177,6 +179,15 @@ show() {
echo -e "${SHOWPREFIX}${MESSAGE}${SHOWSUFFIX}"
fi
}
alertshow() {
local MESSAGE=${1:-""}
local VERBLEVEL=${2:-${VERBOSITY}}
if ((ARG_ALERT==0)); then
show "${@}"
elif (( VERBLEVEL >=1 )); then
echo -e "${SHOWPREFIX}${MESSAGE}${SHOWSUFFIX}${ALERT_TEXT}"
fi
}
warning() {
echo -e "${YELLOW_TEXT}${PREFIXSTRING}${RESET_ATTS}${PROGNAME}: Warning: ${1}" >&2
}
Expand All @@ -191,7 +202,7 @@ trap_cleanup() {
}
trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL EXIT
test_yn() {
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}"
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}${ALERT_TEXT}"
read -r -n 1
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
Expand All @@ -201,7 +212,7 @@ test_yn() {
fi
}
test_yn_need_enter() {
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}"
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}${ALERT_TEXT}"
read -r
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
Expand All @@ -223,10 +234,14 @@ suppress_colours() {
RESET_ATTS=""
SHOWPREFIX="${PREFIXSTRING}"
}
suppress_colour_if_output_not_to_a_terminal() {
suppress_alert() {
ALERT_TEXT=""
}
suppress_colour_and_alert_if_output_not_to_a_terminal() {
if [ ! -t 1 -o ! -t 2 ]; then
# we are going to a non-terminal
suppress_colours
suppress_alert
fi
}
check_file_exists() {
Expand Down Expand Up @@ -1555,7 +1570,7 @@ allow_user_to_modify_config_graphically() {
# from calling conform_config_file(), before the UI is presented
if ((ARG_MENUCONFIG==1)); then
# force the menuconfig, no matter whether interactive or not
show "Executing make ${CONFIGTYPE}; select the kernel options you require..."
alertshow "Executing make ${CONFIGTYPE}; select the kernel options you require..."
make ${CONFIGTYPE}
elif ((ARG_ASK==1)); then
# interactive mode
Expand Down Expand Up @@ -1889,6 +1904,8 @@ Usage: ${PROGNAME} [options]
Options:
-a, --ask turns on interactive mode: you must confirm key actions
-A, --alert sound terminal bell when interaction required
(selecting this also automatically selects --ask)
-b, --snapshot-backup make a datestamped kernel / configuration backup on EFI
system partition (to keep a last-known-good version)
-c, --clean do a make clean at the beginning of kernel build
Expand Down Expand Up @@ -1968,7 +1985,7 @@ process_command_line_options() {
declare -i RC
set +e
# error trapping off, as we want to handle errors
TEMP="$(getopt -o abcefhimpsuvxV --long ask,snapshot-backup,clean,easy-setup,copy-from-staging,help,is-new-kernel-available,menuconfig,postclear,stage-only,verbose,unmount-at-end,rebuild-external-modules,version -n "${PROGNAME}" -- "${@}")"
TEMP="$(getopt -o aAbcefhimpsuvxV --long ask,alert,snapshot-backup,clean,easy-setup,copy-from-staging,help,is-new-kernel-available,menuconfig,postclear,stage-only,verbose,unmount-at-end,rebuild-external-modules,version -n "${PROGNAME}" -- "${@}")"
RC="${?}"
set -e
if ((RC!=0)); then
Expand All @@ -1980,6 +1997,7 @@ process_command_line_options() {
while true ; do
case "${1}" in
-a|--ask) ARG_ASK=1 ; shift ;;
-A|--alert) ARG_ALERT=1 ; ARG_ASK=1 ; shift ;;
-b|--snapshot-backup) ARG_SNAPSHOTBACKUP=1 ; shift ;;
-c|--clean) ARG_CLEAN=1 ; shift ;;
-e|--easy-setup) ARG_EASYSETUP=1 ; shift ;;
Expand Down Expand Up @@ -2008,6 +2026,9 @@ process_command_line_options() {
if ((ARG_ASK==1)); then
ASKFLAG="--ask"
fi
if ((ARG_ALERT==1)); then
ALERTFLAG="--alert"
fi
internal_consistency_option_checks
# process 'perform-then-exit' options
if ((ARG_HELP==1)); then
Expand All @@ -2030,7 +2051,7 @@ process_command_line_options() {
}

# *************** start of script proper ***************
suppress_colour_if_output_not_to_a_terminal
suppress_colour_and_alert_if_output_not_to_a_terminal
check_if_booted_under_efi
find_all_usb_partitions
source_etc_conf_file
Expand Down
6 changes: 5 additions & 1 deletion buildkernel.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH BUILDKERNEL 8 "Version 1.0.11: August 2015"
.TH BUILDKERNEL 8 "Version 1.0.12: August 2015"
.SH NAME
buildkernel \- build secure boot kernel, save to EFI system partition
.SH SYNOPSIS
Expand Down Expand Up @@ -93,6 +93,10 @@ performs a filesystem sync and then unmounts the EFI system partition (if you so
Sets interactive mode, in which you will be asked what to do at a number of
key steps in the process (see \fBALGORITHM DETAIL\fR, above).
.TP
.BR \-A ", " \-\-alert
If possible, sounds the terminal bell when interaction is needed.
Selecting this option automatically selects \fB--ask\fR.
.TP
.BR \-b ", " \-\-snapshot\-backup
Makes a backup of the current kernel and config on the EFI system partition,
using a a datestamp prefix for both files (based on the system date at the time
Expand Down
2 changes: 1 addition & 1 deletion buildkernel.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH BUILDKERNEL 5 "Version 1.0.11: August 2015"
.TH BUILDKERNEL 5 "Version 1.0.12: August 2015"
.SH NAME
buildkernel.conf \- a configuration file for \fBbuildkernel\fR(8)
.SH SYNOPSIS
Expand Down

0 comments on commit 8fde4b7

Please sign in to comment.