diff --git a/build b/build index 647b8d6..8341cd5 100755 --- a/build +++ b/build @@ -5,7 +5,6 @@ # SPDX-FileCopyrightText: 2015, 2016 Klemens Nanni # SPDX-FileCopyrightText: 2022, Caleb La Grange -[ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e export LC_COLLATE=C @@ -19,12 +18,7 @@ eval "$(setvars "" option aur_notice tmpdir)" tmpdir_was_set="y" set | grep TMPDIR 1>/dev/null 2>/dev/null || tmpdir_was_set="n" if [ "${tmpdir_was_set}" = "y" ]; then - tmpdir="${TMPDIR##*/}" - tmpdir="${TMPDIR%_*}" - if [ "${tmpdir}" = "cbmk" ]; then - tmpdir="" - tmpdir_was_set="n" - fi + [ "${TMPDIR%_*}" = "/tmp/cbmk" ] || tmpdir_was_set="n" fi if [ "${tmpdir_was_set}" = "n" ]; then export TMPDIR="/tmp" @@ -32,8 +26,8 @@ if [ "${tmpdir_was_set}" = "n" ]; then export TMPDIR="${tmpdir}" else export TMPDIR="${TMPDIR}" + tmpdir="${TMPDIR}" fi -tmpdir="${TMPDIR}" linkpath="${0}" linkname="${linkpath##*/}" @@ -43,27 +37,30 @@ main() { xx_ id -u 1>/dev/null 2>/dev/null [ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help" - [ "${1}" = "dependencies" ] && xx_ install_packages $@ && cbmk_exit 0 - initialise_command $@ && shift 1 + [ "$1" = "dependencies" ] && xx_ install_packages $@ && cbmk_exit 0 - check_git - check_project "fail" - git_init - - execute_command $@ + for cmd in initcmd check_git check_project git_init excmd; do + eval "${cmd} \$@" + done cbmk_exit 0 } -initialise_command() +initcmd() { [ "$(id -u)" != "0" ] || fail "this command as root is not permitted" + check_project + case "${1}" in - help) usage ${0} && cbmk_exit 0 ;; - list) items "${buildpath}" && cbmk_exit 0 ;; + help) usage ${0} ;; + list) items "${buildpath}" ;; + version) mkversion ;; + *) + option="${1}" + return 0 ;; esac - option="${1}" + cbmk_exit 0 } install_packages() @@ -81,7 +78,7 @@ install_packages() xx_ ${pkg_add} ${pkglist} [ -z "${aur_notice}" ] && return 0 - printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2 + printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2 } # release archives contain .gitignore, but not .git. @@ -94,41 +91,53 @@ git_init() git init || fail "${PWD}: cannot initialise Git repository" git add -A . || fail "${PWD}: cannot add files to Git repository" - git commit -m "${projectname} ${version}" --date "${cdate}" || \ - fail "${PWD}: can't commit ${projectname}/${version}, date ${cdate}" + git commit -m "${projectname} ${version}" --date "${cdate}" \ + --author="cbmk " || \ + fail "$PWD: can't commit ${projectname}/${version}, date $cdate" git tag -a "${version}" -m "${projectname} ${version}" || \ fail "${PWD}: cannot git-tag ${projectname}/${version}" } -execute_command() +excmd() { cbmkcmd="${buildpath}/${option}" [ -f "${cbmkcmd}" ] || fail "Invalid command. Run: ${linkpath} help" - "${cbmkcmd}" $@ || fail "execute_command: ${cbmkcmd} ${@}" + shift 1; "$cbmkcmd" $@ || fail "excmd: ${cbmkcmd} ${@}" } usage() { progname=${0} cat <<- EOF + $(mkversion) + USAGE: ${progname}