-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeb_repack.sh
executable file
·95 lines (80 loc) · 1.8 KB
/
deb_repack.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
#!/usr/bin/env bash
declare file_name
working_dir=tmp/
infile=$1
current_dir=$(pwd)
out_dir="out"
get_out_filename() {
file_name="${infile::-4}_repacked.deb"
}
clean_up() {
cd $current_dir
# rm -rf $out_dir/$get_out_filename
echo "Cleaning up..."
rm -rf $working_dir
}
if [ "$#" -ne 1 ]; then
echo "Usage: $0 deb_package_name.deb"
exit -2
fi
echo "Checking file extension..."
if [[ $infile != *.deb ]]
then
echo "Unsupported file type"
exit -1
else
get_out_filename
fi
echo "Creating output directory..."
if ! mkdir -p $out_dir
then
echo "Cannot create output directory"
exit -1
fi
out_dir=$current_dir/$out_dir
echo "Creating temp directory..."
if ! mkdir -p $working_dir
then
echo "Cannot create temp directory"
exit -1
fi
echo "Extracting deb package..."
if ! ar vx --output=$working_dir $infile; then
echo "Failed to extract deb package"
clean_up
exit -1
fi
echo "Extracting control.tar.zst..."
if ! zstd -d $working_dir\control.tar.zst -o $working_dir\control.tar; then
echo "Failed to extract control.tar.zst package"
clean_up
exit -1
fi
echo "Extracting data.tar.zst..."
if ! zstd -d $working_dir\data.tar.zst -o $working_dir\data.tar; then
echo "Failed to extract data.tar.zst package"
clean_up
exit -1
fi
echo "Compressing control.tar.xz..."
cd $working_dir
if ! xz control.tar; then
echo "Failed to compress control.tar package"
clean_up
exit -1
fi
echo "Compressing data.tar.xz..."
if ! xz data.tar; then
echo "Failed to compress data.tar package"
clean_up
exit -1
fi
cd $current_dir
echo "Creating new deb package..."
if ! ar -rc $out_dir/$file_name $working_dir\debian-binary $working_dir\control.tar.xz $working_dir\data.tar.xz; then
echo "Failed to create deb package"
clean_up
exit -1
fi
clean_up
echo "Done. ${infile} repacked as ${out_dir}/${file_name}"