forked from cf-toolsuite/tanzu-genai-showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip-credentials.sh
More file actions
executable file
·45 lines (34 loc) · 1.21 KB
/
zip-credentials.sh
File metadata and controls
executable file
·45 lines (34 loc) · 1.21 KB
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
#!/bin/bash
# Check if directory argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <directory>"
exit 1
fi
# Set the top-level directory from the argument
TOP_DIR="$1"
# Check if the directory exists
if [ ! -d "$TOP_DIR" ]; then
echo "Error: Directory '$TOP_DIR' does not exist."
exit 1
fi
# Create a temporary directory to store the file structure
TEMP_DIR=$(mktemp -d)
echo "Created temporary directory: $TEMP_DIR"
# Find all .env files and copy them to the temp directory with the same structure
find "$TOP_DIR" -name "*.env" -type f | while read -r file; do
# Get the relative path from the top directory
REL_PATH=$(realpath --relative-to="$TOP_DIR" "$file")
# Create the directory structure in the temp directory
mkdir -p "$TEMP_DIR/$(dirname "$REL_PATH")"
# Copy the file to the temp directory
cp "$file" "$TEMP_DIR/$(dirname "$REL_PATH")/"
echo "Copied: $REL_PATH"
done
# Create the zip file from the temp directory
ZIP_FILE="env_files_$(date +%Y%m%d_%H%M%S).zip"
cd "$TEMP_DIR" && zip -r "../$ZIP_FILE" .
echo "Created zip file: $ZIP_FILE"
# Clean up the temp directory
rm -rf "$TEMP_DIR"
echo "Cleaned up temporary directory"
echo "Done! Zip file created: $ZIP_FILE"