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 'Hostname (e.g. "proteanos"): ' _read -r hostname printf '%s\n' "${hostname}" >/etc/hostname net_wlan_ifaces=false printf 'Network configuration:\n' _select 'Automatic' 'Manual' if [ "x${select_result}" = 'xManual' ]; then exec 3>/etc/network/interfaces.local printf 'auto lo\niface lo inet loopback\n\n' >&3 while true; do printf 'Interface (e.g. "eth0" or "wlan0") or empty to finish: ' _read -r net_iface [ "x${net_iface}" = 'x' ] && break case "${net_iface%%[0-9]}" in eth|wlan);; *) printf 'Unknown interface type\n';; esac net_static=false printf 'Interface configuration:\n' _select 'DHCP' 'Static' if [ "x${select_result}" = 'xStatic' ]; then net_static=true printf 'auto %s\niface %s inet static\n' \ "${net_iface}" "${net_iface}" >&3 printf 'Address: (e.g. "192.168.1.2"): ' _read -r net_addr printf '\taddress %s\n' "${net_addr}" >&3 printf 'Network mask: (e.g. "255.255.255.0"): ' _read -r net_mask printf '\tnetmask %s\n' "${net_mask}" >&3 printf 'Default gateway: (e.g. "%s") or empty: ' \ '192.168.1.1' _read -r net_gateway if [ "x${net_gateway}" != 'x' ]; then printf '\tgateway %s\n' "${net_gateway}" >&3 fi printf 'DNS servers: (e.g. "192.168.1.1 10.0.0.1"): ' _read -r net_dns net_dns="$(printf '%s\n' "${net_dns}" | \ sed 's/[^0-9. ]//g')" exec 4>/etc/resolv.conf for net_ns in ${net_dns}; do printf 'nameserver %s\n' "${net_ns}" >&4 done exec 4>&- printf 'Enable DHCP server:\n' _select 'Yes' 'No' if [ "x${select_result}" = 'xYes' ]; then printf 'Start host address (e.g. "%s"): ' \ '192.168.1.100' _read -r net_dhcpd_start printf '\tdhcpd-start %s\n' "${net_dhcpd_start}" \ >&3 printf 'End host address (e.g. "%s"): ' \ '192.168.1.254' _read -r net_dhcpd_end printf '\tdhcpd-end %s\n' "${net_dhcpd_end}" >&3 printf 'Lease time (e.g. "864000"): ' _read -r net_dhcpd_lease printf '\tdhcpd-option lease %s\n' \ "${net_dhcpd_lease}" >&3 fi else printf 'auto %s\niface %s inet dhcp\n' \ "${net_iface}" "${net_iface}" >&3 fi case "${net_iface%%[0-9]}" in wlan) net_wlan_ifaces=true if ${net_static}; then printf 'Wi-Fi configuration:\n' _select 'Access point' 'Client' if [ "x${select_result}" = 'xClient' ]; then printf '\twpa-mode 0\n' >&3 else printf '\twpa-mode 2\n' >&3 fi else # Force client mode with DHCP. printf '\twpa-mode 0\n' >&3 fi printf 'ESSID (name): ' _read -r net_wpa_ssid printf '\twpa-ssid %s\n' "${net_wpa_ssid}" >&3 printf 'Security:\n' _select 'None' 'WPA2-PSK' if [ "x${select_result}" = 'xWPA2-PSK' ]; then printf '\twpa-proto RSN\n' >&3 printf '\twpa-key-mgmt WPA-PSK\n' >&3 printf 'Pre-shared key (passphrase): ' _read -r net_wpa_psk printf '\twpa-psk %s\n' "${net_wpa_psk}" >&3 else printf '\twpa-key-mgmt NONE\n' >&3 fi ;; esac printf '\n' >&3 done exec 3>&- else printf 'Install WPA supplicant:\n' _select 'Yes' 'No' if [ "x${select_result}" = 'xYes' ]; then net_wlan_ifaces=true fi fi if ${net_wlan_ifaces}; then opkg install wpa-supplicant 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} opkg install lilo boot="$(mountpoint -n /boot | cut -d ' ' -f 1)" boot="${boot%%[0-9]}" printf '\nInstall the boot loader' printf '\n=======================\n\n' printf 'Name of root partition on running system (e.g. "sda1"): ' _read -r root printf '\n' # XXX: Temporary kludge. cp -p /boot/vmlinuz /boot/vmlinuz.old install-lilo "${boot}" "/dev/${root}" >&2 printf '\nCustom configuration' printf '\n====================\n\n' printf 'Additional packages to install (e.g. "fbi cmatrix acpi") or empty: ' _read -r custom_pkgs printf '\n' if [ "x${custom_pkgs}" != 'x' ]; then opkg install ${custom_pkgs} fi printf '\nInstallation complete!\n'