androot/mount.sh

69 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2023-11-07 17:23:39 +01:00
#!/bin/bash
2023-11-08 19:47:37 +01:00
# disable errors regarding androot.source as
# it is created and loaded at runtime
# shellcheck disable=SC1091
2023-11-07 17:23:39 +01:00
source "${TMPDIR}/androot.source"
source "${TMPDIR}/androot.env"
log_diag "mount is now executing, with arguments \"${*}\""
2023-11-08 19:47:37 +01:00
# to avoid repetition
function mountf() {
# $@ is used intentionally here, so ignore error
# shellcheck disable=SC2068
if ! log_execute mount ${@}; then
indicate_fail
2023-11-07 17:23:39 +01:00
exit 1
fi
}
2023-11-08 19:47:37 +01:00
# to avoid repetition
function umountf() {
# $@ is used intentionally here, so ignore error
# shellcheck disable=SC2068
if ! log_execute umount ${@}; then
indicate_fail
2023-11-07 17:23:39 +01:00
exit 1
fi
}
case "${1}" in
"--mount")
log_diag "Using mount mode"
mkdir -p "${LOCATION}/mountdir"
2023-11-08 19:47:37 +01:00
# remount /data on android to enable
# suid and exec flags
2023-11-07 17:23:39 +01:00
if [ "${IS_ANDROID}" == "true" ]; then
2023-11-08 19:47:37 +01:00
indicate_exec "Remounting /data"
2023-11-07 17:23:39 +01:00
mount_fail "/data (remount)" "/data" -o remount,suid,exec
2023-11-08 19:47:37 +01:00
indicate_ok
2023-11-07 17:23:39 +01:00
fi
2023-11-08 19:47:37 +01:00
indicate_exec "Mounting rootfs"
mountf --bind "${LOCATION}/rootfs" "${LOCATION}/mountdir" -o rw,suid,dev,exec,auto,nouser,async
indicate_ok
indicate_exec "Binding directories"
# mount /dev BEFORE /dev/pts
mountf --bind "/dev" "${LOCATION}/mountdir/dev"
mountf --bind "/dev/pts" "${LOCATION}/mountdir/dev/pts"
mountf --bind "/sys" "${LOCATION}/mountdir/sys"
mountf --bind "/proc" "${LOCATION}/mountdir/proc"
indicate_ok
;;
2023-11-07 17:23:39 +01:00
"--unmount")
log_diag "Using unmount mode"
2023-11-08 19:47:37 +01:00
indicate_exec "Unmounting binds"
# unmount /dev AFTER /dev/pts
umountf "${LOCATION}/mountdir/dev/pts"
umountf "${LOCATION}/mountdir/dev"
umountf "${LOCATION}/mountdir/sys"
umountf "${LOCATION}/mountdir/proc"
indicate_ok
indicate_exec "Unmounting rootfs"
umountf "${LOCATION}/mountdir"
indicate_ok
;;
2023-11-07 17:23:39 +01:00
*)
log_error "--mount or --unmount required"
2023-11-08 19:47:37 +01:00
exit 1
;;
esac