-
Notifications
You must be signed in to change notification settings - Fork 44
/
modify-debs
executable file
·49 lines (44 loc) · 1.2 KB
/
modify-debs
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
#!/bin/bash
#
# Based on https://unix.stackexchange.com/questions/138188/easily-unpack-deb-edit-postinst-and-repack-deb
#
modify_control() {
#echo "modify_control $1"
case "$1" in
Multi-Arch*)
grep -q "^$1" control || sed -i "/^Architecture:/a $1" control
;;
esac
}
repack_control() {
cp ../$1 . && rm -rf tmp && mkdir -p tmp && cd tmp || return
t=$(ar t ../$1 | grep control | sed "s/control.tar.//")
d=$(ar t ../$1 | grep data)
case "$t" in
xz)
echo "Please note: changing control archive in package $1 from xz to gz"
ar p ../$1 control.tar.xz | tar -xJ
ar d ../$1 control.tar.xz
;;
gz)
ar p ../$1 control.tar.gz | tar -xz
;;
*)
return
;;
esac
modify_control "$2"
tar czf control.tar.gz *[!z]
ar -i $d -r ../$1 control.tar.gz
}
for deb in *.deb; do
(
mkdir -p repacked && cd repacked && rm -rf ./content && repack_control $deb "$1"
)
done
if [ -d "$2" ]; then
mv repacked/*.deb $2 && rm -rf repacked
echo "Repacked packages has been put in folder $2"
else
echo "Repacked packages are in repacked folder now"
fi