#!/bin/sh
# Debian standard handling
set -e
case $1 in
abort-*) exit 0;;
esac

# 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

# Get and link the cdrom device
if [ ! -b /dev/cdrom ]
then
	db_get workman/which_device
	DEVICE="$RET"
	# I dont trust debconf so that I add two checks
	DEFAULT='/dev/hdc'
	if [ -z "$DEVICE" ]; then DEVICE="$DEFAULT" ; fi
	if [ "$DEVICE" = '/dev/cdrom' ]; then DEVICE="$DEFAULT" ; fi
	# Now the actual link is made
	if ln -sf $DEVICE /dev/cdrom
	then 
	  true 
	else
	  db_input high workman/cdrom_link_failed || true
	fi
	db_go
fi

# change group to cdrom
if chgrp --dereference cdrom /dev/cdrom
then
  true
else
  db_input high workman/cdrom_gid_failed || true
fi
db_go

# allow full access by cdrom
if chmod g+rwx /dev/cdrom
then
  true
else
  db_input high workman/cdrom_perm_failed || true
fi
db_go

# Update menus
if [ -x /usr/bin/update-menus ]; then update-menus; fi
