Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release-src > by-pkgid > 7f6ecc33a2ac0696d0314e52119a60db > files > 3

udftools-1.0.0-0.b3.21.mga5.src.rpm

#!/bin/bash
#
# pktcdvd This shell script sets up a virtual block device for packet-writing
#
# chkconfig: 345 56 44
# description: This script sets up virtual block devices for packet-writing \
#              You can configure it by editing the file /etc/sysconfig/pktcdvd.
# config: /etc/sysconfig/pktcdvd
#
### BEGIN INIT INFO
# Provides: pktcdvd
# Default-Start: 3 4 5
# Short-Description: Virtual block device for packet-writing
# Description: Virtual block device for packet-writing
### END INIT INFO

[ -f /etc/sysconfig/pktcdvd ] || exit 0
# Exit if the file just has the default comments or blank lines
LC_ALL=C /bin/egrep -q -v "^( *#| *$)" /etc/sysconfig/pktcdvd 2>/dev/null || exit 0

. /etc/init.d/functions

function start_pktcdvd() {
   if [ -d /proc/driver/pktcdvd ]; then
	echo
   	gprintf " pktcdvd module already loaded\n"
   else
	message="Loading pktcdvd module "
	modprobe pktcdvd 2>/dev/null >/dev/null
	if [[ $? != 0 ]];then
	    message="$message failed"
	    RETVAL=1
	else
	    message="$message successfull"
	fi
	logger -t "INIT" $message 
   fi
}

function attach_pktcdvd()
{
   LC_ALL=C egrep -v '^( *#| *$)' /etc/sysconfig/pktcdvd |
   while read PKTCDVD BLOCK; do 
       pktsetup $PKTCDVD $BLOCK >/dev/null && gprintf " %s" "$BLOCK" || err=1
   done ; return $err
}

function dettach_pktcdvd()
{
   LC_ALL=C egrep -v '^( *#| *$)' /etc/sysconfig/pktcdvd | 
   while read PKTCDVD BLOCK; do  
       
       pktsetup -d $PKTCDVD >/dev/null && gprintf " %s" "$BLOCK" || err=1 

   done ; return $err
}

# See how we were called.
case "$1" in
  start)
        # Assign devices
        gprintf "Activating pktcdvd devices:"
	start_pktcdvd
	attach_pktcdvd && success || failure
	echo
        ;;
  stop)

        gprintf "Deactivating pktcdvd devices:"
	dettach_pktcdvd && success || failure
	rmmod pktcdvd 2>&1 >/dev/null
	echo
        ;;

  status)
        ID=`id -u`
        if [ $ID -eq 0 ]; then 
   	LC_ALL=C egrep  'mapped' /proc/driver/pktcdvd/* | cut -f 2 -d ":"
        else
          gprintf "You need to be root to use this command ! \n"
        fi
        ;;

  restart|reload)
        $0 stop
        $0 start
        ;;

  *)
        gprintf "Usage: %s\n" "$(basename $0) {start|stop|status|restart}"
        exit 1
	;;
esac

exit 0