# common routines shared by the dpkg-mountable scripts -*- perl -*-
# $Id: generic,v 1.2.2.1 1998/07/28 22:15:01 asm21 Exp $

$boldon=`setterm -bold on`;
$boldoff=`setterm -bold off`;

sub echo {
    my $str=shift;
    print $str . "\n";
}
sub boldecho {
    my $str=shift;
    print "$boldon" . $str . "$boldoff\n";
}

# run a command via the system() call, and return it's exit status
sub syscmd {
    my $cmd=shift;
    return !((system($cmd) & 0xff00) >> 8);
}

$umount=0;
sub domount {
    my $rootfslink=(-l $::rootfs ? readlink($::rootfs) : $::rootfs);
    if (!grep(/$::rootfslink/,`mount`)) {
	echo "Mounting filesystem $::rootfs ...";
	syscmd("mount $::rootfs") or die "Cannot mount root installation filesystem";
	$umount=1;
    }
}

sub doumount {
    if ($umount) {
	echo "Unmounting filesystem $::rootfs ...";
	syscmd("umount $::rootfs") or die "Cannot umount root installation filesystem";
    }
}

sub waitkey {
    my $inv;
    my $str=shift;
    if (!defined($str)) {
	echo "Press [RETURN] to continue.";
    } else {
	echo $str . " Press [RETURN] to continue.";
    }
    $inv=<STDIN>;
    return $inv;
}

1;
