|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
if ! command -v pigz &> /dev/null; then |
|
|
echo "Error: pigz is not installed. Please install it and try again." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
|
|
|
ROOT_DIR="/ssd2/TzuYu/data" |
|
|
|
|
|
|
|
|
usage() { |
|
|
echo "Usage: $0 [--method METHOD --config CONFIG] | [--dir-path DIR_PATH] | [--all]" |
|
|
exit 1 |
|
|
} |
|
|
|
|
|
zip_config() { |
|
|
local method=$1 |
|
|
local config=$2 |
|
|
local dir_path="$ROOT_DIR/$method/$config" |
|
|
local output_path="./data/$method/$config/$config.tar.gz" |
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "$output_path")" |
|
|
|
|
|
|
|
|
echo "Zipping $dir_path to $output_path" |
|
|
tar -cv --use-compress-program=pigz -f "$output_path" -C "$dir_path" . |
|
|
if [[ $? -ne 0 ]]; then |
|
|
echo "Error: Failed to create tar.gz for $dir_path" |
|
|
exit 1 |
|
|
fi |
|
|
} |
|
|
|
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do |
|
|
case $1 in |
|
|
--help) usage ;; |
|
|
--h) usage ;; |
|
|
--all) ALL="true" ;; |
|
|
--method) METHOD="$2"; shift ;; |
|
|
--config) CONFIG="$2"; shift ;; |
|
|
--dir-path) DIR_PATH="$2"; shift ;; |
|
|
*) echo "Unknown parameter: $1"; usage ;; |
|
|
esac |
|
|
shift |
|
|
done |
|
|
|
|
|
|
|
|
if [[ "$ALL" == "true" ]]; then |
|
|
|
|
|
for method_dir in "$ROOT_DIR"/*; do |
|
|
if [[ -d "$method_dir" && "$(basename "$method_dir")" != "Origin" ]]; then |
|
|
method=$(basename "$method_dir") |
|
|
for config_dir in "$method_dir"/config*; do |
|
|
if [[ -d "$config_dir" ]]; then |
|
|
config=$(basename "$config_dir") |
|
|
zip_config "$method" "$config" |
|
|
fi |
|
|
done |
|
|
fi |
|
|
done |
|
|
|
|
|
if [ ! -e "./data/Origin/Origin.tar.gz" ]; then |
|
|
|
|
|
mkdir -p "./data/Origin" |
|
|
|
|
|
|
|
|
echo "Zipping $ROOT_DIR/Origin to ./data/Origin/Origin.tar.gz" |
|
|
tar -cv --use-compress-program=pigz -f "./data/Origin/Origin.tar.gz" -C "$ROOT_DIR/Origin" . |
|
|
if [[ $? -ne 0 ]]; then |
|
|
echo "Error: Failed to create tar.gz for $ROOT_DIR/Origin" |
|
|
exit 1 |
|
|
fi |
|
|
fi |
|
|
echo "All configurations have been zipped successfully." |
|
|
exit 0 |
|
|
fi |
|
|
|
|
|
SPECIFIED="false" |
|
|
|
|
|
|
|
|
if [[ -n "$METHOD" && -n "$CONFIG" ]]; then |
|
|
DIR_PATH="$ROOT_DIR/$METHOD/config$CONFIG" |
|
|
SPECIFIED="true" |
|
|
elif [[ -z "$DIR_PATH" ]]; then |
|
|
echo "Error: Either --method and --config or --dir-path must be specified." |
|
|
usage |
|
|
fi |
|
|
|
|
|
|
|
|
if [[ ! -d "$DIR_PATH" ]]; then |
|
|
echo "Error: Directory $DIR_PATH does not exist." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
|
|
|
METHOD=$(basename "$(dirname "$DIR_PATH")") |
|
|
CONFIG=$(basename "$DIR_PATH") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$SPECIFIED" == "false" ]]; then |
|
|
OUTPUT_TAR="./$CONFIG.tar.gz" |
|
|
echo "Zipping $DIR_PATH to $OUTPUT_TAR" |
|
|
tar -cv --use-compress-program=pigz -f "$OUTPUT_TAR" -C "$DIR_PATH" . |
|
|
if [[ $? -ne 0 ]]; then |
|
|
echo "Error: Failed to create tar.gz for $dir_path" |
|
|
exit 1 |
|
|
fi |
|
|
else |
|
|
|
|
|
zip_config "$METHOD" config"$CONFIG" |
|
|
fi |
|
|
|
|
|
echo "Directory zipped successfully to: $OUTPUT_TAR" |