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

📄 quickcam.sh

📁 在Linux下用于webeye的摄像头的驱动
💻 SH
📖 第 1 页 / 共 2 页
字号:
#!/bin/sh# {{{ [fold] Copyright blaablaas## qc-usb, Logitech QuickCam video driver with V4L support# Derived from qce-ga, linux V4L driver for the QuickCam Express and Dexxa QuickCam## quickcam.sh - Automated driver build and installation system## Copyright (C) 2003-2004  Tuukka Toivonen## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA### }}}# {{{ [fold] Helper functionsKERNEL26X=132608askreturn() {	echo -n "Press Ctrl+C to quit, Enter to continue ---> "	read x	echo ""}askreturnfail() {	echo "WARNING: If you press Enter, I'll try to continue anyway,"	echo "but this probably will fail. You SHOULD press Ctrl+C now."	askreturn}checkprogs() {	ret=0	while [ "$1" != "" ]; do		if which "$1"; then			true		else			echo "Warning: $1 missing"			ret=1		fi		shift	done	return $ret}findprog() {	P="`which "$1" || which "/sbin/$1" || which "/usr/sbin/$1" || which "/usr/local/bin/$1" || which "/usr/local/sbin/$1"`"	if [ $? != 0 ]; then		echo "[!] Couldn't find program $1"		askreturnfail	else		echo "Found program $P"	fi}qcrealpath() {	P="$1"	while [ -L "$P" ]; do		P="`readlink -f -n "$P"`"	done	if [ ! -e "$P" ]; then		return 1	fi	echo "$P"	return 0}configurekernel() {	if [ "$KERN_PATCHLEVEL" -ge "6" ]; then		(cd "$LINUX_DIR" && make oldconfig && make modules_prepare)	elif [ "$KERN_PATCHLEVEL" -le "4" ]; then		(cd "$LINUX_DIR" && make oldconfig && make dep)	else		echo "[!] Unknown kernel patchlevel $KERN_PATCHLEVEL"		return 1	fi	if [ "$?" != "0" ]; then		echo "[!] Kernel configuration failed, see messages above."		askreturnfail		return 1	fi	return 0}# }}}# {{{ [fold] Special root codeif  [ "$QCINSTCMD" != "" ]; then	if [ "`whoami`" != "root" ]; then		echo "[!] Root mode failed, bug in the script?"		askreturnfail		exit 1	fi	echo "=== Entering root mode ==="	R=0	if [ "$QCINSTCMD" = "conf" ]; then		echo "Trying to configure kernel source as root..."		configurekernel		R="$?"	elif [ "$QCINSTCMD" = "mod" ]; then		# Load necessary modules		echo "Now you will see some error messages."		echo "They are probably harmless and you can ignore them"		echo "(until leaving root mode)."		$MODPROBE usbcore		$MODPROBE usb-uhci || $MODPROBE uhci || $MODPROBE uhci_hcd		$MODPROBE usb-ohci || $MODPROBE ohci_hcd		$MODPROBE hc_sl811		$MODPROBE videodev		$MOUNT none /proc/bus/usb -t usbdevfs	elif [ "$QCINSTCMD" = "load" ]; then		# Load qc-usb driver		if [ -w /proc/sys/kernel/sysrq ]; then			echo ""			echo "I will now try to enable the SysRq key."			echo "If your computer crashes, you can try pressing:"			echo "	Alt + SysRq + S: Emergency Sync (write everything on hard disk)"			echo "	Alt + SysRq + U: Unmount all harddisks"			echo "	Alt + SysRq + B: Reboot system immediately"			askreturn			echo "1" >/proc/sys/kernel/sysrq		fi		echo "Now I finally will try to load the module."		echo "If you're unlucky, your computer might crash right now!!!!"		echo "Consider long if you really want to continue."		askreturn		echo "You decided to do it, here we go..."		dmesg -c >/dev/null		$INSMOD "./$MODULE_NAME"	elif [ "$QCINSTCMD" = "unload" ]; then		echo "Trying to unload QuickCam driver..."		$RMMOD quickcam || $RMMOD mod_quickcam	elif [ "$QCINSTCMD" = "inst" ]; then		# Install driver and utilities		make install	fi	echo "=== Leaving root mode ==="	exit $Rfi# }}}# {{{ [fold] Greet messagesecho "-=- Logitech QuickCam USB camera driver installer -=-"echo "Hello! I am the (hopefully) easy-to-use, fully automated"echo "qc-usb driver installation script."echo "At the moment, this is experimental, and if it doesn't work,"echo "don't hesitate to quit this with Ctrl+C and install the"echo "driver manually."echo ""echo "The driver is provided in source code form, so it has to be"echo "compiled. This should happen automatically, but it does mean"echo "that there are some steps required before installation."echo ""echo "You also need to know \"root\" user password to test and"echo "install the driver."echo ""echo "Basically you need only to keep hitting Enter whenever you"echo "see this prompt: --->. Sometimes you're asked root password."echo "Pay special attention to lines beginning with [!]."echo "It means that some trouble has been detected."echo ""echo "To most important location is the path to your kernel source"echo "or headers. This can be guessed, but you can specify it by"echo "giving it as an argument to this script like this:"echo "	./quickcam.sh LINUX_DIR=/usr/src/linux"echo ""#echo "Other possible parameters, for which the default values should"#echo "be good, are MODULE_DIR= for kernel module directory,"#echo "PREFIX= for utility program directory, USER_OPT= for special"#echo "driver parameters, and CC= for C compiler."#echo ""echo "If you haven't done it yet, now it would be a good moment to"echo "take a look at file README."# }}}# {{{ [fold] Evaluate parameterswhile [ "$1" != "" ]; do	echo "Argument found: $1"	eval "$1"	shiftdoneif [ "$LINUX_DIR" != "" ]; then	export LINUX_DIRfiif [ "$MODULE_DIR" != "" ]; then	export MODULE_DIRfiif [ "$PREFIX" != "" ]; then	export PREFIXfiif [ "$USER_OPT" != "" ]; then	export USER_OPTfiif [ "$CC" != "" ]; then	export CCfiif [ "$LD" != "" ]; then	export LDfi# }}}# {{{ [fold] Test programs and versionsecho ""echo "Next I'm going to check if you have some important programs installed"echo "and if they and the kernel are of suitable version."askreturnif [ "$CC" != "" ]; then	echo "Using specified C compiler from environment CC=$CC"else	CC=gcc; export CCfiif [ "$LD" != "" ]; then	echo "Using specified linker from environment ld=$LD"else	LD=ld; export LDficheckprogs "$0" whoami su ls cat "$CC" gcc make grep egrep awk sed tail head install ld uname tr xawtv xdpyinfo dmesg wcif [ $? != 0 ]; then	echo "[!] Some important programs can not be found on default path."	echo "Probably they aren't installed."	echo "You should install them, for example, by using apt-get or rpm."	askreturnfailfiREALPATH="`which realpath || which /usr/local/bin/realpath`"if [ $? != 0 ]; then	REALPATH="qcrealpath"	which readlink	if [ $? != 0 ]; then		echo "[!] Can not find either program readlink nor realpath."		echo "Either one is required for running this script."		askreturnfail	fifiCCVER="`$CC -v 2>&1|grep -i version`"echo "$CC version: $CCVER"GCCVER="`gcc -v 2>&1|grep -i version`"echo "gcc version: $GCCVER"MKVER="`make -v 2>&1|grep -i make|head -n 1`"echo "Make version: $MKVER"LDVER="`ld -v 2>&1|grep -i ld`"echo "Linker version: $LDVER"echo "$MKVER" | grep GNU >/dev/nullif [ $? != 0 ]; then	echo "[!] Make doesn't appear to be GNU Make."	askreturnfailfiOSNAME="`uname -s`"if [ "$OSNAME" != "Linux" ]; then	echo "[!] You don't appear to have Linux, but $OSNAME."	echo "Other kernels are not supported."	askreturnfailfiif [ ! -r /proc/version ]; then	echo "[!] Virtual file /proc/version is missing."	echo "Maybe procfs is not mounted? Please mount it."	echo "If kernel is configured with procfs support, this can be achieved with"	echo "	mount none /proc -t proc"	askreturnfailfiOSCCVER="`cat /proc/version | sed 's,[^)(]*([^)(]*)[^)(]*(\(.*\))[^)(]*,\1,g'`"echo "Kernel compiler: $OSCCVER"if [ "$OSCCVER" != "$CCVER" ]; then	echo "[!] Kernel compiler and $CC seem to be different versions."	echo "Instead, they should be the same. If you have many compilers"	echo "installed, you can specify the correct one with command (in bash)"	echo "	export CC=kgcc"	echo "before trying to install the driver. Replace kgcc with the command"	echo "required for compiling kernels (kgcc is often used in Red Hat systems)."	askreturnfailfi####echo "Looking for more necessary programs..."findprog depmod   && DEPMOD="$P"findprog insmod   && INSMOD="$P"findprog rmmod    && RMMOD="$P"findprog modprobe && MODPROBE="$P"findprog mount    && MOUNT="$P"findprog lsusb    && LSUSB="$P"export DEPMOD INSMOD RMMOD MODPROBE MOUNTDEPMODVER=`$DEPMOD -V 2>&1 | egrep '(^depmod version |module-init-tools)'`INSMODVER=`$INSMOD -V 2>&1 | egrep '(^insmod version |module-init-tools)'`RMMODVER=`$RMMOD -V 2>&1 | egrep '(^rmmod version |module-init-tools)'`MODPROBEVER=`$MODPROBE -V 2>&1 | egrep '(^modprobe version |module-init-tools)'`if [ "$INSMODVER" = "" ]; then INSMODVER="module-init-tools - something"; fiecho "depmod version: $DEPMODVER"echo "insmod version: $INSMODVER"echo "rmmod version: $RMMODVER"echo "modprobe version: $MODPROBEVER"# }}}# {{{ [fold] Test if we're not root and in the correct directoryecho "Checking whether we're root... `whoami`"if [ "`whoami`" = "root" ]; then	echo "[!] Running script as root."	echo "You shouldn't run this script as root. It should work,"	echo "but is unsafe. Please run this as an ordinary user."	echo "When root access is really needed, you will be prompted"	echo "for the root password."	askreturnfailfiecho "Checking for driver source code..."if [ ! -r ./Makefile -o ! -r ./qc-driver.c ]; then	echo "[!] Driver source not found."	echo "The qc-usb driver source code must be in the current directory,"	echo "but I didn't find it."	askreturnfailfiecho "Checking for write permission..."if [ ! -w . ]; then	echo "[!] Current directory not writable"	echo "You don't seem to have write permission to the current directory"	echo "($PWD)"	askreturnfailfi# }}}# {{{ [fold] Check kernel sourceecho ""echo "Previous round done. Now checking if you have kernel source installed."askreturnKERNEL_SOURCE="`make | grep LINUX_DIR | tail -n 1 | awk -F : '{print $2}' | awk '{print $1}'`"echo "Kernel source directory: $KERNEL_SOURCE"if [ ! -r "$KERNEL_SOURCE/include/linux/videodev.h" ]; then	echo "[!] Can not find kernel source or even headers."	echo "Make sure that they are installed (install with e.g. rpm or apt-get"	echo "if necessary) and ensure that you have read rights to the files."	askreturnfailfiHAVEFULLSRC="y"if [ ! -r "$KERNEL_SOURCE/Makefile" ]; then	HAVEFULLSRC="n"	echo "[!] Kernel headers installed, but not complete source code."	echo "Installation still may work with some architectures like Intel x86,"	echo "but will definitely fail on others. Note that for kernel 2.6.x"	echo "we need always full source code."	askreturnelse	KERN_PATCHLEVEL=`awk -F = '/^PATCHLEVEL *=/ {print $2}' < "$KERNEL_SOURCE/Makefile"|tr -d ' 	'`	KERN_VERSION=`awk -F = '/^VERSION *=/ {print $2}' < "$KERNEL_SOURCE/Makefile"|tr -d ' 	'`	echo "Detected kernel version is $KERN_VERSION.$KERN_PATCHLEVEL.x."	if [ "$KERN_VERSION" != "2" ]; then		echo "[!] Kernel major version is not 2, which is completely something"		echo "not expected. Either it was misdetected or you are using"		echo "not supported kernel version."		askreturnfail	fifiif [ ! -r "$KERNEL_SOURCE/.config" ]; then	HAVEFULLSRC="n"	echo "[!] Kernel configuration file $KERNEL_SOURCE/.config not found."	echo "If the headers have been already configured properly, you might"	echo "not need it. But it would be better not to trust this, you"	echo "really should know where is your configuration file, and"	echo "copy it into its place. Often it can be found in /boot/"	echo "directory with a name like /boot/config-2.4.26 or something."	askreturnfailfiKERNELOK="y"if [ ! -r "$KERNEL_SOURCE/include/linux/version.h" ]; then	echo "[!] Can not find version.h in kernel source."	KERNELOK="n"fiif [ ! -r "$KERNEL_SOURCE/include/linux/autoconf.h" ]; then	echo "[!] Kernel source is not configured properly."	KERNELOK="n"fiif [ "$KERNELOK" != "y" ]; then	if [ "$HAVEFULLSRC" == "y" ]; then		echo "You have full kernel source code but it is not configured"		echo "properly. You can configure it by entering the source"		echo "directory and typing (with 2.2.x and 2.4.x kernel versions)"		echo "	make oldconfig"		echo "	make dep"		echo "or (with 2.6.x kernel versions)"		echo "	make oldconfig"		echo "	make modules_prepare"		echo "It is also good idea to first clean up completely the kernel"		echo "source by typing \"make mrproper\", but this will also delete the"

⌨️ 快捷键说明

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