summaryrefslogtreecommitdiffstats
path: root/lib/cmd
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-10-07 20:30:51 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-10-07 20:30:51 (EDT)
commitd7325b15a0949cef77707be5fd0bf864d6338c57 (patch)
treef10d1191c1a05056bef57b2569bd096fdd973d7d /lib/cmd
parentd8c058f9e333ae7d99030c64f9c19c47b3a35085 (diff)
parent6ca3ac8f4d34f2f0348d64178dc0b3e8ccd7aa7f (diff)
Merge branch 'feature/sessions'
Diffstat (limited to 'lib/cmd')
-rw-r--r--lib/cmd/build.sh126
-rw-r--r--lib/cmd/install.sh5
-rw-r--r--lib/cmd/opkg.sh28
-rw-r--r--lib/cmd/shell.sh26
4 files changed, 89 insertions, 96 deletions
diff --git a/lib/cmd/build.sh b/lib/cmd/build.sh
index 140ef4a..32dca26 100644
--- a/lib/cmd/build.sh
+++ b/lib/cmd/build.sh
@@ -19,11 +19,15 @@
# <http://www.gnu.org/licenses/>.
use profile
-use chroot
+use session
use rand
use package
use control
+cmd_build_root=
+cmd_build_pkg_dir=
+cmd_build_build_deps=
+
cmd_build_main()
{
local root=
@@ -31,12 +35,7 @@ cmd_build_main()
local arch=
local plat=
local first_arg=
- local prev_arg=
local arg=
- local dir=
- local uname_s=
- local build_deps=
- local f=
if [ ${#} -lt 2 ]; then
print_cmd_usage 'build' >&2
@@ -44,6 +43,7 @@ cmd_build_main()
fi
root="${1}"
+ cmd_build_root="${root}"
shift 1
opkbuild_optstring="$(cat "${root}/usr/share/opkbuild/optstring")"
@@ -51,98 +51,90 @@ cmd_build_main()
plat="$(cat "${root}/etc/proteanos_plat")"
while getopts "${opkbuild_optstring}" opt 2>/dev/null; do
case "${opt}" in
- a)
- arch="${OPTARG}"
- ;;
- p)
- plat="${OPTARG}"
- ;;
+ a) arch="${OPTARG}";;
+ p) plat="${OPTARG}";;
esac
done
first_arg=true
- prev_arg=
+ cmd_build_pkg_dir=''
for arg in "${@}"; do
if ${first_arg}; then
set --
first_arg=false
else
- set -- "${@}" "${prev_arg}"
+ set -- "${@}" "${cmd_build_pkg_dir}"
fi
- prev_arg="${arg}"
+ cmd_build_pkg_dir="${arg}"
done
. "${root}/etc/os-release"
profile_set "${ID}"
- if ! [ -d "${prev_arg}" ]; then
- error 2 "$(get_msg 'cmd_build_not_a_dir')" "${prev_arg}"
+ if ! [ -d "${cmd_build_pkg_dir}" ]; then
+ error 2 "$(get_msg 'cmd_build_not_a_dir')" \
+ "${cmd_build_pkg_dir}"
fi
- package_init "${prev_arg}"
+ package_init "${cmd_build_pkg_dir}"
package_set_substvars "${arch}" "${plat}"
- rand
- dir="/prokit/build.${rand_x}"
- uname_s="$( (uname -s) 2>/dev/null)" || uname_s='unknown'
- mkdir -p "${root}${dir}/pkg"
- case "${uname_s}" in
- 'Linux')
- mount -o bind "${prev_arg}" "${root}${dir}/pkg"
- ;;
- esac
-
- build_deps="$(package_get_build_deps "${arch}" "${plat}")"
- if [ "x${build_deps}" != 'x' ]; then
- mkdir -p "${root}${dir}/builddeps/control" \
- "${root}${dir}/builddeps/data"
- cmd_build_make_deps_pkg "${root}${dir}" "${rand_x}" \
- "${build_deps}"
+ session_begin "${root}" "${cmd_build_pkg_dir}" cmd_build_fini false
+
+ cmd_build_build_deps="$(package_get_build_deps "${arch}" "${plat}")"
+ if [ "x${cmd_build_build_deps}" != 'x' ]; then
+ cmd_build_make_deps_pkg
+ session_exec opkg install ../builddeps.opk
fi
- chroot_exec "${root}" sh <<-EOF
- cd '${dir}/pkg'
- if [ 'x${build_deps}' != 'x' ]; then
- opkg install ../builddeps.opk
- fi
- opkbuild ${@}
- if [ 'x${build_deps}' != 'x' ]; then
- opkg --autoremove remove prokit-builddeps-${rand_x}
- fi
- EOF
+ session_exec opkbuild "${@}"
- case "${uname_s}" in
- 'Linux')
- umount "${root}${dir}/pkg"
- ;;
- esac
- rmdir "${root}${dir}/pkg"
- rm -f "${root}${dir}/builddeps.opk"
- for f in "${root}${dir}/"*; do
- [ -e "${f}" ] || continue
- mv "${f}" "${prev_arg}/.."
- done
- rmdir "${root}${dir}"
+ cmd_build_fini
+
+ session_end
}
cmd_build_make_deps_pkg()
{
- local build_dir="${1}"
- local build_id="${2}"
- local build_deps="${3}"
+ local pkg_dir=
- printf '2.0\n' >"${build_dir}/builddeps/debian-binary"
- cat >"${build_dir}/builddeps/control/control" <<-EOF
- Package: prokit-builddeps-${build_id}
+ pkg_dir="${cmd_build_root}$(session_dir)/builddeps"
+ mkdir -p "${pkg_dir}/control" "${pkg_dir}/data"
+ printf '2.0\n' >"${pkg_dir}/debian-binary"
+ cat >"${pkg_dir}/control/control" <<-EOF
+ Package: prokit-builddeps-$(session_id)
Source: prokit
Version: 1.0
Architecture: all
Platform: all
- Depends: ${build_deps}
+ Depends: ${cmd_build_build_deps}
Description: Build dependencies metapackage generated by prokit
EOF
- (cd "${build_dir}/builddeps/data"; tar -czf ../data.tar.gz .)
- (cd "${build_dir}/builddeps/control"; tar -czf ../control.tar.gz .)
- (cd "${build_dir}/builddeps"; tar -czf ../builddeps.opk \
+ (cd "${pkg_dir}/data"; tar -czf ../data.tar.gz .)
+ (cd "${pkg_dir}/control"; tar -czf ../control.tar.gz .)
+ (cd "${pkg_dir}"; tar -czf ../builddeps.opk \
'debian-binary' 'data.tar.gz' 'control.tar.gz')
- rm -Rf "${build_dir}/builddeps"
+ rm -Rf "${pkg_dir}"
+}
+
+cmd_build_fini()
+{
+ local session_dir=
+ local f=
+
+ session_dir="$(session_dir)"
+
+ if [ "x${cmd_build_build_deps}" != 'x' ]; then
+ session_exec opkg --autoremove remove \
+ prokit-builddeps-$(session_id)
+ rm "${cmd_build_root}${session_dir}/builddeps.opk"
+ # Hack to avoid this code branch if the function is called again
+ # in response to a signal.
+ cmd_build_build_deps=''
+ fi
+
+ for f in "${cmd_build_root}${session_dir}/"*; do
+ [ -e "${f}" ] || continue
+ [ "x${f##*/}" = 'xwd' ] && continue
+ mv "${f}" "${cmd_build_pkg_dir}/.."
+ done
}
diff --git a/lib/cmd/install.sh b/lib/cmd/install.sh
index 6c1e6ce..529382d 100644
--- a/lib/cmd/install.sh
+++ b/lib/cmd/install.sh
@@ -100,9 +100,10 @@ cmd_install_main()
if [ -d "${chroot}" ]; then
error 2 "$(get_msg 'cmd_install_chroot_dir_exists')" "${chroot}"
fi
- if ! mkdir -p "${chroot}/.prokit"; then
+ if ! mkdir -p "${chroot}/.prokit" "${chroot}/prokit"; then
error 2 "$(get_msg 'cmd_install_mkdir_chroot_fail')" "${chroot}"
fi
+ >"${chroot}/prokit/installing"
info "$(get_msg 'cmd_install_find_pkgs')"
cmd_install_find_pkgs "${mirror}" "${suite}" "${arch}" "${plat}" \
@@ -115,6 +116,8 @@ cmd_install_main()
else
profile_configure_system_foreign "${chroot}"
fi
+
+ rm "${chroot}/prokit/installing"
}
cmd_install_find_pkgs()
diff --git a/lib/cmd/opkg.sh b/lib/cmd/opkg.sh
index 3016773..9f0c0de 100644
--- a/lib/cmd/opkg.sh
+++ b/lib/cmd/opkg.sh
@@ -19,15 +19,16 @@
# <http://www.gnu.org/licenses/>.
use profile
-use chroot
+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,11 +78,22 @@ cmd_opkg_main()
. "${root}/etc/os-release"
profile_set "${ID}"
- chroot_exec "${root}" opkg "${@}"
+ session_begin "${root}" . cmd_opkg_fini false
+
+ session_exec opkg "${@}"
- case "${opks}" in
+ cmd_opkg_fini
+ session_end
+}
+
+cmd_opkg_fini()
+{
+ case "${cmd_opkg_opks}" in
*[!\ ]*)
- rm -f ${opks}
+ rm -f ${cmd_opkg_opks}
+ # Hack to avoid this code branch if the function is
+ # called again in response to a signal.
+ cmd_opkg_opks=''
;;
esac
}
diff --git a/lib/cmd/shell.sh b/lib/cmd/shell.sh
index 5c85d7e..dfff07f 100644
--- a/lib/cmd/shell.sh
+++ b/lib/cmd/shell.sh
@@ -19,12 +19,11 @@
# <http://www.gnu.org/licenses/>.
use profile
-use chroot
+use session
cmd_shell_main()
{
local root=
- local uname_s=
if [ ${#} -lt 1 ]; then
print_cmd_usage 'shell' >&2
@@ -37,28 +36,13 @@ cmd_shell_main()
. "${root}/etc/os-release"
profile_set "${ID}"
- uname_s="$( (uname -s) 2>/dev/null)" || uname_s='unknown'
- mkdir -p "${root}/prokit/wd/${$}"
- case "${uname_s}" in
- 'Linux')
- mount -o bind . "${root}/prokit/wd/${$}"
- ;;
- esac
-
- chroot_mount "${root}"
+ session_begin "${root}" . : false
if [ ${#} -eq 0 ]; then
- chroot "${root}" /bin/sh -c "cd '/prokit/wd/${$}'; /bin/sh"
+ session_exec /bin/sh
printf '\n'
info "$(get_msg 'cmd_shell_exiting')"
else
- chroot "${root}" /bin/sh -c "cd '/prokit/wd/${$}'; ${*}"
+ session_exec "${@}"
fi
- chroot_umount "${root}"
-
- case "${uname_s}" in
- 'Linux')
- umount "${root}/prokit/wd/${$}"
- ;;
- esac
- rmdir "${root}/prokit/wd/${$}"
+ session_end
}