summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-07-21 01:05:22 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-07-21 01:05:22 (EDT)
commit1fdd884913f7ed6bd8ff5a08d4e719a413b8d315 (patch)
tree0d8ddf791437acd60c96a18b110ae1d8d52af6f5
parent859aebf94835201b3f1ab20d5e5b3444f666d230 (diff)
installers/pc: New installer for PC platforms
-rw-r--r--installers/data/pc.sh96
-rw-r--r--installers/pc.sh118
2 files changed, 214 insertions, 0 deletions
diff --git a/installers/data/pc.sh b/installers/data/pc.sh
new file mode 100644
index 0000000..4cd8d09
--- /dev/null
+++ b/installers/data/pc.sh
@@ -0,0 +1,96 @@
+set -u
+
+_read()
+{
+ # The miniprokit call in the installer redirects this script to stdin,
+ # so we need to reconnect stdin to the tty. We can't do this for the
+ # whole script with exec, because the shell reads the script in parts.
+ read "${@}" 0<&1
+}
+
+_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}"
+ 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
+}
+
+printf '\nConfigure the network'
+printf '\n=====================\n\n'
+printf 'Network configuration method:\n'
+_select 'Static' 'DHCP'
+if [ "x${select_result}" = 'xStatic' ]; then
+ printf 'Network interface (e.g. "eth0"): '
+ _read -r netiface
+ printf 'Network address (e.g. "192.168.1.2"): '
+ _read -r netaddr
+ printf 'Network mask (e.g. "255.255.255.0"): '
+ _read -r netmask
+ printf 'Network gateway (e.g. "192.168.1.1"): '
+ _read -r netgw
+ cat >/etc/network/interfaces <<EOF
+auto lo
+iface lo inet loopback
+
+auto ${netiface}
+iface ${netiface} inet static
+ address ${netaddr}
+ netmask ${netmask}
+ gateway ${netgw}
+EOF
+fi
+
+printf '\nSet up users and passwords'
+printf '\n==========================\n\n'
+while ! passwd 0<&1; do
+ :
+done
+printf '\n'
+
+tzpkgs="$(opkg info 'tzdata-*' | sed -n 's/^Package: //p')"
+opkg install tzcode tzdata ${tzpkgs}
+printf '\nConfigure the time zone'
+printf '\n=======================\n\n'
+tz="$(tzselect 0<&2)"
+printf '\n'
+ln -sf "/usr/share/zoneinfo/${tz}" /etc/localtime
+seltzpkg="$(opkg search "/usr/share/zoneinfo/${tz}" | cut -d ' ' -f 1)"
+rmtzpkgs=''
+for tzpkg in ${tzpkgs}; do
+ if ! [ "x${tzpkg}" = "x${seltzpkg}" ]; then
+ rmtzpkgs="${rmtzpkgs} ${tzpkg}"
+ fi
+done
+opkg remove tzcode ${rmtzpkgs}
+
+printf '\nInstallation complete!\n'
diff --git a/installers/pc.sh b/installers/pc.sh
new file mode 100644
index 0000000..aa61b35
--- /dev/null
+++ b/installers/pc.sh
@@ -0,0 +1,118 @@
+#!/bin/sh
+
+set -u
+
+# This should be maintained in order of compatibility, i.e. each arch can also
+# run programs built for the arches before it.
+ARCHES='i686 amd64'
+
+main()
+{
+ local opt=
+ local host_arch=
+ local host_plat=
+ local mirror=
+ local install_arch=
+
+ while getopts 'a:P:m:' opt; do
+ case ${opt} in
+ a) host_arch="${OPTARG}";;
+ P) host_plat="${OPTARG}";;
+ m) mirror="${OPTARG}";;
+ ?)
+ print_usage >&2
+ exit 1
+ ;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ if [ ${#} -ne 1 ]; then
+ print_usage >&2
+ exit 1
+ fi
+ root="${1}"
+
+ install_arch="$(detect_arch)"
+ if [ "x${host_arch}" = 'x' ]; then
+ host_arch="${install_arch}"
+ else
+ validate_arch "${host_arch}"
+ fi
+ 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}"
+ "${0%installers/inst-pc.sh}./miniprokit.sh" shell "${root}" \
+ <"${0%inst-pc.sh}data/pc.sh"
+}
+
+print_usage()
+{
+ printf 'Usage: %s [-a <arch>] [-P <plat>] [-m <mirror>] <root>\n' "${0}"
+}
+
+error()
+{
+ local status=${1}
+ local fmt="${2}"
+ shift 2
+
+ printf "Error: ${fmt}\n" "${@}" >&2
+
+ exit ${status}
+}
+
+detect_arch()
+{
+ local uname_m=
+ local uname_s=
+ local arch=
+
+ uname_m="$( (uname -m) 2>/dev/null)" || uname_m='?'
+ uname_s="$( (uname -s) 2>/dev/null)" || uname_s='?'
+ case "${uname_m}:${uname_s}" in
+ 'i686:Linux') arch='i686-linux-glibc';;
+ 'x86_64:Linux') arch='amd64-linux-glibc';;
+ '?:?') error 2 'Architecture unknown';;
+ *) error 2 'Architecture unsupported';;
+ esac
+
+ printf '%s\n' "${arch}"
+}
+
+validate_arch()
+{
+ local arch="${1}"
+ local arches=
+
+ arches=" ${ARCHES} "
+ if [ "x${arches#* ${arch} }" = "x${arches}" ]; then
+ error 2 'Unknown architecture "%s"' "${arch}"
+ fi
+}
+
+check_arch_compat()
+{
+ local install_arch="${1}"
+ local host_arch="${2}"
+ local arches=
+
+ if [ "x${install_arch}" = "x${host_arch}" ]; then
+ return 0
+ fi
+
+ arches="$(printf ' %s ' ${ARCHES})"
+ if [ "x${arches#* ${host_arch} * ${install_arch} }" = "x${arches}" ]
+ then
+ error 2 'Cannot install a system of architecture %s on %s %s' \
+ "${host_arch}" 'a system of architecture' \
+ "${install_arch}"
+ fi
+}
+
+main "${@}"