mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
Rewrite beesd arg parser
Signed-off-by: Timofey Titovets <timofey.titovets@synesis.ru>
This commit is contained in:
parent
2d14fd90e4
commit
06d41fd518
@ -18,44 +18,70 @@ readonly bees_bin=$(realpath @LIBEXEC_PREFIX@/bees)
|
|||||||
|
|
||||||
command -v "$bees_bin" &> /dev/null || ERRO "Missing 'bees' agent"
|
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] <btrfs_uuid>"
|
||||||
|
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=()
|
ARGUMENTS=()
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
for arg in "${@}"; do
|
||||||
-*)
|
supp=false
|
||||||
ARGUMENTS+=($1)
|
for supp_arg in "${SUPPORTED_ARGS[@]}"; do
|
||||||
;;
|
if [ "$arg" == "$supp_arg" ]; then
|
||||||
*)
|
supp=true
|
||||||
if [ -z "$UUID" ]; then
|
break
|
||||||
UUID="$1"
|
fi
|
||||||
else
|
done
|
||||||
ERRO "Only one filesystem may be supplied"
|
if $supp; then
|
||||||
fi
|
ARGUMENTS+=($arg)
|
||||||
;;
|
else
|
||||||
esac
|
NOT_SUPPORTED_ARGS+=($arg)
|
||||||
shift
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
case "$UUID" in
|
for arg in "${ARGUMENTS[@]}"; do
|
||||||
*-*-*-*-*)
|
case $arg in
|
||||||
FILE_CONFIG=""
|
-h) help;;
|
||||||
for file in "$CONFIG_DIR"/*.conf; do
|
--help) help;;
|
||||||
[ ! -f "$file" ] && continue
|
esac
|
||||||
if grep -q "$UUID" "$file"; then
|
done
|
||||||
INFO "Find $UUID in $file, use as conf"
|
|
||||||
FILE_CONFIG="$file"
|
for arg in "${NOT_SUPPORTED_ARGS[@]}"; do
|
||||||
fi
|
if uuid_valid $arg; then
|
||||||
done
|
[ ! -z "$UUID" ] && help
|
||||||
[ ! -f "$FILE_CONFIG" ] && ERRO "No config for $UUID"
|
UUID=$arg
|
||||||
source "$FILE_CONFIG"
|
fi
|
||||||
;;
|
done
|
||||||
*)
|
|
||||||
echo "Usage: beesd [options] <btrfs_uuid>"
|
[ -z "$UUID" ] && help
|
||||||
echo "- - -"
|
|
||||||
"$bees_bin" --help
|
|
||||||
exit 1
|
FILE_CONFIG=""
|
||||||
;;
|
for file in "$CONFIG_DIR"/*.conf; do
|
||||||
esac
|
[ ! -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
|
## Pre checks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user