diff options
author | P. J. McDermott <pj@pehjota.net> | 2014-07-21 01:27:23 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2014-07-21 01:29:47 (EDT) |
commit | 4c945297c19ababe285cae6bf68540fa91508e2b (patch) | |
tree | 9495ea09c5b30e6f281791d2f00ee8224749c6b3 | |
parent | 1fdd884913f7ed6bd8ff5a08d4e719a413b8d315 (diff) |
installers/pc: Prompt for platform
-rw-r--r-- | installers/pc.sh | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/installers/pc.sh b/installers/pc.sh index aa61b35..586654a 100644 --- a/installers/pc.sh +++ b/installers/pc.sh @@ -6,18 +6,21 @@ set -u # run programs built for the arches before it. ARCHES='i686 amd64' +PLATS=' +Acer Aspire One AO751h i686 ao751h +Dell Dimension 2400 amd64 dimension2400 +' + main() { local opt= - local host_arch= - local host_plat= local mirror= local install_arch= + local host_arch= + local host_plat= - while getopts 'a:P:m:' opt; do + while getopts 'm:' opt; do case ${opt} in - a) host_arch="${OPTARG}";; - P) host_plat="${OPTARG}";; m) mirror="${OPTARG}";; ?) print_usage >&2 @@ -33,17 +36,12 @@ main() root="${1}" install_arch="$(detect_arch)" - if [ "x${host_arch}" = 'x' ]; then - host_arch="${install_arch}" - else - validate_arch "${host_arch}" - fi + read host_arch host_plat <<-EOF + $(prompt_plat) + EOF + host_arch="${host_arch}-${install_arch#*-}" check_arch_compat "${install_arch}" "${host_arch}" - if [ "x${host_plat}" = 'x' ]; then - host_plat='dev' - fi - "${0%installers/inst-pc.sh}./miniprokit.sh" install \ -a "${host_arch}" -P "${host_plat}" \ ${mirror:+-m} ${mirror} "${root}" @@ -53,7 +51,7 @@ main() print_usage() { - printf 'Usage: %s [-a <arch>] [-P <plat>] [-m <mirror>] <root>\n' "${0}" + printf 'Usage: %s [-m <mirror>] <root>\n' "${0}" } error() @@ -67,6 +65,44 @@ error() exit ${status} } +_select() +{ + # Field width of the prompt numbers. + select_width=$(expr ${#} : '.*') + + select_i= + + while :; do + case "${select_i}" in + '') + select_i=0 + for select_word in "${@}"; do + select_i=$(expr ${select_i} + 1) + printf "%${select_width}d) %s\\n" \ + ${select_i} "${select_word}" \ + >&2 + done + ;; + *[!0-9]*) + printf 'Please enter a number in range.\n' >&2 + ;; + *) + if [ ${select_i} -gt 0 ] && \ + [ ${select_i} -le ${#} ]; then + shift $(expr $select_i - 1) + select_result="${1}" + break + fi + printf 'Please enter a number in range.\n' >&2 + ;; + esac + + # Prompt and read input. + printf '%s' "${PS3-#? }" >&2 + read -r select_i || exit + done +} + detect_arch() { local uname_m= @@ -85,15 +121,31 @@ detect_arch() printf '%s\n' "${arch}" } -validate_arch() +prompt_plat() { - local arch="${1}" - local arches= - - arches=" ${ARCHES} " - if [ "x${arches#* ${arch} }" = "x${arches}" ]; then - error 2 'Unknown architecture "%s"' "${arch}" - fi + local desc= + local arch= + local plat= + + set -- + while IFS=' ' read -r desc arch plat; do + [ "x${desc}" = 'x' ] && continue + set -- "${@}" "${desc}" + done <<-EOF + ${PLATS} + EOF + + printf 'Select a platform:\n' >&2 + _select "${@}" + + while IFS=' ' read -r desc arch plat; do + if [ "x${desc}" = "x${select_result}" ]; then + printf '%s %s\n' "${arch}" "${plat}" + break + fi + done <<-EOF + ${PLATS} + EOF } check_arch_compat() |