#!/bin/bash
set -euo pipefail

FS=$1

if [[ -z "$FS" ]]; then
    echo "Must pass build chroot path"
    exit 1
fi

umount_if_mounted() {
    if mountpoint -q "$1"; then
        umount "$1"
    fi
}

umount_if_mounted "$FS/run"
umount_if_mounted "$FS/sys"
umount_if_mounted "$FS/proc"
umount_if_mounted "$FS/dev/pts"
umount_if_mounted "$FS/dev"
