#!/bin/bash
if [ -z "${1}" ]; then
echo "Usage: $0 CHROOT_DIR [BRANCH_NAME|umount]"
exit 1
fi
chrootdir="${1}"
branchname="${2:-}"
if [ ! -d "${chrootdir}" ]; then
echo "Not dir ${chrootdir}"
exit 1
fi
if [ "$(df -T "${chrootdir}" | tail -n1 | awk '{print $2}')" = "sffs" ]; then
echo "Should not use sffs"
exit 1
fi
function mountfs()
{
mountpoint -q "${chrootdir}/dev" || mount --bind /dev "${chrootdir}/dev"
mountpoint -q "${chrootdir}/dev/pts" || mount -t devpts pts "${chrootdir
mountpoint -q "${chrootdir}/proc" || mount -t proc proc "${chrootdir}/pr
mountpoint -q "${chrootdir}/sys" || mount -t sysfs sys "${chrootdir}/sys
}
function umountfs()
{
mountpoint -q "${chrootdir}/dev/pts" && umount "${chrootdir}/dev/pts"
mountpoint -q "${chrootdir}/dev" && umount "${chrootdir}/dev"
mountpoint -q "${chrootdir}/proc" && umount "${chrootdir}/proc"
mountpoint -q "${chrootdir}/sys" && umount "${chrootdir}/sys"
}
function chroot_run()
{
env -i - LC_ALL=C.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US: LROOT=/root TER
}
if [ "${branchname}" = "umount" ]; then
umountfs
exit 0
fi