-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_package.sh
executable file
·216 lines (176 loc) · 6.44 KB
/
make_package.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
################################################################################
# Copyright (c) 2022 ModalAI, Inc. All rights reserved.
#
# Semi-universal script for making a deb and ipk package. This is shared
# between the vast majority of VOXL-SDK packages
#
# Add the 'timestamp' argument to add a date-timestamp suffix to the deb package
# version. This is used by CI for making nightly and development builds.
#
# author: [email protected]
################################################################################
set -e # exit on error to prevent bad ipk from being generated
################################################################################
# Check arguments
################################################################################
USETIMESTAMP=false
MAKE_DEB=true
MAKE_IPK=false
print_usage(){
echo ""
echo " Package the current project into a deb or ipk package."
echo " You must run build.sh first to build the binaries"
echo " if no arguments are given it builds a deb"
echo ""
echo " Usage:"
echo " ./make_package.sh"
echo " ./make_package.sh deb"
echo " Build a DEB package"
echo ""
echo " ./make_package.sh ipk"
echo " Build an IPK package"
echo ""
echo " ./make_package.sh timestamp"
echo " ./make_package.sh deb timestamp"
echo " Build a DEB package with the current timestamp as a"
echo " suffix in both the package name and deb filename."
echo " This is used by CI for development packages."
echo ""
echo ""
}
process_argument () {
if [ "$#" -ne 1 ]; then
echo "ERROR process_argument expected 1 argument"
exit 1
fi
## convert argument to lower case for robustness
arg=$(echo "$1" | tr '[:upper:]' '[:lower:]')
case ${arg} in
"")
;;
"-t"|"timestamp"|"--timestamp")
echo "using timestamp suffix"
USETIMESTAMP=true
;;
"-d"|"deb"|"debian"|"--deb"|"--debian")
MAKE_DEB=true
;;
"-i"|"ipk"|"opkg"|"--ipk"|"--opkg")
MAKE_IPK=true
MAKE_DEB=false
;;
*)
echo "invalid option"
print_usage
exit 1
esac
}
## parse all arguments or run wizard
for var in "$@"
do
process_argument $var
done
################################################################################
# variables
################################################################################
VERSION=$(cat pkg/control/control | grep "Version" | cut -d' ' -f 2)
PACKAGE=$(cat pkg/control/control | grep "Package" | cut -d' ' -f 2)
IPK_NAME=${PACKAGE}_${VERSION}.ipk
DATA_DIR=pkg/data
CONTROL_DIR=pkg/control
IPK_DIR=pkg/IPK
DEB_DIR=pkg/DEB
echo "Package Name: " $PACKAGE
echo "version Number: " $VERSION
################################################################################
# start with a little cleanup to remove old files
################################################################################
# remove data directory where 'make install' installed to
sudo rm -rf $DATA_DIR
mkdir $DATA_DIR
# remove ipk and deb packaging folders
rm -rf $IPK_DIR
rm -rf $DEB_DIR
# remove old ipk and deb packages
rm -f *.ipk
rm -f *.deb
################################################################################
## install compiled stuff into data directory with 'make install'
## try this for all 3 possible build folders, some packages are multi-arch
## so both 32 and 64 need installing to pkg directory.
################################################################################
# make sure build succeeded
if ! [[ -d "misc_files" ]]; then
echo "run build before make_package"
exit 1
fi
################################################################################
## install standard stuff common across ModalAI projects if they exist
################################################################################
if [ -d "services" ]; then
sudo mkdir -p $DATA_DIR/etc/systemd/system/
sudo cp services/* $DATA_DIR/etc/systemd/system/
fi
if [ -d "scripts" ]; then
sudo mkdir -p $DATA_DIR/usr/bin/
sudo chmod +x scripts/*
sudo cp scripts/* $DATA_DIR/usr/bin/
fi
if [ -d "bash_completions" ]; then
sudo mkdir -p $DATA_DIR/usr/share/bash-completion/completions
sudo cp bash_completions/* $DATA_DIR/usr/share/bash-completion/completions
fi
if [ -d "misc_files" ]; then
sudo cp -R misc_files/* $DATA_DIR/
fi
if [ -d "bash_profile" ]; then
sudo mkdir -p ${DATA_DIR}/home/root/.profile.d/
sudo cp -R bash_profile/* ${DATA_DIR}/home/root/.profile.d/
fi
################################################################################
# make an IPK
################################################################################
if $MAKE_IPK; then
echo "starting building IPK package"
## make a folder dedicated to IPK building and make the required version file
mkdir $IPK_DIR
echo "2.0" > $IPK_DIR/debian-binary
## add tar archives of data and control for the IPK package
cd $CONTROL_DIR/
tar --create --gzip -f ../../$IPK_DIR/control.tar.gz *
cd ../../
cd $DATA_DIR/
tar --create --gzip -f ../../$IPK_DIR/data.tar.gz *
cd ../../
## update version with timestamp if enabled
if $USETIMESTAMP; then
dts=$(date +"%Y%m%d%H%M")
VERSION="${VERSION}_${dts}"
IPK_NAME=${PACKAGE}_${VERSION}.ipk
echo "new version with timestamp: $VERSION"
fi
## use ar to make the final .ipk and place it in the repository root
ar -r $IPK_NAME $IPK_DIR/control.tar.gz $IPK_DIR/data.tar.gz $IPK_DIR/debian-binary
fi
################################################################################
# make a DEB package
################################################################################
if $MAKE_DEB; then
echo "starting building Debian Package"
## make a folder dedicated to IPK building and copy the requires debian-binary file in
mkdir $DEB_DIR
## copy the control stuff in
cp -rf $CONTROL_DIR/ $DEB_DIR/DEBIAN
cp -rf $DATA_DIR/* $DEB_DIR
## update version with timestamp if enabled
if $USETIMESTAMP; then
dts=$(date +"%Y%m%d%H%M")
sed -E -i "s/Version.*/&-$dts/" $DEB_DIR/DEBIAN/control
VERSION="${VERSION}-${dts}"
echo "new version with timestamp: $VERSION"
fi
DEB_NAME=${PACKAGE}_${VERSION}_arm64.deb
dpkg-deb --build ${DEB_DIR} ${DEB_NAME}
fi
echo "DONE"