home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 February
/
PCWorld_2000-02_cd.bin
/
live
/
sbin
/
detect
< prev
next >
Wrap
Text File
|
1999-11-12
|
8KB
|
304 lines
#!/bin/sh
####################################
#Name : detect
#
#Description: To detect all the hardware on your system
#
#Copyright (C) 1999 Corel Corporation
#
# EXHIBIT A -Corel Public License.
#
# The contents of this file are subject to the Corel Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# linux.corel.com/linuxproducts/corellinux/license.htm.
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# The Original Code is detect.
# The Initial Developer of the Original Code is Corel Corporation.
# Portions created by Corel are Copyright (C) 1999 All Rights Reserved.
# Contributor(s): ______________________________________.
##############################################################
IDEDIRNAME=/proc/ide
SCSIDIRNAME=/proc/scsi
##
#TO DISPLAY THE INFORMATION FOR THE CD-ROM
##
Cdrom_Header()
{
echo "[cdrom.$j]"
echo " " "device = $Cd_Device"
echo " " "driver = $Cd_Driver"
echo " " "model = $Cd_Model"
echo " "
}
##
#TO DISPLAY THE INFORMATION FOR THE HARD-DISK
##
Disk_Header()
{
echo "[disk.$k]"
echo " " "device = $D_Device"
echo " " "driver = $D_Driver"
echo " " "model = $D_Model"
echo " "
}
##
#TO DISPLAY THE INFORMATION FOR SOUND CARD
##
Sound_Header()
{
echo "[sound.1]"
echo " " "driver = $S_Driver"
echo " "
}
##
#TO DISPLAY THE INFORMATION OF THE KEYBOARD
##
Keyboard_Header()
{
echo "[keyboard.1]"
echo " " "driver = us"
echo " "
}
##
#TO DISPLAY THE INFORMATION FOR THE NETWORK
##
Network_Header()
{
echo "[network.1]"
echo -n " " device = $N_Driver
echo " "
}
##
#TO OUTPUT THE INFORMATION OF DEVICES TO /ETC/DEVICES
##
Output_Devices()
{
rm -f /etc/devices.new
rm -f /dev/mouse
cprobe >> /etc/devices.new
Detect_Cdrom >> /etc/devices.new
Detect_Hd >> /etc/devices.new
Keyboard_Header >> /etc/devices.new
pestcontrol >> /etc/devices.new
monprobe >> /etc/devices.new
# clear
}
############################################################
#
# Method: Detect_Hd()
#
# Author: Katerina Tsarouchas August 26 1999
#
# Purpose: To detect what kind of hard-drive you have
# and where it is located.
#
# Copyright 1999 Corel Corporation.
#
############################################################
Detect_Hd()
{
for x in $IDEDIRNAME/hd[abcd]
do
grep -li 'disk' $IDEDIRNAME/hd?/media > /tmp/found_hd 2>/dev/null
done
let k=0
#check to see if the user has an ide hard-drive
if [ -s /tmp/found_hd ]
then
#get where the drive is located
sed -e 's/\/proc\/ide\///' -e 's/\/media//' < /tmp/found_hd > /tmp/hd_variable
Hd_Drive=`cat /tmp/hd_variable`
#loop through each drive and get all the info for it
for j in $Hd_Drive
do
#get the name of the model
head -1 $IDEDIRNAME/$j/model > /tmp/model_file.$j
#get the name of the driver
cut -d' ' -f1 $IDEDIRNAME/$j/driver > /tmp/driver_file.$j
#get the values for device, model and driver
D_Device=/dev/$j
D_Model=`cat /tmp/model_file.$j`
D_Driver=`cat /tmp/driver_file.$j`
if $( dd if=$D_Device of=/dev/null bs=512 count=1 )
then
#get the next drive
let k=$k+1
Disk_Header
fi
rm -rf /tmp/model_file.* /tmp/driver_file.*
done
rm -rf /tmp/found_hd /tmp/hd_file /tmp/hd_variable
fi
#check to see if the user has a scsi hard-drive
if [ -d $SCSIDIRNAME ]
then
ls $SCSIDIRNAME > /tmp/var_driver
head -1 /tmp/var_driver > /tmp/driver_out
D_Driver=`cat /tmp/driver_out`
grep -C Direct-Access $SCSIDIRNAME/scsi > /tmp/access_file
grep -1 Direct-Access /tmp/access_file > /tmp/temp_file
grep -h "Model" /tmp/temp_file > /tmp/file_model
sed -e 's/^.*Model: //' -e 's/Rev.*//' < /tmp/file_model > /tmp/temp_model
#determine what the device is for scsi
for m in /dev/sd?
do
if $(head -c1b $m > /dev/null)
then
set BOOTDEV=$m
let k=$k+1
head -n $k /tmp/temp_model | tail -n 1 > /tmp/Hd_Model.$k
D_Model=`cat /tmp/Hd_Model.$k`
D_Device=$m
Disk_Header
fi
done
rm -rf /tmp/access_file /tmp/temp_file /tmp/driver_out
rm -rf /tmp/temp_model /tmp/file_model /tmp/var_driver /tmp/Hd_Model.*
fi
}
############################################################
#
# Method: Detect_Cdrom()
#
# Author: Katerina Tsarouchas August 26, 1999
#
# Description: Check to see if the user has a cdrom and
# if it is a scsi or an ide.
#
# Copyright 1999 Corel Corporation.
#
############################################################
Detect_Cdrom()
{
#Search to see if the user CD-ROM is an IDE or a SCSI
grep -li 'cd*rom' $IDEDIRNAME/hd?/media > /tmp/found_cdrom 2>/dev/null
let j=0
let g=0
if [ -s /tmp/found_cdrom ]
then
sed -e 's/\/media//' < /tmp/found_cdrom > /tmp/ide_cdrom
var2=`cat /tmp/ide_cdrom`
sed -e 's/\/proc\/ide\///' < /tmp/ide_cdrom > /tmp/ide_var
ide_var=`cat /tmp/ide_var`
rm -f /tmp/found_cdrom
for s in $ide_var
do
cut -d' ' -f1 /$IDEDIRNAME/$s/driver > /tmp/temp_driver.$s
Cd_Driver=`cat /tmp/temp_driver.$s`
head -1 /$IDEDIRNAME/$s/model > /tmp/model_temp.$s
Cd_Model=`cat /tmp/model_temp.$s`
Cd_Device=/dev/$s
let j=$j+1
Cdrom_Header
done
fi
rm -f /tmp/temp_driver /tmp/model_temp /tmp/ide_var /tmp/ide_cdrom
if [ -d $SCSIDIRNAME ]
then
ls $SCSIDIRNAME > /tmp/temp_driver
head -1 /tmp/temp_driver > /tmp/scsi_var
Cd_Driver=`cat /tmp/scsi_var`
grep -C CD-ROM $SCSIDIRNAME/scsi > /tmp/scsi_out
grep -1 CD-ROM /tmp/scsi_out > /tmp/out_file
grep -w "Model" /tmp/out_file > /tmp/MODEL_file
sed -e 's/^.*Model: //' -e 's/Rev.*//' < /tmp/MODEL_file > /tmp/MODEL_name
sed -e 's/Vendor.* //' < /tmp/MODEL_file > /tmp/foo
foofoo=`cat /tmp/foo`
for r in $foofoo
do
let j=j+1
head -n $j /tmp/MODEL_name | tail -n 1 > /tmp/Cd_Model.$j
Cd_Model=`cat /tmp/Cd_Model.$j`
Cd_Device=/dev/scd$g
Cdrom_Header
let g=g+1
done
fi
rm -f /tmp/temp_driver /tmp/scsi* /tmp/out_file /tmp/MODEL* /tmp/foo
}
##
# PURPOSE: TO DETECT PROPRIETARY CD-ROM DRIVES
##
#bpcd cm206 mcd sbpcd cdrom gscd mcdx sjcd"
#modprobe $CD-ROM_List
#for x in $CD-ROM_List
# do
# lsmod | grep &x && echo Found $x
# done
###########################
#
# THE MAIN FUNCTION
#
###########################
if [ $# = 0 ]
then
echo " "
echo "USAGE: detect [boot] or [probe] or [list]"
echo "boot: to load the modules"
echo "probe: to list your hardware of your system and write it to /etc/devices"
echo "list: to list your hardware of your system and write it to standard output"
echo " "
exit 1
else
case "$1" in
boot)
echo " "
lsmod
;;
probe)
echo " "
Output_Devices
if [ -e /etc/devices ]
then
cp /etc/devices /etc/devices.bak
etcdevdiff
else
cp /etc/devices.new /etc/devices
fi
;;
list)
echo " "
if [ -e /etc/devices ]
then
cat /etc/devices
else
Output_Devices
cat /etc/devices.new
fi
esac
fi