forked from xbianonpi/xbian-package-samba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.package.sh
executable file
·48 lines (39 loc) · 1.93 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
#!/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' ] && { str=''; true; } || str='arm-linux-gnueabihf-strip'
arm-linux-gnu-strip > /dev/null 2>&1
[ $? -eq '127' ] && { str=''; true; }|| str='arm-linux-gnu-strip'
[ -z "$str" ] && { echo "please install binutils-arm-linux-gnueabihf on Debian or arm-linux-gnu-strip on CentOS"; str=''; true; }
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}')
[ $(date +%Y%m%d) = $version1 ] && version2=$((version2 + 1)) || version2=0
version1=$(date +%Y%m%d)
version=$version1-$version2
for f in $(find ./content-tpl -type f -printf "%P\n"); do
cp ./content-tpl/$f content/$f
sed -i "s%__DATE__%$version%g" ./content/$f
done
# 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}".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