#!/bin/sh

# Copyright (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.

MOUNT_ROOT="/media"

for DIR in $MOUNT_ROOT/*; do
    # check if we created it
    if [ ! -e $DIR/.created-by-hal ]; then
	continue
    fi

    # don't touch mounted volumes
    BUSY=
    while read dev dir type options; do
	if [ "$dir" = "$DIR" ]; then
	    BUSY=1
	    break
	fi
    done < /proc/mounts
    if [ "$BUSY" = "1" ]; then
	continue
    fi

    rm -f $DIR/.created-by-hal
    rmdir --ignore-fail-on-non-empty "$DIR"
done

exit 0
