-
Notifications
You must be signed in to change notification settings - Fork 5
/
gen.package.sh
executable file
·53 lines (45 loc) · 2.05 KB
/
gen.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
#!/bin/sh
rm_size() {
cat ./content/DEBIAN/control | grep -v "Installed-Size:" > ./content/DEBIAN/control.new
mv ./content/DEBIAN/control.new ./content/DEBIAN/control
rm -f ./size.txt
}
str='strip'
strargs='--strip-unneeded'
tot=0
if ! dpkg-architecture -iarmhf; then
arm-linux-gnueabihf-strip > /dev/null 2>&1
[ $? -eq '127' ] && { echo "please install binutils-arm-linux-gnueabihf"; str=''; true; } || str='arm-linux-gnueabihf-strip'
fi
package=$(cat ./content/DEBIAN/control | grep Package | awk '{print $2}')
version1=$(cat ./content/DEBIAN/control | grep Version | awk '{print $2}' | awk -F'-' '{print $1}')
version2=$(cat ./content/DEBIAN/control | grep Version | awk '{print $2}' | awk -F'-' '{print $2}')
arch="_$(grep -m1 'Architecture\:' ./content-tpl/DEBIAN/control | awk -F':' '{print $2}' | tr -d ' ')"
[ $(date +%Y%m%d) = $version1 ] && version2="-$((version2 + 1))" || version2=''
version1=$(date +%Y%m%d)
version=$version1$version2
rm -rf content/etc
rsync -a -f"+ */" -f"- *" content-tpl/. content/
(
cd ./content-tpl
for f in $(find ./ -type f -printf "%P\n"); do
cp -d --parents $f ../content/
done
for f in $(find ./ -type l -printf "%P\n"); do
cp -d --parents $f ../content/
done
)
sed -i "s%__DATE__%$version%g" content/DEBIAN/control
# calculate size dynamically. remove first any entry, then add the actual
rm_size
cd content
[ -d ./tmp ] && mv ./tmp ..
find ./ -type f -print0 | xargs -0 -L1 printf "%s\n" | while read f; do [ -z "$str" ] || $str $strargs "$f" 2>/dev/null; s=$(stat -c %s "$f"); tot=$((tot + (s/1024)+1)); echo $tot > ../size.txt; done
printf "Installed-Size: %u\n" $(cat ../size.txt) >> ./DEBIAN/control
find ./ -type f ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' -printf '%P\0' | sort -z| xargs --null md5sum > DEBIAN/md5sums
cd ..
fakeroot dpkg-deb -b ./content "${package}-${version}${arch}".deb
[ -d ./tmp ] && mv ./tmp ./content
# remove the size again, because on different filesystems du will return different size
rm_size
#rm -f ./content/etc/default/*.default