mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
This commit is contained in:
commit
bcfc3cf08b
@ -15,8 +15,8 @@ UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|||||||
# BEESHOME="$MNT_DIR/.beeshome"
|
# BEESHOME="$MNT_DIR/.beeshome"
|
||||||
# BEESSTATUS="$WORK_DIR/$UUID.status"
|
# BEESSTATUS="$WORK_DIR/$UUID.status"
|
||||||
|
|
||||||
## Default options to apply, see --help for details
|
## Options to apply, see `beesd --help` for details
|
||||||
# OPTIONS="--relative-paths --notimestamps"
|
# OPTIONS="--strip-paths --no-timestamps"
|
||||||
|
|
||||||
## Bees DB size
|
## Bees DB size
|
||||||
# Hash Table Sizing
|
# Hash Table Sizing
|
||||||
|
@ -14,50 +14,82 @@ export UUID AL16M
|
|||||||
readonly AL16M="$((16*1024*1024))"
|
readonly AL16M="$((16*1024*1024))"
|
||||||
readonly CONFIG_DIR=@ETC_PREFIX@/bees/
|
readonly CONFIG_DIR=@ETC_PREFIX@/bees/
|
||||||
|
|
||||||
## Pre checks
|
readonly bees_bin=$(realpath @LIBEXEC_PREFIX@/bees)
|
||||||
{
|
|
||||||
[ ! -d "$CONFIG_DIR" ] && ERRO "Missing: $CONFIG_DIR"
|
command -v "$bees_bin" &> /dev/null || ERRO "Missing 'bees' agent"
|
||||||
[ "$UID" == "0" ] || ERRO "Must be run as root"
|
|
||||||
|
uuid_valid(){
|
||||||
|
if uuidparse -n -o VARIANT $1 | grep -i -q invalid; then
|
||||||
|
false
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
command -v @LIBEXEC_PREFIX@/bees &> /dev/null || ERRO "Missing 'bees' agent"
|
help(){
|
||||||
|
echo "Usage: beesd [options] <btrfs_uuid>"
|
||||||
|
echo "- - -"
|
||||||
|
exec "$bees_bin" --help
|
||||||
|
}
|
||||||
|
|
||||||
## Parse args
|
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
|
||||||
|
ARGUMENTS+=($arg)
|
||||||
|
else
|
||||||
|
NOT_SUPPORTED_ARGS+=($arg)
|
||||||
fi
|
fi
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
done
|
||||||
|
|
||||||
case "$UUID" in
|
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=""
|
FILE_CONFIG=""
|
||||||
for file in "$CONFIG_DIR"/*.conf; do
|
for file in "$CONFIG_DIR"/*.conf; do
|
||||||
[ ! -f "$file" ] && continue
|
[ ! -f "$file" ] && continue
|
||||||
if grep -q "$UUID" "$file"; then
|
if grep -q 'UUID=' "$file" | grep -q -- "$UUID"; then
|
||||||
INFO "Find $UUID in $file, use as conf"
|
INFO "Find $UUID in $file, use as conf"
|
||||||
FILE_CONFIG="$file"
|
FILE_CONFIG="$file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[ ! -f "$FILE_CONFIG" ] && ERRO "No config for $UUID"
|
[ ! -f "$FILE_CONFIG" ] && ERRO "No config for $UUID"
|
||||||
source "$FILE_CONFIG"
|
source "$FILE_CONFIG"
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "beesd [options] <btrfs_uuid>"
|
## Pre checks
|
||||||
exit 1
|
{
|
||||||
;;
|
[ ! -d "$CONFIG_DIR" ] && ERRO "Missing: $CONFIG_DIR"
|
||||||
esac
|
[ "$UID" == "0" ] || ERRO "Must be run as root"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WORK_DIR="${WORK_DIR:-/run/bees/}"
|
WORK_DIR="${WORK_DIR:-/run/bees/}"
|
||||||
MNT_DIR="${MNT_DIR:-$WORK_DIR/mnt/$UUID}"
|
MNT_DIR="${MNT_DIR:-$WORK_DIR/mnt/$UUID}"
|
||||||
@ -113,7 +145,7 @@ fi
|
|||||||
chmod 700 "$DB_PATH"
|
chmod 700 "$DB_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
MNT_DIR="${MNT_DIR//\/\//\/}"
|
MNT_DIR="$(realpath $MNT_DIR)"
|
||||||
|
|
||||||
cd "$MNT_DIR"
|
cd "$MNT_DIR"
|
||||||
@LIBEXEC_PREFIX@/bees "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR"
|
"$bees_bin" "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user