kiss: y/n prompts and view package build file feature

This commit is contained in:
Dylan Araps 2020-02-18 21:14:49 +02:00
parent 9bb2c8bee1
commit 290d11092a
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 33 additions and 18 deletions

51
kiss
View File

@ -39,14 +39,26 @@ contains() {
case " $1 " in *" $2 "*) return 0; esac; return 1 case " $1 " in *" $2 "*) return 0; esac; return 1
} }
prompt() { yn() {
# Ask the user for some input. log "${1:-Continue?} (y/n)"
log "Continue?: Press Enter to continue or Ctrl+C to abort here"
# POSIX 'read' has none of the "nice" options like '-n', '-p' # Enable raw input to allow for a single byte to be read from
# etc etc. This is the most basic usage of 'read'. # stdin without needing to wait for the user to press Return.
# '_' is used as 'dash' errors when no variable is given to 'read'. stty -icanon -echo
read -r _
# Read a single byte from stdin using 'dd'. POSIX 'read' has
# no support for single/'N' byte based input from the user.
answer=$(dd ibs=1 count=1 2>/dev/null)
# Disable raw input, leaving the terminal how we *should*
# have found it.
stty icanon echo
# Handle the answer here directly, enabling this function's
# return status to be used in place of checking for '[yY]'
# throughout this program. Also call the function again if
# invalid input is given.
case $answer in y) ;; n) return 1 ;; *) yn "$1"; esac
} }
as_root() { as_root() {
@ -526,7 +538,7 @@ pkg_build() {
log "Building: $*" log "Building: $*"
# Only ask for confirmation if more than one package needs to be built. # Only ask for confirmation if more than one package needs to be built.
[ $# -gt 1 ] || [ "$pkg_update" ] && prompt [ $# -gt 1 ] || [ "$pkg_update" ] && yn
log "Checking to see if any dependencies have already been built" log "Checking to see if any dependencies have already been built"
log "Installing any pre-built dependencies" log "Installing any pre-built dependencies"
@ -560,6 +572,13 @@ pkg_build() {
pkg_verify "$@" pkg_verify "$@"
# Allow user to inspect package files prior to build.
[ "$KISS_AUDIT" != 1 ] ||
for pkg; do
yn "View build file for $pkg?" &&
"${EDITOR:-vi}" "$(pkg_find "$pkg")/build"
done
# Finally build and create tarballs for all passed packages and # Finally build and create tarballs for all passed packages and
# dependencies. # dependencies.
for pkg; do for pkg; do
@ -643,13 +662,9 @@ pkg_build() {
set -- $explicit set -- $explicit
# Only ask for confirmation if more than one package needs to be installed. # Only ask for confirmation if more than one package needs to be installed.
[ $# -gt 1 ] && { [ $# -gt 1 ] && yn "Install built packages? [$*]" && {
log "Install built packages? [$*]" args i "$@"
return
prompt && {
args i "$@"
return
}
} }
log "Run 'kiss i $*' to install the package(s)" log "Run 'kiss i $*' to install the package(s)"
@ -730,8 +745,8 @@ pkg_conflicts() {
# Enable alternatives automatically if it is safe to do so. # Enable alternatives automatically if it is safe to do so.
# This checks to see that the package that is about to be installed # This checks to see that the package that is about to be installed
# doesn't overwrite anything it shouldn't in '/var/db/kiss/installed'. # doesn't overwrite anything it shouldn't in '/var/db/kiss/installed'.
"$grep" -Fxf "$cac_dir/$pid-m" -- "$@" | "$grep" -Fxf "$cac_dir/$pid-m" -- "$@" |
"$grep" -q ":/var/db/kiss/installed/" || choice_auto=1 "$grep" -q ":/var/db/kiss/installed/" || choice_auto=1
# Use 'grep' to list matching lines between the to # Use 'grep' to list matching lines between the to
# be installed package's manifest and the above filtered # be installed package's manifest and the above filtered
@ -1146,7 +1161,7 @@ pkg_updates() {
log "Detected package manager update" log "Detected package manager update"
log "The package manager will be updated first" log "The package manager will be updated first"
prompt yn
pkg_build kiss pkg_build kiss
args i kiss args i kiss