LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 02-18-2013, 11:23 PM   #16
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 634
Blog Entries: 2

Rep: Reputation: 97

Quote:
Originally Posted by volkerdi View Post
Here's a simple C program:

Compile it with gcc, call it trayopen. Then you can use it in scripts based on the exit code, like so:

./trayopen /dev/sr0 && echo tray is open || echo tray is closed
If you want trayopen to be a system-wide app you could copy the executable to /usr/local/bin.

Better still, you could make a package out of it. Here is a simple script that will compile the C program and put the output into a package (note: there must be a space after the \ in the slack-desc section).
Code:
#!/bin/sh

# Slackware build script for trayopen


PRGNAM=trayopen
VERSION=${VERSION:-1.0}
BUILD=${BUILD:-1}
TAG=${TAG:-_custom}

# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
       *) ARCH=$( uname -m ) ;;
  esac
fi

CWD=$(pwd)
PKG=$CWD/package-$PRGNAM

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

set -e # Exit on most errors

rm -rf $PKG
mkdir -p $PKG

# Compile the application and install it into the $PKG directory
gcc -o trayopen trayopen.c
mkdir -p $PKG/usr/bin
cp -a trayopen $PKG/usr/bin

# Copy the slack-desc into $PKG/install
mkdir -p $PKG/install

cat > $PKG/install/slack-desc <<_EOF
trayopen: trayopen 
trayopen:
trayopen: A utility that returns the open/closed status
trayopen: of the CD tray.
trayopen:
trayopen: It can be used in a script such as:
trayopen: trayopen /dev/sr0 && echo tray is open \ 
trayopen: || echo tray is closed
trayopen:
trayopen:
trayopen:
_EOF

# Make the package
cd $PKG
/sbin/makepkg -l y -c n $CWD/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}

Last edited by psionl0; 02-18-2013 at 11:26 PM.
 
Old 02-19-2013, 06:10 AM   #17
GazL
Senior Member
 
Registered: May 2008
Posts: 3,503

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
Quote:
Originally Posted by Woodsman View Post
Revision 3 works on all systems here. Good job!

Perhaps if other people with quirky optical drives find the patch useful that might provide some motivation.
As I said above, though it works, I didn't care for the solution in v3 as it felt half-done. I've had a final stab at it.
I had the inspiration that if we do a second call of CDROM_DRIVE_STATUS after the first CDROMEJECT and if it returns CDS_TRAY_OPEN then we know that there is no need to play that ugly elapsed time based "was it open or closed?" guessing game. Simple really. I don't know why it didn't occur to me from the start.

Unlike V3 this one feels 'right' to me and if Pat wanted to include it I wouldn't have any concerns.


Anyway, job done. I enjoyed that little puzzle.

Last edited by GazL; 02-22-2013 at 05:25 PM.
 
Old 02-19-2013, 03:30 PM   #18
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534Reputation: 534
I tested Version 4 and eject -T works for all systems here.

Quote:
Unlike V3 this one feels 'right' to me and if Pat wanted to include it I wouldn't have any concerns.
We can watch the Current changelog to see, heh?

Quote:
Anyway, job done. I enjoyed that little puzzle.
I enjoyed the distraction too. I hope everybody else benefits from the patch.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to detect eth0 status? kakaburra Slackware 10 08-30-2009 03:28 AM
Cdrom tray status freeindy Linux - Hardware 4 09-30-2008 02:30 PM
How can a process detect the status of a signal bluehive Linux - Newbie 5 01-22-2008 01:23 PM
how to auto detect the status of sendmail!!!!!!!!!! dhanju Linux - Networking 5 10-22-2005 07:35 AM
Detect CD tray load mattkat Linux - Hardware 1 05-31-2004 07:00 AM


All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration