summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-07-13 23:36:41 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-07-13 23:36:41 (EDT)
commitcdb4bd7abb307db1fd68b314a4785cbea8dcdf86 (patch)
treef2d0eb777caf48af26715b242735b14f13da1998
parent24edce389201a9f29bd0f36197a7a4d348c41db9 (diff)
install-lilo: Detect boot/root unless under chroot
-rw-r--r--install-lilo.sh21
1 files changed, 17 insertions, 4 deletions
diff --git a/install-lilo.sh b/install-lilo.sh
index e980baa..ff3dd2c 100644
--- a/install-lilo.sh
+++ b/install-lilo.sh
@@ -8,12 +8,20 @@ main()
[ "x$(id -u)" = 'x0' ] || error 'Must be run as the superuser'
- if [ ${#} -ne 2 ]; then
+ 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)"
+ root="$(mountpoint -n / | cut -d ' ' -f 1)"
+ elif [ ${#} -eq 2 ]; then
+ boot="${1}"
+ root="${2}"
+ else
usage >&2
exit 1
fi
- boot="${1}"
- root="${2}"
[ -e "${boot}" ] || error 'Boot device not found'
[ -e /etc/lilo.conf.in ] || \
@@ -28,7 +36,7 @@ main()
usage()
{
- printf 'Usage: install-lilo <boot> <root>\n'
+ printf 'Usage: install-lilo [<boot> <root>]\n'
}
error()
@@ -40,4 +48,9 @@ error()
exit 2
}
+is_chroot()
+{
+ awk '$5 == "/" { exit(1); };' "/proc/${$}/mountinfo"
+}
+
main "${@}"