-
Notifications
You must be signed in to change notification settings - Fork 20
/
zipFiles.sh
executable file
·116 lines (85 loc) · 3.03 KB
/
zipFiles.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
113
114
115
116
#!/bin/bash
set -e
#MANIFEST_V3="manifest.json_v3"
#if [ -f "$MANIFEST_V3" ]; then
# echo "Please make sure we release only manifest v3. Current version is probably not v3."
# exit 1
#fi
MANIFEST="manifest.json"
MANIFEST_V2="manifest.json_v2"
MANIFEST_V3="manifest.json_v3"
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"
if [ ! -d "$BIN_DIR" ]; then
log_message "Creating bin directory..."
mkdir -p "$BIN_DIR"
fi
if [ -d "$BIN_DIR" ]; then
# delete all files and subdirectories in the directory
log_message "deleting zip files from bin directory..."
rm -rf "$BIN_DIR"/*
fi
create_zip() {
local manifest_file="$1"
local output_zip="$2"
log_message "Creating ZIP using $manifest_file..."
name=""
version=""
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/*" ".DS_Store" "*.json_*" "./node_modules" "./images/v[1-3]/*" "*.sh" "./bin" "./bin/*" "*.json_*" "./.*")
exclude_args=()
for pattern in "${exclusions[@]}"; do
exclude_args+=(-o -path "$pattern")
done
exclude_args=( "${exclude_args[@]:1}" )
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"
}
switch_manifest_version() {
if [ -f "$MANIFEST_V2" ]; then
log_message "Switching to manifest_v2 (Firefox)..."
mv "$MANIFEST" "$MANIFEST_V3"
mv "$MANIFEST_V2" "$MANIFEST"
elif [ -f "$MANIFEST_V3" ]; then
log_message "Switching to manifest_v3 (Chrome)..."
mv "$MANIFEST" "$MANIFEST_V2"
mv "$MANIFEST_V3" "$MANIFEST"
else
log_message "No alternate manifest files found (manifest.json_v2 or manifest.json_v3)"
exit 1
fi
}
manifest_version=$(jq -r '.manifest_version' manifest.json)
# version=$(jq -r '.version' manifest.json)
echo "Manifest version is: $manifest_version"
create_zip "$MANIFEST" "CPI_Helper_Extension_manifestv${manifest_version}.zip"
switch_manifest_version
sleep 2
manifest_version=$(jq -r '.manifest_version' manifest.json)
# version=$(jq -r '.version' manifest.json)
create_zip "$MANIFEST" "CPI_Helper_Extension_manifestv${manifest_version}.zip"
switch_manifest_version
sleep 2
log_message "Both CPI_Helper_Extension_v3.zip and CPI_Helper_Extension_v2.zip created and moved to bin."