#!/bin/sh set -u main() { local boot= [ "x$(id -u)" = 'x0' ] || error 'Must be run as the superuser' if [ ${#} -eq 0 ]; then if is_chroot; then error 'Running under chroot; %s' \ 'please specify the boot and root devices' fi boot="$(mountpoint -n /boot | cut -d ' ' -f 1)" boot="${boot%%[0-9]}" root="$(mountpoint -n / | cut -d ' ' -f 1)" elif [ ${#} -eq 2 ]; then boot="${1}" root="${2}" else usage >&2 exit 1 fi [ -e "${boot}" ] || error 'Boot device not found' [ -e /etc/lilo.conf.in ] || \ error '/etc/lilo.conf: No such file or directory' [ -e /etc/lilo.conf ] && error '/etc/lilo.conf exists' sed "s|@BOOT@|${boot}|g; s|@ROOT@|${root}|g;" /etc/lilo.conf.in \ >/etc/lilo.conf /sbin/lilo rm /etc/lilo.conf } usage() { printf 'Usage: install-lilo [ ]\n' } error() { local fmt="${1}" shift 1 printf "install-lilo: Error: ${fmt}\n" "${@}" >&2 exit 2 } is_chroot() { awk '$5 == "/" { exit(1); };' "/proc/${$}/mountinfo" } main "${@}"