This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·167 lines (126 loc) · 3.75 KB
/
build.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
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
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
##################################
# fujprog apio package builder #
##################################
# Set english language for propper pattern matching
export LC_ALL=C
# Generate toolchain-fujprog-arch-ver.tar.gz
# sources and releases: https://github.com/kost/fujprog/
# -- fujprog apio package version
VERSION=2020.10.6
# -- fujprog version to download
# -- Current v4.6
SRC_MAYOR=4
SRC_MINOR=6
SRC_VER=v$SRC_MAYOR.$SRC_MINOR
# -- Target architectures
ARCH=$1
TARGET_ARCHS="linux_x86_64 windows_amd64 windows_x86 darwin"
# -- Tools name
NAME=toolchain-fujprog
# -- Source fujprov filename (without arch)
SRC_NAME="fujprog-v"$SRC_MAYOR$SRC_MINOR"-"
# -- Source URL
SRC_URL="https://github.com/kost/fujprog/releases/download/$SRC_VER/"
# -- Store current dir
WORK_DIR=$PWD
# -- Folder for storing the downloaded packages
PACKAGES_DIR=$WORK_DIR/_packages
# -- Create the packages directory
mkdir -p "$PACKAGES_DIR"
# -- Print function
function print {
echo ""
echo "$1"
echo ""
}
# -- Check ARCH
if [[ $# -gt 1 ]]; then
echo ""
echo "Error: too many arguments"
exit 1
fi
if [[ $# -gt 1 ]]; then
echo ""
echo "Usage: bash build.sh TARGET"
echo ""
echo "Targets: $TARGET_ARCHS"
exit 1
fi
if [[ $ARCH =~ [[:space:]] || ! $TARGET_ARCHS =~ (^|[[:space:]])$ARCH([[:space:]]|$) ]]; then
echo ""
echo ">>> WRONG ARCHITECTURE \"$ARCH\""
echo "Targets: $TARGET_ARCHS"
echo ""
exit 1
fi
# -- Directory for installating the target files
PACKAGE_DIR=$PACKAGES_DIR/build_$ARCH
# -- Create the package folders
mkdir -p "$PACKAGE_DIR"/"$NAME"/bin
echo ""
echo ">>> ARCHITECTURE \"$ARCH\""
# -- Source architecture: should be the same than target
# -- architecture, but the names in the fujprog and apio
# -- are different: Convert from fujprog to apio
if [ "$ARCH" == "windows_amd64" ]; then
SRC_ARCH="win64"
EXE=".exe"
SRC_NAME=$SRC_NAME$SRC_ARCH$EXE
echo "Source filename: "$SRC_NAME
fi
if [ "$ARCH" == "windows_x86" ]; then
SRC_ARCH="win32"
EXE=".exe"
SRC_NAME=$SRC_NAME$SRC_ARCH$EXE
echo "Source filename: "$SRC_NAME
fi
if [ "$ARCH" == "linux_x86_64" ]; then
SRC_ARCH="linux-x64"
EXE=""
SRC_NAME=$SRC_NAME$SRC_ARCH$EXE
echo "Source filename: "$SRC_NAME
fi
if [ "$ARCH" == "darwin" ]; then
SRC_ARCH="mac-x64"
EXE=""
SRC_NAME=$SRC_NAME$SRC_ARCH$EXE
echo "Source filename: "$SRC_NAME
fi
echo "Download from: "$SRC_URL
# --- Enter to the package bin directory
cd "$PACKAGE_DIR"/"$NAME"/bin || exit
# --- Download the executable file, if it does not exist yet
if [[ -f fujprog$EXE ]]; then
echo "FILE Already exist"
else
wget $SRC_URL/$SRC_NAME
# -- Rename the file to fujprog
mv $SRC_NAME fujprog$EXE
# -- Give the executable permision to fujprog
chmod a+x fujprog$EXE
fi
# -- Create package script
# -- Copy templates/package-template.json
cp -r "$WORK_DIR"/build-data/templates/package-template.json "$PACKAGE_DIR"/"$NAME"/package.json
if [ "$ARCH" == "linux_x86_64" ]; then
sed -i "s/%VERSION%/\"$VERSION\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
sed -i "s/%SYSTEM%/\"linux_x86_64\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
fi
if [ "$ARCH" == "windows_amd64" ]; then
sed -i "s/%VERSION%/\"$VERSION\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
sed -i "s/%SYSTEM%/\"windows_amd64\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
fi
if [ "$ARCH" == "windows_x86" ]; then
sed -i "s/%VERSION%/\"$VERSION\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
sed -i "s/%SYSTEM%/\"windows_x86\"/;" "$PACKAGE_DIR"/"$NAME"/package.json
fi
## --Create a tar.gz package
cd "$PACKAGE_DIR/$NAME" || exit
tar -czvf "../$NAME-$ARCH-$VERSION.tar.gz" ./*
# -- Create the releases folder
mkdir -p "$WORK_DIR/releases"
## -- Copy the package to the releases folder
cd "$PACKAGE_DIR" || exit
cp "$NAME"-"$ARCH"-"$VERSION".tar.gz "$WORK_DIR"/releases
echo ""