#!/usr/bin/perl

# Don't allow interruption.
$SIG{INT}=$SIG{TERM}=$SIG{HUP}=sub {};

use warnings;
use strict;
use Mooix::Thing;
use Mooix::Root;

if ($< != 0) {
	die "$0 must be run as root\n";
}

sub usage {
	print STDERR <<EOF;
Usage: removeavatar avatardir
EOF
        exit 1;
}

my $dir=shift || usage();
if (! -d $dir) {
	die "$dir does not exist\n";
}

my $obj=Mooix::Thing->get($dir);
if (! ref $obj) {
	die "$dir is not a mooix object";
}

# Remove the object from the sessionmanager's avatars list.
$Mooix::Root->system->sessionmanager->avatars->remove(object => $obj);

$obj->destroy;
