diff options
-rw-r--r-- | src/main.sh | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/src/main.sh b/src/main.sh index 2fbbdbf..6b57b71 100644 --- a/src/main.sh +++ b/src/main.sh @@ -41,43 +41,18 @@ conf_key= lock= exit_status= -main() +handle_sig() { - local cmd= - local status= - - if [ -f "$(dirname "${0}")/.builddirstamp" ]; then - in_place=true - builddir="$(dirname "${0}")" - else - in_place=false - builddir='' - fi - - init_sigs - load_locale - - get_options "${@}" - shift $((${OPTIND} - 1)) + local sig="${1}" + shift 1 - base_dir="${opt_b:-.}" + unlock - if ${opt_h:-false}; then - cmd='help' - elif ${opt_V:-false}; then - cmd='version' - elif [ ${#} -lt 1 ]; then - cmd_help_main >&2 - exit 1 + if [ "x${exit_status:+set}" = 'xset' ]; then + exit ${exit_status} else - cmd="${1}" - shift 1 + exit $((128 + ${sig})) fi - - run_cmd "${cmd}" "${@}" - status=${?} - - return ${status} } init_sigs() @@ -115,12 +90,6 @@ get_options() return 0 } -init() -{ - lock - get_conf -} - lock() { mkdir -p "${base_dir}/.db" @@ -161,11 +130,10 @@ get_conf() return 0 } -fini() +init() { - update_feeds - collect_garbage - unlock + lock + get_conf } unlock() @@ -173,16 +141,48 @@ unlock() rm -f "${lock}" } -handle_sig() +fini() { - local sig="${1}" - shift 1 - + update_feeds + collect_garbage unlock +} - if [ "x${exit_status:+set}" = 'xset' ]; then - exit ${exit_status} +main() +{ + local cmd= + local status= + + if [ -f "$(dirname "${0}")/.builddirstamp" ]; then + in_place=true + builddir="$(dirname "${0}")" else - exit $((128 + ${sig})) + in_place=false + builddir='' fi + + init_sigs + load_locale + + get_options "${@}" + shift $((${OPTIND} - 1)) + + base_dir="${opt_b:-.}" + + if ${opt_h:-false}; then + cmd='help' + elif ${opt_V:-false}; then + cmd='version' + elif [ ${#} -lt 1 ]; then + cmd_help_main >&2 + exit 1 + else + cmd="${1}" + shift 1 + fi + + run_cmd "${cmd}" "${@}" + status=${?} + + return ${status} } |