summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-10-07 17:04:40 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-10-07 17:04:40 (EDT)
commitfb8633200b1e0bd4009293a5ffad24fbd78f17e5 (patch)
treecdb7c70102e0f3a430dec1bbd8a415063de304ca
parent6a4c4b1696e6f81c1d53f5e8a51bb2589a608bfc (diff)
cmd/opkg: Factor cleanup code into sig handler cb
-rw-r--r--lib/cmd/opkg.sh20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/cmd/opkg.sh b/lib/cmd/opkg.sh
index cc3c623..795322c 100644
--- a/lib/cmd/opkg.sh
+++ b/lib/cmd/opkg.sh
@@ -22,12 +22,13 @@ use profile
use session
use rand
+cmd_opkg_opks=
+
cmd_opkg_main()
{
local root=
local first_arg=
local install_cmd=
- local opks=
local arg=
local new_fname=
@@ -41,7 +42,7 @@ cmd_opkg_main()
first_arg=true
install_cmd=false
- opks=''
+ cmd_opkg_opks=''
for arg in "${@}"; do
if ${first_arg}; then
set --
@@ -56,7 +57,9 @@ cmd_opkg_main()
fi
rand
new_fname="/tmp/prokit.${rand_x}.opk"
- opks="${opks} ${root}${new_fname}"
+ cmd_opkg_opks="$(printf '%s %s\n' \
+ "${cmd_opkg_opks}" \
+ "${root}${new_fname}")"
cp "${arg}" "${root}${new_fname}"
set -- "${@}" "${new_fname}"
;;
@@ -75,13 +78,18 @@ cmd_opkg_main()
. "${root}/etc/os-release"
profile_set "${ID}"
- session_begin "${root}" . : false
+ session_begin "${root}" . cmd_opkg_fini false
session_exec opkg "${@}"
session_end
- case "${opks}" in
+ cmd_opkg_fini
+}
+
+cmd_opkg_fini()
+{
+ case "${cmd_opkg_opks}" in
*[!\ ]*)
- rm -f ${opks}
+ rm -f ${cmd_opkg_opks}
;;
esac
}