#!/bin/sh
# The script has to ensure that a link /dev/cdrom to the real
# CD-ROM device exists and that the device belongs to the cdrom
# group and is readable and executable by the group
# Workman should not be run suid root !

# Source debconf library.
. /usr/share/debconf/confmodule

db_title 'WorkMan Setup'

SYMDEV='/dev/cdrom'

if [ ! -b "$SYMDEV" ]
then
	DEVICE="$SYMDEV"
	while [ "$DEVICE" = "$SYMDEV" ]
	do
	  DEFAULT='/dev/hdc'
	  db_input high workman/which_device ||true
	  db_go
	  db_get workman/which_device
	  DEVICE="$RET"
# Checks
# a) empty
	  if [ -z $DEVICE ]; then DEVICE=$DEFAULT ; fi
# b) the symbolic link itself
	  if [ $DEVICE = "$SYMDEV" ]
	  then 
	    db_input critical workman/not_physical
	    if [ $? -eq 30 ]; then DEVICE=$DEFAULT ; fi
	    db_go
	  fi
# c) no block device
	  if [ ! -b "$DEVICE" ]
	  then 
	     db_input high workman/no_block_device
	     if [ $? -ne 30 ]
	     then 
		db_input high workman/change_block_device
		db_go
	        db_get workman/change_block_device
		if [ "$RET" = "true" ]; then DEVICE="$SYMDEV"; fi
	     fi
	  fi
	done
fi
