# Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ inherit eutils linux-info DESCRIPTION="Kernel-space driver for Alcatel SpeedTouch USB modems (for >=2.6.10 kernels)" HOMEPAGE="http://www.speedtouch.com" At="SpeedTouch330_firmware_3012.zip" SRC_URI="http://www.speedtouch.com/download/drivers/USB/${At}" DOWNLOAD_URL="http://www.speedtouch.com/driver_upgrade_lx_3.0.1.2.htm" # License is shown at http://www.speedtouch.com/driver_upgrade_lx_3.0.1.2.htm LICENSE="SpeedTouch" SLOT="0" # Being a kernel module, this ebuild will work on several arches KEYWORDS="~x86" # Reasonable version of baselayout DEPEND="app-arch/unzip sys-apps/grep sys-apps/coreutils >=sys-apps/baselayout-1.11.13-r1 !net-dialup/speedtouch" # udev replaces hotplug, as mentioned at # http://www.linux-usb.org/SpeedTouch/firmware/firmware.html # hotplug only needs to be *installed*, to create /etc/hotplug/usb/ - it does # not need to be running. RDEPEND=">=net-dialup/ppp-2.4.2-r10 sys-apps/module-init-tools >=sys-apps/hotplug-20040923-r1 >=sys-fs/udev-068-r1" FIRMWARE_VER="3.012" S=${WORKDIR} pkg_config() { einfo "Checking SpeedTouch USB modem" local DETECTION_FAILED=0 local REVISION local FIRMWARE_FILENAME_1="speedtch-ZZZL-1.bin" local FIRMWARE_FILENAME_2="speedtch-ZZZL-2.bin" # Attempt to detect an attached modem if [ -e /proc/bus/usb/devices ]; then REVISION=$(grep '^P: *Vendor=06b9 ProdID=4061 ' \ /proc/bus/usb/devices \ | sed -e 's/.*Rev= *\([^ ]*\)/\1/') if [ ! -z "${REVISION}" ]; then einfo "Modem revision is ${REVISION}" fi case "${REVISION}" in 0.00|2.00) # Old stingray and purple modem einfo "Detected a Stingray/purple (or older silver) modem" FIRMWARE_FILENAME_1="speedtch-KQD6-1.bin" FIRMWARE_FILENAME_2="speedtch-KQD6-2.bin" ;; 4.00) # Modern silver modem einfo "Detected a modern silver modem" ;; *) # Detection failed - assume it's a modern silver modem ewarn "SpeedTouch modem not found in the list of USB devices" DETECTION_FAILED=1 ;; esac else # Failed to detect because /proc/bus/usb/devices not present ewarn "USB Device Filesystem (USB_DEVICEFS) is not enabled in the kernel" DETECTION_FAILED=1 fi if [ ${DETECTION_FAILED} -eq 1 ]; then # Assume a modern silver modem as the default ewarn "Failed to detect attached SpeedTouch device" ewarn "Defaulted to version 4 (modern silver modem)" ewarn "To change the firmware files for an older modem, run:" ewarn "cd /lib/firmware && ln -sfn speedtch-KQD6-1 speedtch-1.bin && ln -sfn speedtch-KQD6-2 speedtch-2.bin" fi # Create symlinks ln -sfn ${FIRMWARE_FILENAME_1} /lib/firmware/speedtch-1.bin ln -sfn ${FIRMWARE_FILENAME_2} /lib/firmware/speedtch-2.bin einfo "Checking kernel modules" # Get kernel version linux-info_pkg_setup # Check kernel version if [ ${KV_MAJOR} -lt 2 ] \ || ([ ${KV_MAJOR} -eq 2 ] && [ ${KV_MINOR} -lt 6 ]) \ || ([ ${KV_MAJOR} -eq 2 ] && [ ${KV_MINOR} -eq 6 ] \ && [ ${KV_PATCH} -lt 10 ]) then eerror "emerge speedtouch instead, for kernel <2.6.10, or upgrade the kernel." eerror "The kernel-space driver does not exist in your current kernel." fi # Check kernel modules # Don't care about PPP_DEFLATE and PPP_BSDCOMP if ! (linux_chkconfig_present PACKET); then ewarn "Recompile the kernel with CONFIG_PACKET=y" fi if ! (linux_chkconfig_present PPPOATM); then ewarn "Recompile the kernel with CONFIG_PPPOATM" fi # Required to grep /proc/bus/usb/devices if ! (linux_chkconfig_present USB_DEVICEFS); then ewarn "Recompile the kernel with CONFIG_USB_DEVICEFS=y" fi if ! (linux_chkconfig_present USB_SPEEDTOUCH); then ewarn "Recompile the kernel with CONFIG_USB_SPEEDTOUCH" fi # ppp must be compiled with atm USE flag if ! built_with_use net-dialup/ppp atm; then eerror "Please emerge ppp with the 'atm' USE flag." fi einfo "Checking manual configuration" # Check for manual configuration which might interfere with the ebuild local RETVAL if [ -e /etc/conf.d/local.start ]; then grep -q "pppd" /etc/conf.d/local.start; RETVAL=$? if [ $RETVAL = 0 ]; then ewarn "pppd is automatically run from /etc/init.d/speedtouch when the modem" ewarn "is plugged in, so please remove it from /etc/conf.d/local.start" fi fi if [ -e /etc/hotplug/usb.usermap ]; then grep -q "4061" /etc/hotplug/usb.usermap; RETVAL=$? if [ $RETVAL = 0 ]; then ewarn "Please remove the SpeedTouch line from /etc/hotplug/usb.usermap" fi fi } src_unpack() { if [ ! -r ${DISTDIR}/${At} ]; then eerror "Cannot read ${At} - please check its permissions." die fi } src_install() { # Unzip archive unzip ${DISTDIR}/${At} -d ${S} &> /dev/null || die "Failed during unzipping of ${DISTDIR}/{At}" local ADSL_FILE_NAME="adsl" if [ -e "/etc/ppp/peers/${ADSL_FILE_NAME}" ]; then # Same filename as in old 'speedtouch' ebuild ADSL_FILE_NAME="adsl.sample" ewarn "Compare /etc/ppp/peers/adsl against 'adsl.sample'" fi einfo "Extracting firmware files" # Extract the "stage 1" portion of the firmware dd if=${S}/KQD6_${FIRMWARE_VER} of=${S}/speedtch-KQD6-1.bin \ ibs=1 obs=991 count=991 skip=36 &> /dev/null \ || die "Extraction of stage 1 firmware (step 1) failed" dd if=${S}/ZZZL_${FIRMWARE_VER} of=${S}/speedtch-ZZZL-1.bin \ ibs=1 obs=935 count=935 skip=32 &> /dev/null \ || die "Extraction of stage 1 firmware (step 2) failed" # Extract the "stage 2" portion of the firmware dd if=${S}/KQD6_${FIRMWARE_VER} of=${S}/speedtch-KQD6-2.bin \ ibs=1 obs=762650 count=762650 skip=1027 &> /dev/null \ || die "Extraction of stage 2 firmware (step 1) failed" dd if=${S}/ZZZL_${FIRMWARE_VER} of=${S}/speedtch-ZZZL-2.bin \ ibs=1 obs=775545 count=775545 skip=967 &> /dev/null \ || die "Extraction of stage 2 firmware (step 2) failed" # Copy to the firmware directory insinto /lib/firmware insopts -m 600 doins ${S}/speedtch-KQD6-1.bin doins ${S}/speedtch-KQD6-2.bin doins ${S}/speedtch-ZZZL-1.bin doins ${S}/speedtch-ZZZL-2.bin local PPP_FILE_EXT="pppoatm" insopts -m 600; insinto /etc/ppp/peers newins ${FILESDIR}/adsl.sample-${PPP_FILE_EXT} ${ADSL_FILE_NAME} exeinto /etc/init.d newexe ${FILESDIR}/speedtouch.rc-${PPP_FILE_EXT} speedtouch insopts -m 644; insinto /etc/hotplug/usb doins ${FILESDIR}/speedtch.usermap exeinto /etc/hotplug/usb newexe ${FILESDIR}/speedtch-hotplug-3 speedtch insinto /etc/conf.d newins ${FILESDIR}/speedtouch.confd-3 speedtouch # Docs dodoc ${FILESDIR}/README } pkg_postinst() { # Attempt to detect an attached modem pkg_config einfo "To complete the installation, you must read the documentation in" einfo "/usr/share/doc/${PF}" } pkg_prerm() { # From http://dev.gentoo.org/~plasmaroo/devmanual/ebuild-writing/functions/pkg_prerm/ # Remove stale symlinks, if the ebuild is being uninstalled # Have to be careful that the symlinks remain when the ebuild is *re*-installed [ -L /lib/firmware/speedtch-1.bin ] \ && [ ! -f /lib/firmware/speedtch-ZZZL-1.bin ] \ && rm -f /lib/firmware/speedtch-1.bin [ -L /lib/firmware/speedtch-2.bin ] \ && [ ! -f /lib/firmware/speedtch-ZZZL-2.bin ] \ && rm -f /lib/firmware/speedtch-2.bin }