File size: 2,647 Bytes
7ffae14
 
47295d2
 
 
 
 
 
7ffae14
57d2434
7ffae14
 
 
 
 
 
 
 
 
 
 
 
47295d2
7ffae14
 
 
 
 
47295d2
7ffae14
 
 
 
47295d2
 
7ffae14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47295d2
7ffae14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47295d2
7ffae14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47295d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash

# Ensure pigz is installed
if ! command -v pigz &> /dev/null; then
    echo "Error: pigz is not installed. Please install it and try again."
    exit 1
fi

# Defined the root directory of the whole dataset
ROOT_DIR="../data_test"

# Function to display usage
usage() {
    echo "Usage: $0 [--method METHOD --config CONFIG] | [--all]"
    exit 1
}
# Function to unzip a single directory
unzip_config() {
    local method=$1
    local config=$2
    local output_path="$ROOT_DIR/$method/$config"
    local zipped_file="./data/$method/$config/$config.tar.gz"
    echo "Decompressing $zipped_file to $output_path"
    # Ensure the output directory exists
    mkdir -p "$output_path"

    # Create the tar.gz file
    echo "Decompressing $zipped_file to $output_path"
    tar -xv --use-compress-program=pigz -f "$zipped_file" --directory "$output_path"
    if [[ $? -ne 0 ]]; then
        echo "Error: Failed to decompress $zipped_file"
        exit 1
    fi
    # Confirm completion
    echo "Decompressing $zipped_file sucessfully to $output_path"
}

# Parse arguments
while [[ "$#" -gt 0 ]]; do
    case $1 in
        --help) usage ;;
        --h) usage ;;
        --all) ALL="true" ;;
        --method) METHOD="$2"; shift ;;
        --config) CONFIG="$2"; shift ;;
        *) echo "Unknown parameter: $1"; usage ;;
    esac
    shift
done

# unzipping all folders
if [[ "$ALL" == "true" ]]; then
    # Iterate through all methods and configs
    for method_dir in ./data/*; 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")
                    unzip_config "$method" "$config"
                fi
            done
        fi
    done

    if [ -e "./data/Origin/Origin.tar.gz" ]; then
        # Ensure the output directory exists
        mkdir -p "$ROOT_DIR/Origin"

        # decompress tar.gz file
        echo "Decompressing ./data/Origin/Origin.tar.gz to $ROOT_DIR/Origin"
        tar -xv --use-compress-program=pigz -f "./data/Origin/Origin.tar.gz" --directory "$ROOT_DIR/Origin"
        if [[ $? -ne 0 ]]; then
            echo "Error: Failed to decompress ./data/Origin/Origin.tar.gz"
            exit 1
        fi
    fi
    echo "All configurations have been zipped successfully."
    exit 0
fi


# Validate arguments
if [[ ! -n "$METHOD" || ! -n "$CONFIG" ]]; then
    echo "Error: Both --method and --config or --all must be specified."
    usage
fi
unzip_config "$METHOD" "config$CONFIG"