forked from xuejian1354/openwrt_cc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgbuild.sh
executable file
·184 lines (150 loc) · 5.86 KB
/
pkgbuild.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
#!/bin/bash
# ctc-pkg-build -- construct a ChinaTelecom recognized tar package from the .ipk
# Ali.Dong <[email protected]>
# based on a script by Steve Redler IV, [email protected] 5-21-2001
# 2016-06-08 [email protected]
# Updated to work on Familiar Pre0.7rc1, with busybox tar.
# Note it Requires: binutils-ar (since the busybox ar can't create)
# For UID debugging it needs a better "find".
set -e
BASEDIR=$(pwd)
version=1.0
FIND="$(which find)"
FIND="${FIND:-$(which gfind)}"
TAR="${TAR:-$(which tar)}"
ipkg_extract_value() {
sed -e "s/^[^:]*:[[:space:]]*//"
}
required_field() {
field=$1
target_dir=$2
grep "^$field:" < $target_dir/control | ipkg_extract_value
}
# ./generate_app_json [control_dir]
generate_app_json() {
local control_dir=$1
local vendor_name=$2
if [ "$control_dir" = "." -o "$control_dir" = "./" ] ; then
control_dir=$PWD
fi
# echo "generate_app_json: $control_dir"
pkg=`required_field Package $control_dir`
version=`required_field Version $control_dir | sed 's/Version://; s/^.://g;'`
arch=`required_field Architecture $control_dir`
appsign=com.chinatelecom.all.smartgateway.${pkg}_${arch}
desp=`required_field Description $control_dir`
author=`required_field Maintainer $control_dir`
rom=`required_field Installed-Size $control_dir`
ram=`required_field MemoryLimit $control_dir`
# Parse the path to colorful icon
if [ "${pkg}" == "transvpnv3" ]; then
pathstr="package/upointech/transvpnv3/icon/ispeed64black.png"
elif [ "${pkg}" == "nets" ]; then
pathstr="package/xbsafe/nets/icon/speed.png"
fi
if [ ${pathstr:0:1} = '/' ]; then
col_icon=$pathstr
else
col_icon=${BASEDIR}/$pathstr
fi
col_file=${col_icon##*/}
# Parse the path to black-and-white icon
if [ "${pkg}" == "transvpnv3" ]; then
pathstr="package/upointech/transvpnv3/icon/ispeed64.png"
elif [ "${pkg}" == "nets" ]; then
pathstr="package/xbsafe/nets/icon/speed1.png"
fi
if [ ${pathstr:0:1} = '/' ]; then
mono_icon=$pathstr
else
mono_icon=${BASEDIR}/$pathstr
fi
mono_file=${mono_icon##*/}
if [ ! -f $control_dir/control ]; then
echo "***Error: Control file $control_dir/control is not exist."
return 1
fi
# Now generate the app.json file
echo "{" > $control_dir/app.json
echo -e "\t\"PlatformID\": \"OPKG\"," >> $control_dir/app.json
echo -e "\t\"appsign\": \"${appsign}${vendor_name}\"," >> $control_dir/app.json
if [ "${pkg}" == "transvpnv3" ]; then
echo -e "\t\"appname\": \"游戏加速器\"," >> $control_dir/app.json
elif [ "${pkg}" == "nets" ]; then
echo -e "\t\"appname\": \"插件测速\"," >> $control_dir/app.json
fi
echo -e "\t\"version\": \"$version\"," >> $control_dir/app.json
echo -e "\t\"dep_version\": \"\"," >> $control_dir/app.json
echo -e "\t\"description\": \"$desp\"," >> $control_dir/app.json
echo -e "\t\"author\": \"$author\"," >> $control_dir/app.json
echo -e "\t\"URL\": \"www.example.com\"," >> $control_dir/app.json
echo -e "\t\"email\": \"[email protected]\"," >> $control_dir/app.json
echo -e "\t\"icon\": \"$col_file\"," >> $control_dir/app.json
echo -e "\t\"icon1\": \"$mono_file\"," >> $control_dir/app.json
echo -e "\t\"rom_use\": \"$rom\"," >> $control_dir/app.json
echo -e "\t\"ram_use\": \"$ram\"," >> $control_dir/app.json
echo -e "\t\"install_file\": \"install/${appsign}.ipk\"," >> $control_dir/app.json
echo -e "\t\"thirdparty\": \"\"," >> $control_dir/app.json
echo -e "\t\"package_name\": \"\"," >> $control_dir/app.json
echo -e "\t\"activity_name\": \"\"," >> $control_dir/app.json
echo -e "\t\"isdefaultapp\": \"0\"," >> $control_dir/app.json
echo -e "\t\"configtype\": \"0\"," >> $control_dir/app.json
echo -e "\t\"configurl\": \"\"," >> $control_dir/app.json
echo -e "\t\"configurl_mobile\": \"\"" >> $control_dir/app.json
echo "}" >> $control_dir/app.json
return 0
}
###
# ctc-pkg-build "main"
###
ogargs="--owner=0 --group=0"
usage="Usage: $0 <ipk_path> [vendor]"
# continue on to process additional arguments
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
echo $usage >&2
exit 1
fi
if [ ! -f $1 ]; then
echo "*** Error: ipk file $1 does not exist." >&2
exit 1
fi
# parse the path string
pathstr=$1
if [ ${pathstr:0:1} = '/' ]; then
ipk_name=$1
else
ipk_name=${BASEDIR}/$1
fi
#Parse the vendor, this is a optional parameter
if [ $# -eq 2 ]; then
vendor=_$2
else
vendor=""
fi
dest_dir=${ipk_name%/*}
tmp_dir=$dest_dir/CTC_PKG_BUILD.$$
mkdir $tmp_dir
mkdir $tmp_dir/tmp
( $TAR -zxf $ipk_name -C $tmp_dir/tmp && $TAR -zxf $tmp_dir/tmp/control.tar.gz -C $tmp_dir/tmp )
if [ ! -f $tmp_dir/tmp/control ]; then
echo "*** Error: No control file found in $tmp_dir." >&2
rm -rf $tmp_dir
exit 1
fi
cp $tmp_dir/tmp/control $tmp_dir
rm -rf $tmp_dir/tmp
if ! generate_app_json $tmp_dir $vendor; then
echo >&2
echo "ctc-ipk-build: Please fix the above errors and try again." >&2
rm -rf $tmp_dir
exit 1
fi
rm -f $tmp_dir/control
ctc_ipk_str=com.chinatelecom.all.smartgateway.${pkg}_${arch}
#echo $ctc_ipk_str
ctc_tar_file=$dest_dir/${ctc_ipk_str}.tar.gz
rm -f $ctc_tar_file
( cd $tmp_dir && mkdir install && cp $ipk_name install/${ctc_ipk_str}.ipk && cp $col_icon ./ && cp $mono_icon ./ && $TAR $ogargs --format=gnu -czf ${ctc_tar_file} ./app.json ./install ./${col_file} ./${mono_file} )
rm -rf $tmp_dir
echo "Generated CTC package ${ctc_ipk_str}.tar.gz to $dest_dir"
#find -L bin/ -name *.ipk | grep "packages/base" | grep -v "${pkg}" | xargs -i rm {} >/dev/null