⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quickcam.sh

📁 在Linux下用于webeye的摄像头的驱动
💻 SH
📖 第 1 页 / 共 2 页
字号:
		echo ".config file, which has to be copied somewhere else to keep safe."		echo "I can also try to do this automatically, in which case"		echo "just keep pressing enter, otherwise abort now."		askreturn		echo "You want me to configure the kernel automatically. All right."		echo "If the kernel configuration file doesn't match exactly the"		echo "kernel source, you will be asked some questions."		echo "This is not a good sign, but if the difference is very small"		echo "(maybe a few unimportant questions) it still might work."		echo "Usually you can just select the default answer for the questions."		askreturn		if [ ! -w "$KERNEL_SOURCE" ]; then			echo "You don't have write permission to the kernel source,"			echo "so I must obtain root access to configure it. Type"			echo "the root password now (Ctrl+D to cancel):"			QCINSTCMD="conf" KERN_PATCHLEVEL="$KERN_PATCHLEVEL" LINUX_DIR="$LINUX_DIR" su -p -c "$0"		else			configurekernel		fi		KERNELOK="y"		if [ ! -r "$KERNEL_SOURCE/include/linux/version.h" ]; then			echo "[!] Can still not find version.h in kernel source."			KERNELOK="n"		fi		if [ ! -r "$KERNEL_SOURCE/include/linux/autoconf.h" ]; then			echo "[!] Kernel source is still not configured properly."			KERNELOK="n"		fi		if [ "$KERNELOK" != "y" ]; then			echo "[!] Kernel configuration failed."			echo "Check if you got any special messages above."			askreturnfail		fi	else		echo "You have only kernel headers but they are not configured"		echo "properly. It's pointless trying to continue, this won't work."		echo "Either install properly configured kernel headers or full"		echo "source with kernel configuration file. In the latter case"		echo "I can configure the kernel source using the configuration"		echo "file automatically."		askreturnfail	fifiKERNEL_VERSION="`make | grep 'Kernel version code' | tail -n 1 | awk -F : '{print $2}' | awk '{print $1}'`"KERNEL_UTS=`awk -F \" '/[ 	]*\#[ 	]*define[ 	]*UTS_RELEASE[ 	]*/ { print $2 }' "$KERNEL_SOURCE/include/linux/version.h"|tail -n 1`MODULE_NAME="`make | grep 'Driver file name' | tail -n 1 | awk -F : '{print $2}' | awk '{print $1}'`"INSTALL_DIR="`make | grep 'Module install directory' | tail -n 1 | awk -F : '{print $2}' | awk '{print $1}'`"export MODULE_NAMEUTS_COUNT=`grep UTS_RELEASE < "$KERNEL_SOURCE/include/linux/version.h" | wc -l`if [ $? != 0 ]; then UTS_COUNT=0; fiif [ $UTS_COUNT -ne 1 ]; then	echo "[!] Multiple kernel versions specified in linux/version.h"	echo "This is probably a heavily modified Red Hat or other distributor"	echo "kernel, and the kernel version check doesn't work."	echo "So we can not check if your kernel version is correct, so we"	echo "must just hope so."	askreturnfiecho "Kernel version name: $KERNEL_UTS"echo "Kernel source version code: $KERNEL_VERSION"echo "Driver file name: $MODULE_NAME"echo "Module install directory: $INSTALL_DIR"if [ "$KERNEL_VERSION" -ge "$KERNEL26X" -a "$HAVEFULLSRC" != "y" ]; then	echo "[!] Not complete kernel 2.6.x source found (possibly just headers)"	echo "Remember that pure headers for 2.6.x kernel are not sufficient."	askreturnfailfi# Hmm, it appears that we don't actually need write permission even if not using O= option#if [ "$KERNEL_VERSION" -ge "$KERNEL26X" -a ! -w "$KERNEL_SOURCE/Makefile" ]; then#	echo "[!] You have 2.6.x version kernel but not write permissions"#	echo "to the source code. For 2.6.x the driver installation"#	echo "requires write access to the kernel sources."#	askreturnfail#fiif [ $UTS_COUNT = 1 -a "$KERNEL_UTS" != "`uname -r`" ]; then	echo "[!] Kernel source version mismatch."	echo "This script assumes that the running kernel should be same as"	echo "the kernel sources against which the driver will be compiled,"	echo "but they don't seem to be."	echo "Kernel source is \"$KERNEL_UTS\" but running kernel is \"`uname -r`\"."	echo "You may need to do \"make bzImage\" to correct this error."	askreturnfailfiif [ "$KERNEL_VERSION" -lt "131602" ]; then	echo "[!] You have older kernel than 2.2.18, it is not supported."	askreturnfailfimake | grep ':' | tail -n 7echo $DEPMODVER | grep module-init-tools >/dev/nullDEPMOD_MIT=$?echo $INSMODVER | grep module-init-tools >/dev/nullINSMOD_MIT=$?echo $RMMODVER | grep module-init-tools >/dev/nullRMMOD_MIT=$?echo $MODPROBEVER | grep module-init-tools >/dev/nullMODPROBE_MIT=$?if [ "$KERNEL_VERSION" -ge "$KERNEL26X" ]; then	if [ $DEPMOD_MIT != 0 -o $INSMOD_MIT != 0 -o $RMMOD_MIT != 0 -o $MODPROBE_MIT != 0 ]; then		echo "[!] Using modutils with 2.6.x kernel."		echo "2.6.x requires newer module-init-tools."		echo "WARNING!! Using old rmmod with 2.6.x kernel may crash the computer!"		askreturnfail	fielse	if [ $DEPMOD_MIT = 0 -o $INSMOD_MIT = 0 -o $RMMOD_MIT = 0 -o $MODPROBE_MIT = 0 ]; then		echo "[!] Using module-init-tools with 2.4.x/2.2.x kernel."		echo "These kernels require older modutils."		askreturnfail	fifi# }}}# {{{ [fold] Load modules if necessaryecho ""echo "The QuickCam driver requires other drivers from kernel."echo "I'll now check if those seem to be loaded."askreturncheckvideo() {	cat /proc/modules | awk '{print $1}' | grep '^videodev' >/dev/null	MOD_VID=$?	cat /proc/devices | grep ' video_capture$' >/dev/null	DEV_VID=$?	if [ $MOD_VID != 0 -a $DEV_VID != 0 ]; then		echo "[!] Linux video driver appears to be not loaded."		echo "You could load it as root with command:"		echo "	modprobe videodev"		echo "(but I can do it for you automatically)"		return 1	fi	if [ $DEV_VID = 0 ]; then		NUM_VID="`cat /proc/devices | grep ' video_capture$' | awk '{print $1}'`"		if [ "$NUM_VID" != "81" ]; then			echo "[!] Video device is loaded but it has unusual major number $NUM_VID."			echo "This may cause problems."			askreturn		fi	fi	return 0}checkusb() {	cat /proc/modules | awk '{print $1}' | egrep '(^uhci|^usb-uhci|^usb-ohci)' >/dev/null	MOD_HCD=$?	if [ -d /proc/bus/usb ]; then PROCFS_USB=0; else PROCFS_USB=1; fi	cat /proc/devices | grep ' usb$' >/dev/null	DEV_USB=$?	LSUSBOUT="`$LSUSB 2>&1`"	LSUSBOK=$?	echo "$LSUSBOUT" | grep 'Permission denied' >/dev/null	if [ $? = 0 -o "$LSUSBOUT" = "" ]; then		LSUSBOK=1	fi	echo "$LSUSBOUT" | grep 'No such file or directory' >/dev/null	if [ $? = 0 ]; then		LSUSBOK=1	fi	if [ $MOD_HCD != 0 -a $LSUSBOK != 0 ]; then		echo "[!] USB host driver appears not to be loaded."		echo "If your computer is typical PC with modularized UHCI or OHCI,"		echo "you probably should issue the following commands:"		echo "	modprobe uhci || modprobe usb-uhci || modprobe usb-ohci"		echo "as root and retry. I can also do this automatically"		echo "for testing purposes, but the modules need to be reloaded"		echo "after each reboot."	fi	if [ $DEV_USB != 0 -a $LSUSBOK != 0 ]; then		echo "[!] USB driver doesn't appear to be installed."		return 1	fi	if [ $LSUSBOK != 0 ]; then		echo "[!] lsusb ($LSUSB) doesn't work. Maybe USB filesystem is not mounted."		echo "To mount it, do"		echo "	mount none /proc/bus/usb -t usbdevfs"		echo "as root, or insert line"		echo "	none /proc/bus/usb usbdevfs defaults 0 0"		echo "into /etc/fstab, and do command"		echo "	mount -a"		echo "as root."		echo "Another possibility is that you're using too old version of lsusb,"		echo "which would require root permissions to list USB devices."		echo "In this case, don't worry, we just can't check if your camera"		echo "is supported (but you can do it manually as root)."		echo "Without lsusb, I can not detect automatically your camera."		return 1	fi	return 0}echo "Modules loaded into the kernel:"cat /proc/modules | awk '{print $1}' | tr '\n' ' 'echo ""cat /proc/modules | awk '{print $1}' | egrep '(^quickcam|^mod_quickcam)' >/dev/nullif [ $? = 0 ]; then	echo "[!] The QuickCam driver is already loaded!"	echo "You should first remove the (old?) module by issuing"	echo "	rmmod mod_quickcam || rmmod quickcam"	echo "as root, otherwise I will fail to install the new module."	echo "I will now try to unload it for you automatically,"	echo "if you just give me the root password (Ctrl+D to cancel):"	QCINSTCMD="unload" su -p -c "$0"ficat /proc/modules | awk '{print $1}' | egrep '(^quickcam|^mod_quickcam)' >/dev/nullif [ $? = 0 ]; then	echo "[!] QuickCam driver failed to unload."	echo "It is not possible to install new version before unloading"	echo "the older version. Check that no application is using the"	echo "camera, using e.g."	echo "	lsof /dev/video0"	echo "or whatever is the camera device file."	askreturnfailficheckvideoVIDEO_OK=$?checkusbUSB_OK=$?if [ $VIDEO_OK != 0 -o $USB_OK != 0 ]; then	echo "I will now try to load the missing modules."	echo "Type root password and press Enter (or Ctrl+D to abort)."	QCINSTCMD="mod" su -p -c "$0"	echo "Modules loaded now into the kernel:"	cat /proc/modules | awk '{print $1}' | tr '\n' ' '	echo ""	checkvideo	VIDEO_OK=$?	checkusb	USB_OK=$?fiif [ $VIDEO_OK != 0 -o $USB_OK != 0 ]; then	echo "[!] Failed again. I did not succeed loading the necessary drivers."	askreturnfailfi# }}}# {{{ [fold] Detect cameraecho ""echo "Next round: let's see if you have a supported QuickCam."echo "Please plug in your USB camera before continuing."askreturnecho "I can find the following probably compatible devices:"$LSUSB | grep -i 'ID 046d:' | egrep '(:0840 |:0850 |:0870 )'FOUNDCAM=$?if [ $FOUNDCAM != 0 ]; then	echo "[!] Didn't find compatible cameras."	echo "If you got message: \"Permission denied\", it means that"	echo "you simply have too old lsusb, and you can ignore this problem."	echo "In this case you have to be root to use lsusb, but I won't do that."	askreturnfailfi# }}}# {{{ [fold] Compilationecho ""echo "Another round done. Let's now compile the driver, it takes a while."echo "This step will also clear old unnecessary files from the directory."askreturnmake clean && make allls -la "$MODULE_NAME"if [ ! -r "$MODULE_NAME" ]; then	echo "[!] Looks like the driver compilation failed."	echo "Did you get any error messages above?"	echo "If asking for help, show what error messages you got."	askreturnfailfiif [ ! -x ./qcset ]; then	echo "[!] Looks like compilation of the utility programs failed."	askreturnfailfi# }}}# {{{ [fold] Load and check camera device fileecho ""echo "Now everything should be well and the driver compiled."echo "Let's then try actually loading the fresh driver and testing"echo "if it works."askreturnecho "To load the driver, I need to know the root password."QCINSTCMD="load" su -p -c "$0"cat /proc/modules | awk '{print $1}' | egrep '(^quickcam)' >/dev/nullif [ $? != 0 ]; then	dmesg	echo "[!] The QuickCam driver failed to load!"	echo "If you saw any special error messages, like about"	echo "unresolved symbols, tell about them when asking for help."	askreturnfailfiecho "The driver detected the following supported cameras:"dmesg | grep '^quickcam'if [ $? != 0 ]; then	echo "[!] No cameras detected."	echo "Try unloading and reloading the driver manually with"	echo "	rmmod quickcam; insmod ./$MODULE_NAME debug=-1"	echo "and then checking whether there are any messages indicating"	echo "problems with command"	echo "	dmesg"	askreturnfailfiVIDEODEV=`dmesg | awk '/^quickcam: Registered device:/ { print $4 }' | head -n 1`VIDEODEV_REAL="`$REALPATH $VIDEODEV`"echo "I will be using $VIDEODEV, if there are more cameras I'll not test them."askreturnecho "Testing if $VIDEODEV is correct."ls -la "$VIDEODEV"if [ "$VIDEODEV" != "$VIDEODEV_REAL" ]; then	ls -la "$VIDEODEV_REAL"	echo "$VIDEODEV is a symbolic link to $VIDEODEV_REAL."fiif [ ! -r $VIDEODEV_REAL -o ! -w $VIDEODEV_REAL ]; then	echo "[!] You don't have read/write access to $VIDEODEV."	echo "On many distributions, you should add yourself into the"	echo "\"video\" group by giving command"	echo "	adduser `whoami` video"	echo "and then log in again to be able to access the video."	echo "A quick alternative is just to do"	echo "	chmod a+rw $VIDEODEV_REAL"	askreturnfailfiVIDEODEV_MAJ=`ls -la "$VIDEODEV_REAL" | awk '{print $5}' | tr -d ','`VIDEODEV_MIN=`ls -la "$VIDEODEV_REAL" | awk '{print $6}'`if [ "$VIDEODEV_MAJ" != "81" ]; then	echo "[!] $VIDEODEV_REAL major number is $VIDEODEV_MAJ."	echo "Usually it should be 81, so there are problems ahead."	askreturnfailfiCAMERA_MIN=`echo $VIDEODEV | sed 's,.*/[^0-9]*\([0-9]*\),\1,g'`if [ "$CAMERA_MIN" != "$VIDEODEV_MIN" ]; then	echo "[!] Bad minor number $VIDEODEV_MIN in $VIDEODEV_REAL, should be $CAMERA_MIN."	echo "To correct this problem, remove the bad file $VIDEODEV_REAL and"	echo "recreate it with mknod-command (read man mknod). Example:"	echo "	rm -f $VIDEODEV"	echo "	mknod $VIDEODEV c 81 $CAMERA_MIN"	echo "	chmod a+rw $VIDEODEV"	askreturnfailfi# }}}# {{{ [fold] Final testecho ""echo "Right now driver is loaded and should be ready to run."echo "Let's test if user applications can see it, starting with qcset."askreturn./qcset "$VIDEODEV" -i | head -n 1 | grep 'Logitech QuickCam USB'if [ $? != 0 ]; then	echo "[!] qcset did not found the QuickCam camera"	askreturnfailfiecho "If you like, you can quit now and start using the camera -"echo "you have good chances that it works, if no problems were detected."echo "If you have X Window System running and xawtv installed,"echo "I can now run it automatically for you."echo "You will then also have opportunity to install the driver permanently."askreturnxdpyinfo 2>&1 >/dev/nullif [ $? != 0 ]; then	echo "[!] Looks like you don't have X Window System running."	echo "It is necessary for testing the camera."	askreturnfailfiecho "Launching xawtv (press q on xawtv window to quit it)..."echo "If the image is not sharp, try focusing it by turning the"echo "wheel around the camera lens."echo "	xawtv -noscale -noxv -c \"$VIDEODEV\""xawtv -noscale -noxv -c "$VIDEODEV"# }}}# {{{ [fold] Final installecho ""echo "Well, did it work, did you get a picture?"echo "If you did, you might now want to install the driver"echo "permanently. Just proceed to do that..."askreturnecho "Just an extra warning: the driver ($MODULE_NAME) and"echo "the utility (qcset) will be now copied into system"echo "directories. If you have already other versions,"echo "they will be overwritten. Verify by giving root password."QCINSTCMD="inst" su -p -c "$0"if [ ! -f "$INSTALL_DIR/misc/$MODULE_NAME" ]; then	echo "[!] Module install failed to $INSTALL_DIR/misc/$MODULE_NAME"	askreturnfailfiecho "Hopefully the driver is now installed and can be loaded"echo "with command"echo "	modprobe quickcam"echo "as root. You can put this command into some startup"echo "script to do it always automatically at boot."echo "The exact location depends on distribution, and this"echo "script is yet too dumb to do this automatically."askreturn# }}}echo "Goodbye..."exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -