-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.sh
112 lines (85 loc) · 2.83 KB
/
zip.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
set -e
MANIFEST="manifest.json"
MANIFEST_V3="manifest.json_v3"
EXTENSION_NAME="Dark CPI Extension"
BIN_DIR="./bin"
log_message() {
local message="$1"
local timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $message"
}
log_message "Copy readme to docs. Readme.md"
cp README.md docs/readme/README.md
log_message "----------------------"
log_message "Starting zip creation process"
# Create bin directory if not exists
if [ ! -d "$BIN_DIR" ]; then
log_message "Creating bin directory..."
mkdir -p "$BIN_DIR"
fi
# Clean bin directory
if [ -d "$BIN_DIR" ]; then
log_message "Deleting zip files from bin directory..."
rm -rf "$BIN_DIR"/*
fi
create_zip() {
local manifest_file="$1"
local version_name="$2"
local output_zip="$3"
log_message "Creating ZIP for $version_name using $manifest_file..."
name=""
version=""
# Extract name and version from manifest file
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ "$line" == *"\"name\":"* ]]; then
name=$(echo "$line" | awk -F'"' '{print $4}')
elif [[ "$line" == *"\"version\":"* ]]; then
version=$(echo "$line" | awk -F'"' '{print $4}' | tr -d ',')
fi
done < "$manifest_file"
name="${name//,/}"
name="${name// /_}"
exclusions=("./docs/*" "./node_modules" "*.sh" "./bin/*" "*.md" "./.*")
exclude_args=()
for pattern in "${exclusions[@]}"; do
exclude_args+=(-o -path "$pattern")
done
exclude_args=( "${exclude_args[@]:1}" )
rm -f "$BIN_DIR/$output_zip"
files_to_zip=$(find . -type f ! \( "${exclude_args[@]}" \))
if [ -z "$files_to_zip" ]; then
log_message "No files found to zip for $version_name. Exiting."
exit 1
fi
echo "$files_to_zip" | zip -@ "$BIN_DIR/$output_zip"
log_message "ZIP file created: $BIN_DIR/$output_zip"
}
process_manifest() {
local manifest_file="$1"
local version_name="$2"
local output_zip="$3"
if [ -f "$manifest_file" ]; then
log_message "$version_name manifest found."
create_zip "$manifest_file" "$version_name" "$output_zip"
else
log_message "$version_name manifest not found. Skipping."
fi
}
log_message "Checking manifest.json for version"
version=$(jq -r '.version' "$MANIFEST")
if [ "$version" == "null" ]; then
log_message "Could not determine the version from manifest.json. Exiting."
exit 1
fi
manifest_version=$(jq -r '.manifest_version' "$MANIFEST")
if [ "$manifest_version" == "3" ]; then
log_message "Manifest version 3 detected (Chrome)"
create_zip "$MANIFEST" "Chrome" "$EXTENSION_NAME.zip"
else
log_message "Unknown or unsupported manifest version in manifest.json!"
exit 1
fi
process_manifest "$MANIFEST_V3" "Chrome" "$EXTENSION_NAME.zip"
log_message "ZIP creation process completed."