-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinitdb-prepare.sh
executable file
·56 lines (44 loc) · 1.64 KB
/
initdb-prepare.sh
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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Log function for better readability and maintenance
log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $*"
}
# Error handler to capture any issues and exit gracefully
error_exit() {
log "ERROR: $1"
exit 1
}
# Validate that DATASET is set
[ -z "$DATASET" ] && error_exit "DATASET environment variable is not set."
# Define paths relative to the script's location
COMMON_DIR="$SCRIPT_DIR/common"
BUILD_DIR="$SCRIPT_DIR/build"
DATASET_DIR="$SCRIPT_DIR/$DATASET"
# Ensure build directories exist
log "Ensuring build directories exist..."
mkdir -p "$BUILD_DIR/postgres" "$BUILD_DIR/mongodb" || error_exit "Failed to create build directories."
# Function to copy files from source to destination
copy_files() {
local src=$1
local dest=$2
local label=$3
if [ -d "$src" ]; then
log "Copying $label files from $src to $dest..."
cp -R "$src"/* "$dest" || error_exit "Failed to copy files from $src to $dest."
else
log "WARNING: Directory $src not found. Skipping $label files."
fi
}
# Copy global scripts into build directory
log "Processing global scripts..."
copy_files "$COMMON_DIR/postgres" "$BUILD_DIR/postgres" "Postgres"
copy_files "$COMMON_DIR/mongodb" "$BUILD_DIR/mongodb" "MongoDB"
# Copy dataset-specific scripts into build directory
log "Processing dataset ($DATASET) scripts..."
copy_files "$DATASET_DIR/postgres" "$BUILD_DIR/postgres" "Postgres"
copy_files "$DATASET_DIR/mongodb" "$BUILD_DIR/mongodb" "MongoDB"
log "File copying completed successfully."