#! /bin/sh # # udftools # Call pktsetup to set up packet device associations # # chkconfig: 2345 99 01 # description: udftools packet writing # processname: udftools # # Based on /etc/rc.d/scripts/idetune # Based on udftools.init script from Debian unstable # written by LAKostis ### ### --- 12 Aug 2005 --- ### modified by Arioch ( mailto:the_Arioch@nm.ru xmpp:arioch@jabber.ru ) ### fixed: var $DESC was not initialised ### fixed: /sbin/service added to usage help (TO DO: take it from $0 ?) ### fixed: redudant if's and loops encapsulated into subroutines ### fixed: screen output for start and stop is more pretty now (i think so) ### TO DO: check_kernel() is not to be ALT-specific. Hows to do it in generic way? ### TO DO: use /var/lock/subsys/udftools to say of it was we who insmod'ed ### pktcdvd.ko, then rmmod it on service stop ### TO DO: enumerate CD-ROMs instead of forcing user to tune $DEFAULTFILE ### fixed? if any of numerous [un]mapping would fail - the whole script would fail # # Original Debian copyrights goes here # # Written and Copyright 2003 Richard Atterer debian.org>, GPLv2. # * Thanks to Aleksandar Topuzovic fer.hr> for an # initial version of the script. # * Thanks to Cyrille Chépélov chepelov.org> for additional # help with the specifics of 2.6 packet writing. # * Thanks to Christopher Martin utoronto.ca> # for fixes to make things work on systems that have "no udev + new # interface" or "udev + old interface" WITHOUT_RC_COMPAT=1 RETVAL=0 DESC="packet burning for CD-RW" # Source function library. . /etc/init.d/functions # in ALTLinux only wks* and std26-* kernel have packet writing support check_kernel() { local flavor local kver local valid=0 flavor=`/bin/uname -r|/bin/cut -d- -f2` kver=`kernelversion_minor` [ "$kver" -gt 5 ] && `egrep -qs '(std|wks)26' "$flavor"` [ "$kver" -eq 4 ] && `egrep -qs 'wks' "$flavor"` valid=$? echo "$valid" } PATH=/sbin:/bin:/usr/sbin:/usr/bin DEFAULTFILE=/etc/sysconfig/udftools DEVICES="" NEWINTNAMES="0 1 2 3" UDEVNAMES="/dev/pktcdvd/0 /dev/pktcdvd/1 /dev/pktcdvd/2 /dev/pktcdvd/3" UDEV="" NEWINT="" PKTSETUP=/usr/bin/pktsetup if test -e /dev/.devfsd; then OLDINTNAMES="/dev/pktcdvd/0 /dev/pktcdvd/1 /dev/pktcdvd/2 /dev/pktcdvd/3" else OLDINTNAMES="/dev/pktcdvd0 /dev/pktcdvd1 /dev/pktcdvd2 /dev/pktcdvd3" fi ### if test -f "$DEFAULTFILE"; then ### # Read user settings ### . "$DEFAULTFILE" ### fi SourceIfNotEmpty "$DEFAULTFILE" ### is it supposed to override #PKTSETUP ? ### if no - next check better to be at top of the script - faster exit ;-) [ -x "$PKTSETUP" ] || exit 0 [ "`check_kernel`" -eq 1 ] || exit 0 # Only execute modprobe if DEVICES set - avoid possible problems with # the module for people who don't use packet writing. if test -n "$DEVICES"; then modprobe pktcdvd || true if test -z "$NEWINT"; then # User did not set NEWINT, try auto-detection if [ `/sbin/kernelversion_minor` -eq 6 ] && [ `/bin/uname -r|/bin/cut -d- -f1|/bin/cut -d. -f3` -ge 8 ]; then NEWINT=true else NEWINT=false fi fi if test -z "$UDEV"; then # User did not set UDEV, try auto-detection if grep -E -q "^[^[:space:]]+ /dev tmpfs" /proc/mounts; then UDEV=true else UDEV=false fi fi fi ECHO_PREFIX=" " if $NEWINT; then ECHO_PREFIX="$ECHO_PREFIX /dev/pktcdvd/" fi local_MapDrive() { # $1 - new packet device, $2 - corresponding block device action "$ECHO_PREFIX$1 ==> $2" "$PKTSETUP \"$1\" \"$2\" " return $? } local_UnmapDrive() { # $1 - packet device to detach from block device $2 action "$ECHO_PREFIX$1 -X- $2" "$PKTSETUP -d \"$1\" " return $? } local_DevicesLoop() { # $1 - action-function local FN=$1 local err_cnt=0 if $NEWINT; then set $NEWINTNAMES else if $UDEV; then set $UDEVNAMES else set $OLDINTNAMES fi fi for DEVICE in $DEVICES; do $FN "$1" "$DEVICE" || err_cnt=1 # not supported by /bin/sh: $((err_cnt++)) shift done return $err_cnt }; dostart() { if test -z "$DEVICES"; then echo -n "Not starting $DESC: No devices listed in $DEFAULTFILE" echo_passed else echo "Starting $DESC:" local_DevicesLoop local_MapDrive fi RETVAL=$? return $RETVAL } dostop() { if test -z "$DEVICES"; then echo -n "Not stopping $DESC: No devices listed in $DEFAULTFILE" echo_passed else echo "Stopping $DESC:" local_DevicesLoop local_UnmapDrive fi RETVAL=$? return $RETVAL } case "$1" in start) dostart;; stop) dostop;; status) $PKTSETUP -s || true;; restart|force-reload) dostop; dostart;; *) msg_usage "/sbin/service ${0##*/} {start|stop|restart|force-reload|status}" RETVAL=1 esac exit $RETVAL