1
1
#! /bin/sh
2
+ # shellcheck disable=SC2046,SC2034
2
3
3
4
# mk-owrt-package.sh
4
5
@@ -82,29 +83,29 @@ export _OWRTFW initsys=procd curr_sh_g="/bin/sh"
82
83
PATH_orig=" $PATH "
83
84
84
85
# ## Checks
85
- [ ! -d " $owrt_dist_dir " ] && die " openwrt distribution dir '$owrt_dist_dir ' doesn't exist."
86
- [ ! -f " $owrt_dist_dir /feeds.conf.default" ] && die " feeds.conf.default not found in '$owrt_dist_dir '."
86
+ [ ! -d " $owrt_dist_dir " ] && die " *** Openwrt distribution dir '$owrt_dist_dir ' doesn't exist. *** "
87
+ [ ! -f " $owrt_dist_dir /feeds.conf.default" ] && die " *** feeds.conf.default not found in '$owrt_dist_dir '. *** "
87
88
88
89
case " $1 " in
89
90
3|4) FW_ver=" $1 " ; buildsavail=" build is available" ; ipksavail=" ipk is available" ;;
90
91
' ' |" 3 4" |" 4 3" ) FW_ver=" 3 4" ; buildsavail=" builds are available" ; ipksavail=" ipk's are available" ;;
91
- * ) printf ' %s\n' " Invalid OpenWrt firewall version '$1 '. Use '3' or '4' or no argument to build both." ; exit 1
92
+ * ) printf ' %s\n' " *** Invalid OpenWrt firewall version '$1 '. Use '3' or '4' or no argument to build both. *** " ; exit 1
92
93
esac
93
94
94
95
95
96
# ## Main
96
97
97
98
unset build_dirs ipk_paths
98
99
for _OWRTFW in $FW_ver ; do
99
- unset ipt depends conflicts
100
+ unset ipt nft depends conflicts
100
101
case " $_OWRTFW " in
101
- 3) export _fw_backend=ipt; ipt=" -iptables" ; depends=" +ipset +iptables +kmod-ipt-ipset" ; conflicts=firewall4 ;;
102
- 4) export _fw_backend=nft; depends=" +firewall4 +nftables" ;;
103
- * ) echo " Specify OpenWrt firewall version!" ; exit 1
102
+ 3) export _fw_backend=ipt; ipt=" -iptables" ; depends=" +ipset +iptables +kmod-ipt-ipset" ; conflicts=' CONFLICTS:= firewall4' ;;
103
+ 4) export _fw_backend=nft; nft= " -nftables " ; depends=" +firewall4 +nftables" ;;
104
+ * ) echo " *** Specify OpenWrt firewall version! *** " ; exit 1
104
105
esac
105
106
owrt_dist_src_dir=" $owrt_dist_dir /my_packages/net/network/$p_name$ipt "
106
107
107
- build_dir=" $script_dir /owrt-build$ipt "
108
+ build_dir=" $script_dir /owrt-build$ipt$nft "
108
109
files_dir=" $build_dir /files"
109
110
110
111
# Prepare geoip-shell for OpenWrt
@@ -115,32 +116,37 @@ for _OWRTFW in $FW_ver; do
115
116
116
117
mkdir -p " $files_dir$install_dir " &&
117
118
mkdir -p " $files_dir$lib_dir " &&
118
- mkdir -p " $files_dir /etc/init.d" || die " Failed to create directories for $p_name build."
119
+ mkdir -p " $files_dir /etc/init.d" || die " *** Failed to create directories for $p_name build. *** "
119
120
120
121
121
122
export PATH=" /usr/sbin:/usr/bin:/sbin:/bin" inst_root_gs=" $build_dir /files"
122
- printf ' %s\n' " running '$src_dir /$p_name -install.sh'"
123
- sh " $src_dir /$p_name -install.sh" || die " Failed to run the -install script or it reported an error."
123
+ printf ' %s\n' " *** Running '$src_dir /$p_name -install.sh'... *** "
124
+ sh " $src_dir /$p_name -install.sh" || die " *** Failed to run the -install script or it reported an error. *** "
124
125
echo
125
126
export PATH=" $HOME /openwrt/staging_dir/host/bin:$PATH_orig "
126
127
build_dirs=" $build_dirs$build_dir$_nl "
127
128
129
+ cp " $script_dir /$p_name -owrt-uninstall.sh" " ${files_dir}${lib_dir} " ||
130
+ die " *** Failed to copy '$script_dir /$p_name -owrt-uninstall.sh' to '${files_dir}${lib_dir} '. ***"
128
131
129
- rm -f " $files_dir /usr/bin/$p_name -uninstall.sh"
130
- cp " $script_dir /$p_name -owrt-uninstall.sh" " $files_dir /usr/bin" ||
131
- die " Failed to copy '$script_dir /$p_name -owrt-uninstall.sh' to '$files_dir /usr/bin'."
132
-
132
+ echo " *** Sanitizing the build... ***"
133
+ rm -f " ${files_dir}${install_dir} /${p_name} -uninstall.sh"
133
134
[ " $_OWRTFW " = 3 ] && rm -f " $files_dir /usr/lib/$p_name -" * nft.sh
134
135
135
- cd " $files_dir " || die " Failed to cd into '$files_dir '"
136
+ # remove debug stuff
137
+ sed -Ei ' s/(\[[[:blank:]]*"\$debugmode"[[:blank:]]*\][[:blank:]]*&&[[:blank:]]*)*debugprint.*"(;){0,1}//g;s/^[[:blank:]]*(setdebug|debugentermsg|debugexitmsg)$//g;s/ debugmode_arg=1//g' \
138
+ $( find -- " $build_dir " /* -print | grep ' .sh$' )
139
+ sed -i -n -e /" #@" /\{ :1 -e n\; /" #@" /\{ :2 -e n\; p\; b2 -e \}\; b1 -e \}\; p " ${files_dir}${lib_dir} /$p_name -lib-common.sh" || exit 1
140
+
141
+ cd " $files_dir " || die " *** Failed to cd into '$files_dir ' ***"
136
142
137
- printf ' %s\n' " Creating '$build_dir /Makefile'..."
143
+ printf ' %s\n' " *** Creating '$build_dir /Makefile'... *** "
138
144
{
139
145
awk ' {gsub(/\$p_name_c/,P); gsub(/\$p_name/,p); gsub(/\$install_dir/,i); sub(/\$curr_ver/,v); sub(/\$_OWRTFW/,o); \
140
146
sub(/\$pkg_ver/,r); sub(/\$depends/,d); sub(/\$conflicts/,c); gsub(/\$_fw_backend/,f); \
141
- gsub(/\$ipt/,I); gsub(/\$_lib/,l)}1' \
147
+ gsub(/\$ipt/,I); gsub(/\$_lib/,l); gsub(/\$lib_dir/,L) }1' \
142
148
p=" $p_name " P=" $p_name_c " v=" $curr_ver " r=" $pkg_ver " o=" $_OWRTFW " i=" $install_dir " l=" $lib_dir /$p_name -lib" \
143
- f=" $_fw_backend " I=" $ipt " d=" $depends " c=" $conflicts " " $script_dir /makefile.tpl"
149
+ L= " $lib_dir " f=" $_fw_backend " I=" $ipt " d=" $depends " c=" $conflicts " " $script_dir /makefile.tpl"
144
150
145
151
printf ' \n%s\n' " define Package/$p_name$ipt /install"
146
152
@@ -151,37 +157,37 @@ for _OWRTFW in $FW_ver; do
151
157
$0~t {print "\t$(INSTALL_BIN) ./files/" $0 " $(1)" s n} \
152
158
$0~b {print "\t$(INSTALL_CONF) ./files/" $0 " $(1)" s l}' \
153
159
c=" ${conf_dir# " /" } " i=" ${install_dir# " /" } " n=" ${init_dir# " /" } " l=" ${lib_dir# " /" } " s=" /" \
154
- f=" ${conf_dir# " /" } /" a=" ${install_dir# " /" } /" t=" ${init_dir# " /" } /" b=" ${lib_dir# " /" } /" s= " / "
160
+ f=" ${conf_dir# " /" } /" a=" ${install_dir# " /" } /" t=" ${init_dir# " /" } /" b=" ${lib_dir# " /" } /"
155
161
156
162
printf ' \n%s\n\n%s\n\n' " endef" " \$ (eval \$ (call BuildPackage,$p_name$ipt ))"
157
163
} > " $build_dir /Makefile"
158
164
echo
159
165
160
166
# ## Configure owrt feeds
161
- printf ' \n%s\n' " Preparing owrt feeds..."
162
- cd " $owrt_dist_dir " || die " failed to cd into '$owrt_dist_dir '"
167
+ printf ' \n%s\n' " *** Preparing owrt feeds... *** "
168
+ cd " $owrt_dist_dir " || die " *** Failed to cd into '$owrt_dist_dir ' *** "
163
169
164
- mkdir -p " $owrt_dist_src_dir " || die " failed to make dir '$owrt_dist_src_dir '"
170
+ mkdir -p " $owrt_dist_src_dir " || die " *** Failed to make dir '$owrt_dist_src_dir ' *** "
165
171
166
- printf ' %s\n' " copying $p_name$ipt build into '$owrt_dist_src_dir '..."
167
- cp -r " $build_dir " /* " $owrt_dist_src_dir " || die " copy failed"
172
+ printf ' %s\n' " *** Copying $p_name$ipt build into '$owrt_dist_src_dir '... *** "
173
+ cp -r " $build_dir " /* " $owrt_dist_src_dir " || die " *** Copy failed *** "
168
174
echo
169
175
170
- curr_feeds=" $( grep -v " my_packages" " $owrt_dist_dir /feeds.conf.default" ) " || die " failed to cat '$owrt_dist_dir /feeds.conf.default'"
171
- echo " Prepending entry 'src-link local $owrt_dist_dir /my_packages' to '$owrt_dist_dir /feeds.conf.default'..."
176
+ curr_feeds=" $( grep -v " my_packages" " $owrt_dist_dir /feeds.conf.default" ) " ||
177
+ die " *** Failed to cat '$owrt_dist_dir /feeds.conf.default' ***"
178
+ echo " *** Prepending entry 'src-link local $owrt_dist_dir /my_packages' to '$owrt_dist_dir /feeds.conf.default'... ***"
172
179
printf ' %s\n%s\n' " src-link local $owrt_dist_dir /my_packages" " $curr_feeds " > " $owrt_dist_dir /feeds.conf.default" ||
173
- die " failed to add 'my_packages' src dir to '$owrt_dist_dir /feeds.conf.default"
180
+ die " *** Failed to add 'my_packages' src dir to '$owrt_dist_dir /feeds.conf.default *** "
174
181
175
- printf ' \n%s\n' " Updating Openwrt feeds..."
176
- ./scripts/feeds update -a || die " Failed to update owrt feeds."
177
- echo " Installing feed '$p_name$ipt '..."
178
- ./scripts/feeds install $p_name$ipt || die " Failed to add $p_name$ipt to the make config."
182
+ printf ' \n%s\n' " *** Updating Openwrt feeds... *** "
183
+ ./scripts/feeds update -a || die " *** Failed to update owrt feeds."
184
+ echo " *** Installing feed '$p_name$ipt '... *** "
185
+ ./scripts/feeds install $p_name$ipt || die " *** Failed to add $p_name$ipt to the make config."
179
186
180
187
grep " $p_name$ipt =m" .config 1> /dev/null || {
181
- printf ' \n%s\n' " I will now run 'make menuconfig'. Go to Image Configuration ---> Separate feed repositories ---> Check [*] Enable local feeds "
182
- echo " Then Go to Network --->, scroll down till you see '$p_name$ipt ' and make sure '$p_name$ipt ' is checked with <M>."
188
+ printf ' \n%s\n' " *** I will now run 'make menuconfig'. *** "
189
+ echo " Go to Network --->, scroll down till you see '$p_name$ipt ' and make sure '$p_name$ipt ' is checked with <M>."
183
190
echo " Then exit and save."
184
-
185
191
echo " Press Enter when ready."
186
192
read -r dummy
187
193
make menuconfig
@@ -190,21 +196,21 @@ for _OWRTFW in $FW_ver; do
190
196
191
197
# ## make new ipk
192
198
printf ' \n%s\n\n' " *** Making ipk for OpenWrt with firewall$_OWRTFW ... ***"
193
- echo " running : make -j4 package/$p_name$ipt /clean"
199
+ echo " *** Running : make -j4 package/$p_name$ipt /clean *** "
194
200
make -j4 " package/$p_name$ipt /clean"
195
- echo " running : make -j4 package/$p_name$ipt /compile"
201
+ echo " *** Running : make -j4 package/$p_name$ipt /compile *** "
196
202
make -j4 " package/$p_name$ipt /compile"
197
203
198
204
ipk_path=" $( find . -name " ${p_name}${ipt} _$curr_ver *.ipk" -exec echo {} \; | head -n1) "
199
- [ ! " $ipk_path " ] || [ ! -f " $ipk_path " ] && die " Can not find file '$ipk_path '"
205
+ [ ! " $ipk_path " ] || [ ! -f " $ipk_path " ] && die " *** Can not find file '$ipk_path ' *** "
200
206
201
207
new_ipk_path=" $build_dir /$p_name ${ipt} _$curr_ver -$pkg_ver .ipk"
202
208
mv " $ipk_path " " $new_ipk_path " && ipk_paths=" $ipk_paths$new_ipk_path$_nl " ||
203
- printf ' %s\n' " Failed to move '$ipk_path ' to '$new_ipk_path '" >&2
209
+ printf ' %s\n' " *** Failed to move '$ipk_path ' to '$new_ipk_path ' *** " >&2
204
210
done
205
211
206
212
[ " ${build_dirs% " $_nl " } " ] && {
207
- printf ' \n%s\n%s\n' " New $buildsavail here:" " ${build_dirs% " $_nl " } "
213
+ printf ' \n%s\n%s\n' " *** New $buildsavail here:" " ${build_dirs% " $_nl " } "
208
214
echo
209
- [ " ${ipk_paths% " $_nl " } " ] && printf ' %s\n%s\n' " New $ipksavail here:" " ${ipk_paths% " $_nl " } "
215
+ [ " ${ipk_paths% " $_nl " } " ] && printf ' %s\n%s\n' " *** New $ipksavail here:" " ${ipk_paths% " $_nl " } "
210
216
}
0 commit comments