androot/mount.sh

60 lines
1.8 KiB
Bash
Raw Normal View History

2023-11-07 17:23:39 +01:00
#!/bin/bash
# shellcheck disable=SC2181 disable=SC1091 disable=SC2236
# shellcheck disable=SC2068
source "${TMPDIR}/androot.source"
source "${TMPDIR}/androot.env"
log_diag "mount is now executing, with arguments \"${*}\""
function mount_fail() {
echo "#### mount ${1}" &>> "${TMPDIR}/androot.log"
shift
mount ${@} &>> "${TMPDIR}/androot.log"
if [ ! "${?}" == "0" ]; then
log_fail
exit 1
fi
}
function unmount_fail() {
echo "#### unmount ${1}" &>> "${TMPDIR}/androot.log"
shift
umount ${@} &>> "${TMPDIR}/androot.log"
if [ ! "${?}" == "0" ]; then
log_fail
exit 1
fi
}
case "${1}" in
"--mount")
log_diag "Using mount mode"
mkdir -p "${LOCATION}/mountdir"
if [ "${IS_ANDROID}" == "true" ]; then
log_exec "Remounting /data"
mount_fail "/data (remount)" "/data" -o remount,suid,exec
log_ok
fi
log_exec "Mounting rootfs"
mount_fail "rootfs" --bind "${LOCATION}/rootfs" "${LOCATION}/mountdir" -o rw,suid,dev,exec,auto,nouser,async
log_ok
log_exec "Binding directories"
mount_fail "/dev" --bind "/dev" "${LOCATION}/mountdir/dev"
mount_fail "/dev/pts" --bind "/dev/pts" "${LOCATION}/mountdir/dev/pts"
mount_fail "/sys" --bind "/sys" "${LOCATION}/mountdir/sys"
mount_fail "/proc" --bind "/proc" "${LOCATION}/mountdir/proc"
log_ok;;
"--unmount")
log_diag "Using unmount mode"
log_exec "Unmounting binds"
unmount_fail "/dev/pts" "${LOCATION}/mountdir/dev/pts"
unmount_fail "/dev" "${LOCATION}/mountdir/dev"
unmount_fail "/sys" "${LOCATION}/mountdir/sys"
unmount_fail "/proc" "${LOCATION}/mountdir/proc"
log_ok
log_exec "Unmounting rootfs"
unmount_fail "rootfs" "${LOCATION}/mountdir"
log_ok;;
*)
log_error "--mount or --unmount required"
exit 1;;
esac