diff options
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/build.sh | 30 | ||||
-rw-r--r-- | src/cmd/install.sh | 23 | ||||
-rw-r--r-- | src/cmd/installer-pc.sh | 37 | ||||
-rw-r--r-- | src/cmd/mkinitramfs.sh | 22 | ||||
-rw-r--r-- | src/cmd/opkg.sh | 19 | ||||
-rw-r--r-- | src/cmd/shell.sh | 18 |
6 files changed, 109 insertions, 40 deletions
diff --git a/src/cmd/build.sh b/src/cmd/build.sh index dbfd910..1d0ad52 100644 --- a/src/cmd/build.sh +++ b/src/cmd/build.sh @@ -34,7 +34,7 @@ cmd_build_main() if [ ${#} -lt 2 ]; then print_cmd_usage 'build' >&2 - exit 1 + return 1 fi root="${1}" @@ -43,7 +43,9 @@ cmd_build_main() dev='' if is_block "${root}"; then dev="${root}" - root="$(block_mount "${dev}")" + if ! root="$(block_mount "${dev}")"; then + return 2 + fi fi cmd_build_root="${root}" @@ -70,16 +72,28 @@ cmd_build_main() cmd_build_pkg_dir="${arg}" done - profile_detect "${root}" + if ! profile_detect "${root}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi if ! [ -d "${cmd_build_pkg_dir}" ]; then - error 2 "$(get_msg 'cmd_build_not_a_dir')" \ - "${cmd_build_pkg_dir}" + error "$(get_msg 'cmd_build_not_a_dir')" "${cmd_build_pkg_dir}" + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi + if ! package_init "${cmd_build_pkg_dir}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 fi - package_init "${cmd_build_pkg_dir}" package_set_substvars "${arch}" "${plat}" - session_begin "${root}" "${cmd_build_pkg_dir}" cmd_build_fini false + if ! session_begin "${root}" "${cmd_build_pkg_dir}" cmd_build_fini false + then + cmd_build_fini + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi cmd_build_build_deps="$(package_get_build_deps "${arch}" "${plat}")" if [ "x${cmd_build_build_deps}" != 'x' ]; then @@ -94,6 +108,8 @@ cmd_build_main() session_end [ "x${dev}" != 'x' ] && block_umount "${root}" + + return 0 } cmd_build_make_deps_pkg() diff --git a/src/cmd/install.sh b/src/cmd/install.sh index ae26588..d32f488 100644 --- a/src/cmd/install.sh +++ b/src/cmd/install.sh @@ -30,13 +30,13 @@ cmd_install_main() if ! get_options "${@}"; then print_cmd_usage 'install' >&2 - exit 1 + return 1 fi shift $(($OPTIND - 1)) if [ ${#} -lt 2 ]; then print_cmd_usage 'install' >&2 - exit 1 + return 1 fi # TODO: Consider making suite optional, getting a default suite from the @@ -50,7 +50,9 @@ cmd_install_main() else profile='proteanos' fi - profile_set "${profile}" + if ! profile_set "${profile}"; then + return 2 + fi suite="$(profile_normalize_suite "${suite}")" if [ "x${cmd_install_opt_F+set}" = 'xset' ]; then @@ -62,14 +64,21 @@ cmd_install_main() dev='' if is_block "${root}"; then dev="${root}" - root="$(block_mount "${dev}")" + if ! root="$(block_mount "${dev}")"; then + return 2 + fi fi - install_system "${cmd_install_opt_m-}" "${suite}" \ - "${cmd_install_opt_a-}" "${cmd_install_opt_p-}" \ - "${root}" "${foreign}" + if ! install_system "${cmd_install_opt_m-}" "${suite}" \ + "${cmd_install_opt_a-}" "${cmd_install_opt_p-}" \ + "${root}" "${foreign}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 1 + fi [ "x${dev}" != 'x' ] && block_umount "${root}" + + return 0 } cmd_install_register() diff --git a/src/cmd/installer-pc.sh b/src/cmd/installer-pc.sh index f9fd509..348838e 100644 --- a/src/cmd/installer-pc.sh +++ b/src/cmd/installer-pc.sh @@ -33,26 +33,28 @@ cmd_installer_pc_main() if ! get_options "${@}"; then print_cmd_usage 'installer-pc' >&2 - exit 1 + return 1 fi shift $(($OPTIND - 1)) if [ "x${cmd_installer_pc_opt_a-}" = 'x' ]; then print_cmd_usage 'installer-pc' >&2 - exit 1 + return 1 fi if [ "x${cmd_installer_pc_opt_p-}" = 'x' ]; then print_cmd_usage 'installer-pc' >&2 - exit 1 + return 1 fi if [ ${#} -ne 2 ]; then print_cmd_usage 'installer-pc' >&2 - exit 1 + return 1 fi suite="${1}" dev="${2}" - check_block "${dev}" + if ! check_block "${dev}"; then + return 2 + fi if [ "x${suite%%:*}" != "x${suite}" ]; then profile="${suite%%:*}" @@ -60,15 +62,23 @@ cmd_installer_pc_main() else profile='proteanos' fi - profile_set "${profile}" + if ! profile_set "${profile}"; then + return 2 + fi suite="$(profile_normalize_suite "${suite}")" cmd_installer_pc_make_partition_and_fs "${dev}" - root="$(block_mount "${dev}1")" + if ! root="$(block_mount "${dev}1")"; then + return 2 + fi - install_system "${cmd_installer_pc_opt_m-}" "${suite}" \ - "${cmd_installer_pc_opt_a-}" "${cmd_installer_pc_opt_p-}" \ - "${root}" false + if ! install_system "${cmd_installer_pc_opt_m-}" "${suite}" \ + "${cmd_installer_pc_opt_a-}" \ + "${cmd_installer_pc_opt_p-}" \ + "${root}" false; then + block_umount "${root}" + return 1 + fi if [ -f "${root}/sbin/lilo" ]; then read b4 b3 b2 b1 <<-EOF @@ -76,13 +86,18 @@ cmd_installer_pc_main() EOF # This ln command won't be needed once lilo 24.1-1 is uploaded. ln "${root}/boot/vmlinuz" "${root}/boot/vmlinuz.old" - session_begin "${root}" . : false + if ! session_begin "${root}" . : false + block_umount "${root}" + return 2 + fi session_exec install-lilo \ "${dev}" "PARTUUID=${b1}${b2}${b3}${b4}-01" session_end fi block_umount "${root}" + + return 0 } cmd_installer_pc_make_partition_and_fs() diff --git a/src/cmd/mkinitramfs.sh b/src/cmd/mkinitramfs.sh index 0ff0923..41e6327 100644 --- a/src/cmd/mkinitramfs.sh +++ b/src/cmd/mkinitramfs.sh @@ -29,21 +29,21 @@ cmd_mkinitramfs_main() if ! get_options "${@}"; then print_cmd_usage 'mkinitramfs' >&2 - exit 1 + return 1 fi shift $(($OPTIND - 1)) if [ "x${cmd_mkinitramfs_opt_l-}" = 'x' ]; then print_cmd_usage 'mkinitramfs' >&2 - exit 1 + return 1 fi if [ "x${cmd_mkinitramfs_opt_i-}" = 'x' ]; then print_cmd_usage 'mkinitramfs' >&2 - exit 1 + return 1 fi if [ ${#} -lt 1 ]; then print_cmd_usage 'mkinitramfs' >&2 - exit 1 + return 1 fi linux_output="${cmd_mkinitramfs_opt_l}" @@ -54,16 +54,22 @@ cmd_mkinitramfs_main() dev='' if is_block "${root}"; then dev="${root}" - root="$(block_mount "${dev}")" + if ! root="$(block_mount "${dev}")"; then + return 2 + fi fi - profile_detect "${root}" + if ! profile_detect "${root}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi arch="$(cat "${root}/etc/proteanos_arch")" plat="$(cat "${root}/etc/proteanos_plat")" if ! img="$(profile_find_kernel "${root}" "${arch}" "${plat}")"; then + error "$(get_msg 'cmd_mkinitramfs_kernel_not_found')" [ "x${dev}" != 'x' ] && block_umount "${root}" - error 2 "$(get_msg 'cmd_mkinitramfs_kernel_not_found')" + return 2 fi cp -p "${root}/${img}" "${linux_output}" @@ -71,6 +77,8 @@ cmd_mkinitramfs_main() >"${initramfs_output}" [ "x${dev}" != 'x' ] && block_umount "${root}" + + return 0 } cmd_mkinitramfs_register() diff --git a/src/cmd/opkg.sh b/src/cmd/opkg.sh index 5a48fb8..b99a977 100644 --- a/src/cmd/opkg.sh +++ b/src/cmd/opkg.sh @@ -31,7 +31,7 @@ cmd_opkg_main() if [ ${#} -lt 1 ]; then print_cmd_usage 'opkg' >&2 - exit 1 + return 1 fi root="${1}" @@ -40,7 +40,9 @@ cmd_opkg_main() dev='' if is_block "${root}"; then dev="${root}" - root="$(block_mount "${dev}")" + if ! root="$(block_mount "${dev}")"; then + return 2 + fi fi first_arg=true @@ -78,9 +80,16 @@ cmd_opkg_main() fi done - profile_detect "${root}" + if ! profile_detect "${root}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi - session_begin "${root}" . cmd_opkg_fini false + if ! session_begin "${root}" . cmd_opkg_fini false; then + cmd_opkg_fini + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi session_exec opkg "${@}" @@ -88,6 +97,8 @@ cmd_opkg_main() session_end [ "x${dev}" != 'x' ] && block_umount "${root}" + + return 0 } cmd_opkg_fini() diff --git a/src/cmd/shell.sh b/src/cmd/shell.sh index e761f55..8d5cd16 100644 --- a/src/cmd/shell.sh +++ b/src/cmd/shell.sh @@ -25,7 +25,7 @@ cmd_shell_main() if [ ${#} -lt 1 ]; then print_cmd_usage 'shell' >&2 - exit 1 + return 1 fi root="${1}" @@ -34,12 +34,20 @@ cmd_shell_main() dev='' if is_block "${root}"; then dev="${root}" - root="$(block_mount "${dev}")" + if ! root="$(block_mount "${dev}")"; then + return 2 + fi fi - profile_detect "${root}" + if ! profile_detect "${root}"; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi - session_begin "${root}" . : false + if ! session_begin "${root}" . : false; then + [ "x${dev}" != 'x' ] && block_umount "${root}" + return 2 + fi if [ ${#} -eq 0 ]; then session_exec /bin/sh printf '\n' @@ -50,6 +58,8 @@ cmd_shell_main() session_end [ "x${dev}" != 'x' ] && block_umount "${root}" + + return 0 } cmd_shell_register() |