smol fixes
This commit is contained in:
@@ -13,22 +13,36 @@ fi
|
|||||||
|
|
||||||
CONFIG_FILE="$1.yml"
|
CONFIG_FILE="$1.yml"
|
||||||
GLOBS_FILE="${2:-node-key-globs.txt}"
|
GLOBS_FILE="${2:-node-key-globs.txt}"
|
||||||
|
SCRIPT_DIR="$(dirname "$0")"
|
||||||
|
|
||||||
# Check if config file exists
|
# Try to find config file in multiple locations
|
||||||
if [[ ! -f "/root/rpc/$CONFIG_FILE" ]]; then
|
if [[ -f "$SCRIPT_DIR/$CONFIG_FILE" ]]; then
|
||||||
echo "Error: Configuration file /root/rpc/$CONFIG_FILE does not exist"
|
CONFIG_PATH="$SCRIPT_DIR/$CONFIG_FILE"
|
||||||
|
elif [[ -f "/root/rpc/$CONFIG_FILE" ]]; then
|
||||||
|
CONFIG_PATH="/root/rpc/$CONFIG_FILE"
|
||||||
|
else
|
||||||
|
echo "Error: Configuration file $CONFIG_FILE not found in $SCRIPT_DIR or /root/rpc"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Resolve globs file path - always relative to script directory
|
||||||
|
if [[ "$GLOBS_FILE" == /* ]]; then
|
||||||
|
# Absolute path provided, use as-is
|
||||||
|
GLOBS_PATH="$GLOBS_FILE"
|
||||||
|
else
|
||||||
|
# Relative path, resolve relative to script directory
|
||||||
|
GLOBS_PATH="$SCRIPT_DIR/$GLOBS_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if globs file exists
|
# Check if globs file exists
|
||||||
if [[ ! -f "$(dirname "$0")/$GLOBS_FILE" ]]; then
|
if [[ ! -f "$GLOBS_PATH" ]]; then
|
||||||
echo "Error: Globs file $(dirname "$0")/$GLOBS_FILE does not exist"
|
echo "Error: Globs file $GLOBS_PATH does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read volume keys from config file
|
# Read volume keys from config file
|
||||||
echo "Reading volume configuration from $CONFIG_FILE..."
|
echo "Reading volume configuration from $CONFIG_PATH..."
|
||||||
keys=$(cat /root/rpc/$CONFIG_FILE | yaml2json - | jq '.volumes' | jq -r 'keys[]')
|
keys=$(cat "$CONFIG_PATH" | yaml2json - | jq '.volumes' | jq -r 'keys[]')
|
||||||
|
|
||||||
if [[ -z "$keys" ]]; then
|
if [[ -z "$keys" ]]; then
|
||||||
echo "Error: No volumes found in configuration"
|
echo "Error: No volumes found in configuration"
|
||||||
@@ -42,16 +56,16 @@ while IFS= read -r line || [[ -n "$line" ]]; do
|
|||||||
if [[ -n "$line" && ! "$line" =~ ^[[:space:]]*# ]]; then
|
if [[ -n "$line" && ! "$line" =~ ^[[:space:]]*# ]]; then
|
||||||
globs+=("$line")
|
globs+=("$line")
|
||||||
fi
|
fi
|
||||||
done < "$(dirname "$0")/$GLOBS_FILE"
|
done < "$GLOBS_PATH"
|
||||||
|
|
||||||
if [[ ${#globs[@]} -eq 0 ]]; then
|
if [[ ${#globs[@]} -eq 0 ]]; then
|
||||||
echo "Error: No glob patterns found in $GLOBS_FILE"
|
echo "Error: No glob patterns found in $GLOBS_PATH"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
volume_count=$(echo "$keys" | wc -l)
|
volume_count=$(echo "$keys" | wc -l)
|
||||||
echo "Found $volume_count volumes to process"
|
echo "Found $volume_count volumes to process"
|
||||||
echo "Using ${#globs[@]} glob pattern(s) from $GLOBS_FILE"
|
echo "Using ${#globs[@]} glob pattern(s) from $GLOBS_PATH"
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
|
|
||||||
deleted_count=0
|
deleted_count=0
|
||||||
@@ -69,27 +83,44 @@ for key in $keys; do
|
|||||||
volume_deleted=0
|
volume_deleted=0
|
||||||
|
|
||||||
# For each glob pattern, find and delete matching files
|
# For each glob pattern, find and delete matching files
|
||||||
# Use subshell to safely change directory and enable globstar
|
# Use find instead of shell globbing for more reliable pattern matching
|
||||||
for glob in "${globs[@]}"; do
|
for glob in "${globs[@]}"; do
|
||||||
# Process in subshell to avoid affecting parent shell state
|
# Convert glob pattern to find pattern
|
||||||
while IFS= read -r file; do
|
# Handle **/ patterns by using find recursively
|
||||||
if [[ -n "$file" && -f "$file" ]]; then
|
if [[ "$glob" =~ ^\*\*/ ]]; then
|
||||||
echo " Deleting: $file"
|
# Pattern like **/nodekey - find recursively
|
||||||
rm -f "$file"
|
find_pattern="${glob#\*\*/}" # Remove **/ prefix
|
||||||
((volume_deleted++))
|
while IFS= read -r -d '' file; do
|
||||||
((deleted_count++))
|
if [[ -n "$file" && -f "$file" ]]; then
|
||||||
fi
|
echo " Deleting: $file"
|
||||||
done < <(
|
rm -f "$file"
|
||||||
# Enable extended globbing and globstar for recursive patterns
|
((volume_deleted++))
|
||||||
shopt -s globstar nullglob
|
((deleted_count++))
|
||||||
cd "$volume_path" || exit 1
|
|
||||||
# Expand glob pattern and output full paths
|
|
||||||
for f in $glob; do
|
|
||||||
if [[ -f "$f" ]]; then
|
|
||||||
echo "$volume_path/$f"
|
|
||||||
fi
|
fi
|
||||||
done
|
done < <(find "$volume_path" -type f -name "$find_pattern" -print0 2>/dev/null)
|
||||||
)
|
elif [[ "$glob" == */* ]]; then
|
||||||
|
# Pattern like staking/* - find in specific directory
|
||||||
|
find_dir="${glob%/*}"
|
||||||
|
find_name="${glob#*/}"
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
if [[ -n "$file" && -f "$file" ]]; then
|
||||||
|
echo " Deleting: $file"
|
||||||
|
rm -f "$file"
|
||||||
|
((volume_deleted++))
|
||||||
|
((deleted_count++))
|
||||||
|
fi
|
||||||
|
done < <(find "$volume_path/$find_dir" -maxdepth 1 -type f -name "$find_name" -print0 2>/dev/null)
|
||||||
|
else
|
||||||
|
# Simple pattern like "key" or "node_key.json" - find recursively
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
if [[ -n "$file" && -f "$file" ]]; then
|
||||||
|
echo " Deleting: $file"
|
||||||
|
rm -f "$file"
|
||||||
|
((volume_deleted++))
|
||||||
|
((deleted_count++))
|
||||||
|
fi
|
||||||
|
done < <(find "$volume_path" -type f -name "$glob" -print0 2>/dev/null)
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $volume_deleted -eq 0 ]]; then
|
if [[ $volume_deleted -eq 0 ]]; then
|
||||||
|
|||||||
@@ -81,6 +81,6 @@ for file in "${restore_files[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
./delete-node-keys.sh $1
|
"$dir/delete-node-keys.sh" "$1"
|
||||||
|
|
||||||
echo "node $1 restored."
|
echo "node $1 restored."
|
||||||
|
|||||||
Reference in New Issue
Block a user