From e0f315d47abbb3b14c6c37b450de60d49fb41114 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Thu, 19 Apr 2018 02:35:24 +0300 Subject: [PATCH 1/3] Make beesd -h useful Signed-off-by: Timofey Titovets --- scripts/beesd.in | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/beesd.in b/scripts/beesd.in index 269f77f..629c755 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -14,13 +14,9 @@ export UUID AL16M readonly AL16M="$((16*1024*1024))" readonly CONFIG_DIR=@PREFIX@/etc/bees/ -## Pre checks -{ - [ ! -d "$CONFIG_DIR" ] && ERRO "Missing: $CONFIG_DIR" - [ "$UID" == "0" ] || ERRO "Must be run as root" -} +readonly bees_bin=$(realpath @LIBEXEC_PREFIX@/bees) -command -v @LIBEXEC_PREFIX@/bees &> /dev/null || ERRO "Missing 'bees' agent" +command -v "$bees_bin" &> /dev/null || ERRO "Missing 'bees' agent" ## Parse args ARGUMENTS=() @@ -54,11 +50,21 @@ case "$UUID" in source "$FILE_CONFIG" ;; *) - echo "beesd [options] " + echo "Usage: beesd [options] " + echo "- - -" + "$bees_bin" --help exit 1 ;; esac + +## Pre checks +{ + [ ! -d "$CONFIG_DIR" ] && ERRO "Missing: $CONFIG_DIR" + [ "$UID" == "0" ] || ERRO "Must be run as root" +} + + WORK_DIR="${WORK_DIR:-/run/bees/}" MNT_DIR="${MNT_DIR:-$WORK_DIR/mnt/$UUID}" BEESHOME="${BEESHOME:-$MNT_DIR/.beeshome}" @@ -113,7 +119,7 @@ fi chmod 700 "$DB_PATH" } -MNT_DIR="${MNT_DIR//\/\//\/}" +MNT_DIR="$(realpath $MNT_DIR)" cd "$MNT_DIR" -@LIBEXEC_PREFIX@/bees "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR" +"$bees_bin" "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR" From 2d14fd90e4085e253b2379dbb24345f004c47453 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Thu, 19 Apr 2018 02:38:02 +0300 Subject: [PATCH 2/3] Update options in sample config Signed-off-by: Timofey Titovets --- scripts/beesd.conf.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/beesd.conf.sample b/scripts/beesd.conf.sample index ee1413a..036540a 100644 --- a/scripts/beesd.conf.sample +++ b/scripts/beesd.conf.sample @@ -15,8 +15,8 @@ UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # BEESHOME="$MNT_DIR/.beeshome" # BEESSTATUS="$WORK_DIR/$UUID.status" -## Default options to apply, see --help for details -# OPTIONS="--relative-paths --notimestamps" +## Options to apply, see `beesd --help` for details +# OPTIONS="--strip-paths --no-timestamps" ## Bees DB size # Hash Table Sizing From 06d41fd5180ec7284083bd0222f82f8c8c98502a Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Sun, 29 Apr 2018 07:52:49 +0300 Subject: [PATCH 3/3] Rewrite beesd arg parser Signed-off-by: Timofey Titovets --- scripts/beesd.in | 96 ++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/scripts/beesd.in b/scripts/beesd.in index 629c755..9665036 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -18,44 +18,70 @@ readonly bees_bin=$(realpath @LIBEXEC_PREFIX@/bees) command -v "$bees_bin" &> /dev/null || ERRO "Missing 'bees' agent" -## Parse args +uuid_valid(){ + if uuidparse -n -o VARIANT $1 | grep -i -q invalid; then + false + fi +} + +help(){ + echo "Usage: beesd [options] " + echo "- - -" + exec "$bees_bin" --help +} + +get_bees_supp_opts(){ + "$bees_bin" --help |& awk '/--../ { gsub( ",", "" ); print $1 " " $2}' +} + +SUPPORTED_ARGS=( + $(get_bees_supp_opts) +) +NOT_SUPPORTED_ARGS=() ARGUMENTS=() -while [ $# -gt 0 ]; do - case "$1" in - -*) - ARGUMENTS+=($1) - ;; - *) - if [ -z "$UUID" ]; then - UUID="$1" - else - ERRO "Only one filesystem may be supplied" - fi - ;; - esac - shift + +for arg in "${@}"; do + supp=false + for supp_arg in "${SUPPORTED_ARGS[@]}"; do + if [ "$arg" == "$supp_arg" ]; then + supp=true + break + fi + done + if $supp; then + ARGUMENTS+=($arg) + else + NOT_SUPPORTED_ARGS+=($arg) + fi done -case "$UUID" in - *-*-*-*-*) - FILE_CONFIG="" - for file in "$CONFIG_DIR"/*.conf; do - [ ! -f "$file" ] && continue - if grep -q "$UUID" "$file"; then - INFO "Find $UUID in $file, use as conf" - FILE_CONFIG="$file" - fi - done - [ ! -f "$FILE_CONFIG" ] && ERRO "No config for $UUID" - source "$FILE_CONFIG" - ;; - *) - echo "Usage: beesd [options] " - echo "- - -" - "$bees_bin" --help - exit 1 - ;; -esac +for arg in "${ARGUMENTS[@]}"; do + case $arg in + -h) help;; + --help) help;; + esac +done + +for arg in "${NOT_SUPPORTED_ARGS[@]}"; do + if uuid_valid $arg; then + [ ! -z "$UUID" ] && help + UUID=$arg + fi +done + +[ -z "$UUID" ] && help + + +FILE_CONFIG="" +for file in "$CONFIG_DIR"/*.conf; do + [ ! -f "$file" ] && continue + if grep -q 'UUID=' "$file" | grep -q -- "$UUID"; then + INFO "Find $UUID in $file, use as conf" + FILE_CONFIG="$file" + fi +done +[ ! -f "$FILE_CONFIG" ] && ERRO "No config for $UUID" +source "$FILE_CONFIG" ## Pre checks