1 |
rakinar2 |
575 |
#!/bin/bash |
2 |
|
|
|
3 |
|
|
extensions=$(find . -maxdepth 1 -type d -not -name . -not -name .git -not -name .extbuild -not -name .extbuilds) |
4 |
|
|
failed_builds=() |
5 |
|
|
extbuilds_final_dir=$(pwd)/.extbuilds |
6 |
|
|
|
7 |
|
|
for extension in $extensions; do |
8 |
|
|
name=$(basename $extension) |
9 |
|
|
echo "BUILD $name" |
10 |
|
|
|
11 |
|
|
cd $extension |
12 |
|
|
echo "PWD $(pwd)" |
13 |
|
|
|
14 |
|
|
if [ ! -f extension.json ]; then |
15 |
|
|
echo "No metadata found for extension: $name" |
16 |
|
|
failed_builds+=($name) |
17 |
|
|
continue |
18 |
|
|
fi |
19 |
|
|
|
20 |
|
|
metadata=$(cat extension.json) |
21 |
|
|
main_directory=$(echo $metadata | jq -r '.main_directory') |
22 |
|
|
build_command=$(echo $metadata | jq -r '.build_command') |
23 |
|
|
resources=$(echo $metadata | jq -r '.resources') |
24 |
|
|
version=$(cat package.json | jq -r '.version') |
25 |
|
|
|
26 |
|
|
npm install -D |
27 |
|
|
|
28 |
|
|
if [ $? -eq 0 ]; then |
29 |
|
|
if [ -z "$build_command" ] || test "$build_command" = "null"; then |
30 |
|
|
echo "NOBUILD $name" |
31 |
|
|
else |
32 |
|
|
eval $build_command |
33 |
|
|
|
34 |
|
|
if [ $? -ne 0 ]; then |
35 |
|
|
echo "FAIL $name" |
36 |
|
|
failed_builds+=($name) |
37 |
|
|
continue |
38 |
|
|
fi |
39 |
|
|
fi |
40 |
|
|
fi |
41 |
|
|
|
42 |
|
|
if [ $? -ne 0 ]; then |
43 |
|
|
echo "FAIL $name" |
44 |
|
|
failed_builds+=($name) |
45 |
|
|
else |
46 |
|
|
echo "PACKAGE $name" |
47 |
|
|
root="${name}-${version}" |
48 |
|
|
extbuild_dir=".extbuild/$root" |
49 |
|
|
|
50 |
|
|
echo "MKDIR $extbuild_dir" |
51 |
|
|
mkdir -p $extbuild_dir/$main_directory |
52 |
|
|
echo "COPY $main_directory/* $extbuild_dir/$main_directory" |
53 |
|
|
cp -r $main_directory/* $extbuild_dir/$main_directory |
54 |
|
|
echo "COPY package.json $extbuild_dir" |
55 |
|
|
cp package.json $extbuild_dir |
56 |
|
|
echo "COPY extension.json $extbuild_dir" |
57 |
|
|
cp extension.json $extbuild_dir |
58 |
|
|
echo "COPY $resources/ $extbuild_dir" |
59 |
|
|
cp -r $resources/ $extbuild_dir |
60 |
|
|
|
61 |
|
|
if [ -f README.md ]; then |
62 |
|
|
echo "COPY README.md $extbuild_dir" |
63 |
|
|
cp README.md $extbuild_dir |
64 |
|
|
fi |
65 |
|
|
|
66 |
|
|
if [ -f README ]; then |
67 |
|
|
echo "COPY README $extbuild_dir" |
68 |
|
|
cp README $extbuild_dir |
69 |
|
|
fi |
70 |
|
|
|
71 |
|
|
if [ -f LICENSE ]; then |
72 |
|
|
echo "COPY LICENSE $extbuild_dir" |
73 |
|
|
cp LICENSE $extbuild_dir |
74 |
|
|
fi |
75 |
|
|
|
76 |
|
|
echo "TAR $root.tar.gz" |
77 |
|
|
cd .extbuild |
78 |
|
|
tar -czvf $root.tar.gz $root |
79 |
|
|
mv $root.tar.gz .. |
80 |
|
|
cd .. |
81 |
|
|
|
82 |
|
|
if [ $? -ne 0 ]; then |
83 |
|
|
echo "FAIL $name" |
84 |
|
|
failed_builds+=($name) |
85 |
|
|
else |
86 |
|
|
echo "SUCCESS $name" |
87 |
|
|
mkdir -p "$extbuilds_final_dir/$name" |
88 |
|
|
count=1 |
89 |
|
|
|
90 |
|
|
if [ -e "$extbuilds_final_dir/$name/$root.tar.gz" ]; then |
91 |
|
|
while [ -e "$extbuilds_final_dir/$name/$root-$count.tar.gz" ]; do |
92 |
|
|
((count++)) |
93 |
|
|
done |
94 |
|
|
|
95 |
|
|
prevcount=$((count - 1)) |
96 |
|
|
|
97 |
|
|
sum1=$(tarsum "$root.tar.gz") |
98 |
|
|
sum2=$(tarsum "$extbuilds_final_dir/$name/$root-$prevcount.tar.gz") |
99 |
|
|
|
100 |
|
|
if [ -e "$extbuilds_final_dir/$name/$root-$prevcount.tar.gz" ] && test "$sum1" = "$sum2"; then |
101 |
|
|
((count--)) |
102 |
|
|
fi |
103 |
|
|
|
104 |
|
|
sum2=$(tarsum "$extbuilds_final_dir/$name/$root.tar.gz") |
105 |
|
|
|
106 |
|
|
if [ $count -eq 1 ] && test "$sum1" = "$sum2"; then |
107 |
|
|
count="" |
108 |
|
|
else |
109 |
|
|
count="-$count" |
110 |
|
|
fi |
111 |
|
|
else |
112 |
|
|
count="" |
113 |
|
|
fi |
114 |
|
|
|
115 |
|
|
if [ ! -e "$extbuilds_final_dir/$name/$root$count.tar.gz" ]; then |
116 |
|
|
mv "$root.tar.gz" "$extbuilds_final_dir/$name/$root$count.tar.gz" |
117 |
|
|
echo "SAVE $root$count.tar.gz" |
118 |
|
|
else |
119 |
|
|
echo "SKIP $root$count.tar.gz" |
120 |
|
|
rm "$root.tar.gz" |
121 |
|
|
fi |
122 |
|
|
fi |
123 |
|
|
fi |
124 |
|
|
|
125 |
|
|
cd .. |
126 |
|
|
done |
127 |
|
|
|
128 |
|
|
if [ ${#failed_builds[@]} -eq 0 ]; then |
129 |
|
|
echo "All extensions built successfully" |
130 |
|
|
else |
131 |
|
|
echo "Failed to build extensions: ${failed_builds[@]}" |
132 |
|
|
exit 1 |
133 |
|
|
fi |