#!/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=$(awk -v mountpoint="$MOUNT_ROOT/$MOUNTPOINT" '{ if ($2 == mountpoint) {print "yes"; exit }}' /proc/mounts)
    if [ "x$BUSY" = "xyes" ]; then
	continue
    fi

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

exit 0
