-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·155 lines (132 loc) · 3.57 KB
/
build
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Function to show usage information
usage() {
echo "Usage: $0 [-v version]"
exit 1
}
# Function to log messages
log() {
local msg="$1"
echo "$(date +'%Y-%m-%d %H:%M:%S') - $msg"
}
# Parse the optional parameter
while getopts ":v:" opt; do
case ${opt} in
v )
version=$OPTARG
;;
\? )
usage
;;
esac
done
# If version is not provided, prompt the user for it
if [ -z "$version" ]; then
read -p "Enter the version number: " version
fi
# Extract the major version from the full version string
major_version=$(echo $version | cut -d '.' -f 1)
log "Starting script for version $version, major version $major_version"
# Create temp folder
temp_dir=$(mktemp -d)
if [ ! -d "$temp_dir" ]; then
log "Failed to create temporary directory"
exit 1
fi
log "Created temporary directory $temp_dir"
# Define URLs and paths
repo="phalcon/ide-stubs"
zip_url="https://github.com/${repo}/archive/refs/tags/v${version}.zip"
zip_file="${temp_dir}/v${version}.zip"
meta_src_dir="meta"
meta_dest_dir="${temp_dir}/META-INF"
jar_file="phalconautocomplete-${version}.jar"
dist_dir="$(pwd)/dist"
# Create dist folder if it doesn't exist
mkdir -p "$dist_dir"
if [ $? -ne 0 ]; then
log "Failed to create dist directory"
exit 1
fi
# Download zip from GitHub into temp folder
log "Downloading $zip_url"
curl -L -o "$zip_file" -H "Accept: application/vnd.github.v3+json" -H "User-Agent: Mozilla/5.0" "$zip_url"
if [ $? -ne 0 ]; then
log "Failed to download $zip_url"
exit 1
fi
# Verify download
if [ ! -f "$zip_file" ]; then
log "Downloaded file not found"
exit 1
fi
log "Downloaded file saved to $zip_file"
# Extract zip file and remove leading directory
log "Extracting $zip_file"
unzip "$zip_file" -d "$temp_dir"
if [ $? -ne 0 ]; then
log "Failed to unzip $zip_file"
exit 1
fi
extracted_dir=$(find "$temp_dir" -mindepth 1 -maxdepth 1 -type d)
if [ ! -d "$extracted_dir/src" ]; then
log "Source directory not found in $extracted_dir"
exit 1
fi
log "Extracted directory found at $extracted_dir"
mkdir -p "${temp_dir}/src"
mv "$extracted_dir/src"/* "${temp_dir}/src"
if [ $? -ne 0 ]; then
log "Failed to move source files"
exit 1
fi
# Create META-INF directory
mkdir -p "$meta_dest_dir"
if [ $? -ne 0 ]; then
log "Failed to create META-INF directory"
exit 1
fi
# Copy all files from meta into the temp/META-INF folder
cp -r "$meta_src_dir"/* "$meta_dest_dir"
if [ $? -ne 0 ]; then
log "Failed to copy meta files"
exit 1
fi
# Replace {version} with the specified version in META-INF/plugin.xml
sed -i '' "s/{version}/$version/g" "$meta_dest_dir/plugin.xml"
if [ $? -ne 0 ]; then
log "Failed to replace version in plugin.xml"
exit 1
fi
# Replace {majorversion} with the extracted major version in META-INF/plugin.xml
sed -i '' "s/{majorversion}/$major_version/g" "$meta_dest_dir/plugin.xml"
if [ $? -ne 0 ]; then
log "Failed to replace major version in plugin.xml"
exit 1
fi
# Navigate to the temp directory
cd "$temp_dir"
if [ $? -ne 0 ]; then
log "Failed to change directory to $temp_dir"
exit 1
fi
# Create a JAR file with the specified scheme, only including src directory files and META-INF
zip -r "$jar_file" src META-INF
if [ $? -ne 0 ]; then
log "Failed to create JAR file"
exit 1
fi
# Move the JAR file to the dist directory
mv "$jar_file" "$dist_dir"
if [ $? -ne 0 ]; then
log "Failed to move JAR file to dist directory"
exit 1
fi
# Clean up temporary files and directories
cd ..
rm -rf "$temp_dir"
if [ $? -ne 0 ]; then
log "Failed to clean up temporary files"
exit 1
fi
log "JAR file created successfully: ${dist_dir}/${jar_file}"