I've put together a script for building GnuRadio+UHD for both Ubuntu recent and Fedora recent.

I've attached it.

This is outgrowth of a script I put together and distributed to a few people several years ago, but it has
  been updated quite a bit and supports both Ubuntu and Fedora.

Your mileage may vary. Void where prohibited. Some settling may have occurred during transit. Batteries not
  included.  Only use while awake.  Do not use in the bathtub.

--
Marcus Leech
Principal Investigator
Shirleys Bay Radio Astronomy Consortium
http://www.sbrac.org

#!/bin/sh
#
# Build script for UHD+GnuRadio on Fedora and Ubuntu
#
SUDOASKED=n
function prereqs {
        sudocheck
        echo Installing pre-prequisites
        #
        # Check whether we're on a Fedora or Ubuntu system, and "do the right 
thing"
        #  for either system
        #
        # It's a Fedora system
        #
        if [ -f /etc/fedora-release ]
        then
                case `cat /etc/fedora-release` in
                *12*|*13*|*14*|*15*)
                        sudo yum -y groupinstall "Engineering and Scientific" 
"Development Tools" 
                        sudo yum -y install fftw-devel cppunit-devel 
wxPython-devel libusb-devel \
                          guile boost-devel alsa-lib-devel numpy gsl-devel 
python-devel pygsl \
                          python-cheetah python-lxml guile-devel PyOpenGL \
                          PyQt4-devel qwt-devel qwtplot3d-qt4-devel libusb 
libusb-devel \
                          libusb1 libusb1-devel cmake git wget sdcc
                ;;
                *)
                        echo Your Fedora system release must be at least 12 to 
proceed
                        exit
                        ;;
                esac
                
        #
        # It's a Ubuntu system
        #
        elif [ -f /etc/lsb-release ]
        then
                case `grep DISTRIB_RELEASE /etc/lsb-release` in
                *10.04*|*10.10*)
                        sudo apt-get -y install libfontconfig1-dev 
libxrender-dev libpulse-dev swig g++ \
                        automake autoconf libtool python-dev libfftw3-dev \
                        libcppunit-dev libboost-all-dev libusb-dev fort77 sdcc 
sdcc-libraries \
                        libsdl1.2-dev python-wxgtk2.8 git-core guile-1.8-dev \
                        libqt4-dev python-numpy ccache python-opengl 
libgsl0-dev \
                        python-cheetah python-lxml doxygen qt4-dev-tools 
libusb-1.0-0-dev \
                        libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools \
                        cmake git wget sdcc
                        ;;
                        
                *9.10*)
                        sudo apt-get -y install swig g++ automake autoconf 
libtool python-dev libfftw3-dev \
                        libcppunit-dev libboost1.38-dev libusb-dev fort77 sdcc 
sdcc-libraries \
                        libsdl1.2-dev python-wxgtk2.8 git-core guile-1.8-dev \
                        libqt4-dev python-numpy ccache python-opengl 
libgsl0-dev \
                        python-cheetah python-lxml doxygen qt4-dev-tools 
libusb-1.0-0-dev \
                        libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools \
                        cmake git wget sdcc
                        ;;
                        
                *)
                        echo Your Ubuntu release must be at least 9.10 to 
proceed
                        exit
                        ;;
                esac
        else
                echo This script supports only Ubuntu and Fedora systems
                echo Your Fedora system must be at least Fedora 13
                echo Your Ubuntu system must be at least Ubuntu 9.10
                exit
        fi
}


function gitfetch {
        cd $HOME
        date=`date +%Y%m%d%H%M%S`

        #
        # Check for existing gnuradio directory
        #
        if [ -d $HOME/gnuradio ]
        then
                mv $HOME/gnuradio $HOME/gnuradio.$date
        fi

        #
        # Check for existing UHD directory
        #
        if [ -d $HOME/uhd ]
        then
                mv $HOME/uhd $HOME/uhd.$date
        fi

        #
        # GIT the gnu radio source tree
        #
        git clone http://gnuradio.org/git/gnuradio.git

        if [ ! -d gnuradio/gnuradio-core ]
        then
                echo GIT checkout of Gnu Radio failed!
                exit
        fi

        #
        # GIT the UHD source tree
        #
        git clone git://code.ettus.com/ettus/uhd.git

        if [ ! -d uhd/host ]
        then
                echo GIT checkout of UHD failed!
                exit
        fi
}

function uhd_build {
        #
        # UHD build
        #
        sudocheck
        cd $HOME
        if [ ! -d uhd ]
        then
                echo you do not appear to have the \'uhd\' directory
                echo you should probably use $0 gitfetch to fetch the 
appropriate
                echo files using GIT
                exit
        fi
        echo Building UHD first...
        cd uhd/host
        mkdir build
        cd build
        cmake ../
        make 
        sudo make install
        if [ ! -f /usr/local/bin/uhd_find_devices -o 
/usr/local/bin/uhd_find_devices -ot $HOME/uhd ]
        then
                echo UHD build/install apparently failed exiting $0
                exit
        fi
        echo Done building UHD
}

function firmware {
        sudocheck
        #
        # Firmware/FPGA images...
        #
        cd $HOME
        echo Fetching FPGA/Firmware images via wget
        mkdir wget-tmp
        cd wget-tmp
        wget -nd -r -np 
http://www.ettus.com/downloads/uhd_images/UHD-images-most-recent/
        tar xf *-Linux.tar.gz
        cd UHD*/share/uhd/images
        if [ ! -d /usr/local/share/uhd/images ]
        then
                sudo mkdir -p /usr/local/share/uhd/images
        fi
        sudo cp * /usr/local/share/uhd/images
        sudo chmod 644 /usr/local/share/uhd/images/*
        cd $HOME
        rm -rf wget-tmp
        echo Done installing FPGA/Firmware images via wget
}

function gnuradio_build {
        sudocheck
        cd $HOME
        
        if [ ! -d gnuradio ]
        then
                echo you do not appear to have the \'gnuradio\' directory
                echo you should probably use $0 gitfetch to fetch the 
appropriate
                echo files using GIT
                exit
        fi
        
        #
        # LD stuff
        #
        echo /usr/local/lib >tmp$$

        if grep -q /usr/local/lib /etc/ld.so.conf.d/*
        then
                echo /usr/local/lib already in ld.so.conf.d
        else
                sudo cp tmp$$ /etc/ld.so.conf.d/local.conf
        fi
        rm -f tmp$$
        sudo ldconfig

        PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
        export PKG_CONFIG_PATH

        #
        # Build Gnuradio
        #
        cd $HOME
        echo Building Gnu Radio...
        cd gnuradio
        git status >foo$$
        if grep -q "On branch next" foo$$
        then
                echo No need to change to branch \'next\' already done
        else
                git branch --track next origin/next
                git checkout next
        fi
        rm foo$$
        ./bootstrap
        ./configure
        make
        sudo make install
        if [ ! -f /usr/local/bin/gnuradio-companion -o 
/usr/local/bin/gnuradio-companion -ot $HOME/gnuradio/grc ]
        then
                echo Gnu Radio build/install apparently failed exiting $0
                exit
        fi
        echo Done building Gnu Radio
}

function mod_groups {
        sudocheck
        #
        # Post install stuff
        #
        # USRP rules for UDEV and USRP group
        #
        #
        # Check for USRP group, and update if necessary
        if grep -q usrp /etc/group
        then
                echo Group \'usrp\' already in /etc/group
        else
                sudo /usr/sbin/groupadd usrp
        fi

        #
        # Check that our calling user is in the USRP group, update if necessary
        #
        if grep -q usrp.*${USER} /etc/group
        then
                echo User $USER already in group \'usrp\'
        else
                sudo /usr/sbin/usermod -a -G usrp $USER
        fi
}

function mod_udev {
        sudocheck
        cd $HOME
        #
        # Check for UDEV rules file, update if necessary
        #
        if [ ! -f /etc/udev/rules.d/10-usrp.rules ]
        then
                cat >>tmp$$ <<"!EOF!"
        # rule to grant read/write access on USRP to group named usrp.
        # to use, install this file in /etc/udev/rules.d as 10-usrp.rules
        ACTION=="add", BUS=="usb", SYSFS{idVendor}=="fffe", 
SYSFS{idProduct}=="0002", GROUP:="usrp", MODE:="0660"
!EOF!
                chmod 644 tmp$$
                sudo mv tmp$$ /etc/udev/rules.d/10-usrp.rules
                sudo killall -HUP udevd
                sudo udevadm control --reload_rules
                rm -f tmp$$
        else
                echo USRP rules for UDEV already in place
        fi
}

function mod_sysctl {
        sudocheck
        cd $HOME
        #
        # Modify sysctl.conf as necessary
        #
        cat >tmp$$ <<!EOF!
        # Updates for Gnu Radio
        net.core.rmem_max = 1000000
        net.core.wmem_max = 1000000
        kernel.shmmax = 2147483648
!EOF!


        if grep -q 'Updates for Gnu Radio' /etc/sysctl.conf
        then
                echo Required updates to /etc/sysctl.conf already in place
        else
                echo Applying updates to /etc/sysctl.conf
                cat /etc/sysctl.conf tmp$$ >tmp2$$
                chmod 644 tmp2$$
                sudo mv tmp2$$ /etc/sysctl.conf
        fi

        sudo sysctl -w net.core.rmem_max=1000000
        sudo sysctl -w net.core.wmem_max=1000000
        sudo sysctl -w kernel.shmmax=2147483648
         
        rm -f tmp$$
        rm -f tmp2$$
}

function all {
        prereqs
        touch -d "2 hours ago" touch$$
        if [ -d $HOME/uhd -a -d $HOME/gnuradio ]
        then
                if [ $HOME/uhd -ot touch$$ -o $HOME/gnuradio -ot touch$$ ]
                then
                        gitfetch
                else
                        echo Skipping git fetch, since \'uhd\' and \'gnuradio\' 
are new enough
                fi
        else
                gitfetch
        fi
        rm -f touch$$
        uhd_build
        firmware
        gnuradio_build
        mod_groups
        mod_udev
        mod_sysctl
}

function help {
        echo available functions are: all prereqs gitfetch uhd_build firmware 
gnuradio_build mod_groups mod_udev mod_sysctl
}

cd $HOME
PATH=$PATH:/usr/libexec/sdcc
export PATH

function sudocheck {
        #
        # Check SUDO privileges
        #
        if [ $SUDOASKED = n ]
        then
                echo SUDO privileges are required 
                echo -n Do you have SUDO privileges'?'
                read ans
                case $ans in
                        y|yes|YES|Y)
                                echo Continuing with script
                                SUDOASKED=y
                                ;;
                        *)
                                echo Exiting.  Please ensure that you have SUDO 
privileges on this system!
                                exit
                                ;;
                esac
        fi
}

case $# in
        0)
                all
                exit
esac

for arg in $*
do
        $arg
done
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to