git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Pfeiffer <coding _ lirion.de> 2020-04-27 08:36:20 +0200
committerHarald Pfeiffer <coding _ lirion.de> 2020-04-27 08:36:20 +0200
commit3be592752791cb9d7f7967bcfbeb75ab3294bceb (patch)
tree83538d0a2eca51245f74ddec92180dc8958dd01f
parent45d80382825427180b193a39d47f49dbcfbe4e59 (diff)
downloadlinux-scripts-3be592752791cb9d7f7967bcfbeb75ab3294bceb.tar.bz2
introducing -y flag
-rwxr-xr-xsbin/makebuff12
1 files changed, 7 insertions, 5 deletions
diff --git a/sbin/makebuff b/sbin/makebuff
index 0569a9d..ca6dd2d 100755
--- a/sbin/makebuff
+++ b/sbin/makebuff
@@ -13,20 +13,21 @@
# LICENCE included in containing directory.
# AUTHOR: Harald Pfeiffer <coding@lirion.de>
-declare -x FILEC BUFDIR="/var/local/buff"
+declare -x FILEC BUFDIR="/var/local/buff" YES="no"
hayulp() {
- printf "USAGE: %b [ -b DIR ] [ -f COUNT ] | [ -b DIR ] [ -p ] | [ -h ]\\n" "$(basename "$0")"
+ printf "USAGE: %b [ -y ] ( [ -b DIR ] [ -f COUNT ] | [ -b DIR ] [ -p ] | [ -h ] )\\n" "$(basename "$0")"
(
printf -- "-h:;This help\\n"
printf -- "-b:;Buffer directory. If specified and purge mode is selected, needs to be\n"
printf " ;specified before -p. Default: %b\n" "$BUFDIR"
printf -- "-f:;Number of files (of 256 KiB each) to be created.\n"
printf -- "-p:;Purge the buffer directory\\n"
+ printf -- "-y:;Yes Mode: non-interactive, make the script proceed without asking.\n"
)|column -ts\;
}
purge() {
- read -rp "Purging $BUFDIR, continue? [y/N] " PCONF
+ [ "$YES" == "no" ]&&read -rp "Purging $BUFDIR, continue? [y/N] " PCONF||PCONF="y"
case "$PCONF" in
y|Y|j|J)
for i in "$BUFDIR"/*;do
@@ -36,12 +37,13 @@ purge() {
esac
}
-while getopts :hpb:f: SHOPT; do
+while getopts :hpyb:f: SHOPT; do
case "${SHOPT}" in
h)hayulp;exit 0;;
f)FILEC="${OPTARG}";;
b)BUFDIR="${OPTARG}";;
p)purge;exit "$?";;
+ y)YES="yes";;
*)shift $((OPTIND-1));printf "Invalid option: -%b\\n" "${OPTARG}" >&2;exit 127;;
esac
done
@@ -56,7 +58,7 @@ else
fi
chmod 02750 "$BUFDIR"||exit 1
-[ -z "$FILEC" ]&&read -rp "How many files should we create? [40] " FILEC
+[ "$YES" == "no" ]&&[ -z "$FILEC" ]&&read -rp "How many files should we create? [40] " FILEC
[ -z "$FILEC" ]&&FILEC=40
printf "[....] Creating buffer files\\033[s..."