#!/bin/sh # # This script tries to automagically install the mga driver including # the HAL library for Xorg 7.0 # # This software is licensed under the GPL. # # I cannot be made responsible for any data-loss, system misconfiguration # or other things that may be caused by the use of this script. # # ChangeLog: # ============================================================================= # 1.1.3 Again correcting the name of the g++ package # * Due to how package matching is done (regex, haha) the '+' signs # in g++ confuse the regex compiler and therefore they need to be # escaped using backslashes, otherwise the installer tells you to # install g++ although it is already installed. # 1.1.2 Corrected the g++ package name for RPM based systems # * Instead of g++, the package is called gcc-c++ # 1.1.1 Added missing dependency to g++ # * g++ is also needed to compile this driver # 1.1.0 Featuring RPM support # * Added basic support for RPM based distributions, especially Redhat FC5 # Many thanks to André Frick (projects@andrefrick.de) for providing the # necessary background information on FC5 # * Some small improvements for checking for necessary binaries before # doing the automatic package installation # * Implemented more generalization for future updates # * Added speed improvements by using temporary files for the output of # the package installation programs # # 1.0.1 Bugfix release # * The apt-get command redirects its output to $LOGFILE and because we # want the user to enter y or n for the installation of packages, he # doesn't see the question produced by apt-get -> Don't redirect the # output of apt-get # * Added additional functionality for checking the availability of # packages before we try to install them automatically # * Added a quick and dirty workaround for the Ubuntu problem mentioned # by Hark in the General Linux Forums. Ubuntu has no installable # package called xutils-dev, instaed it provides the package "imake" # # 1.0.0 Initial release # =============================================================================== # # (c) by Alexander Griesser # 2006-06-13 echo "=============================================================" echo " _______________ ____ __ __ __ __ __ __ __" echo " / ___/_ __/ __ \/ __ \ / / / / / / / / / / / / / /" echo " \__ \ / / / / / / /_/ / / / / / / / / / / / / / / /" echo " ___/ // / / /_/ / ____/ /_/ /_/ /_/ /_/ /_/ /_/ /_/" echo "/____//_/ \____/_/ (_) (_) (_) (_) (_) (_) (_)" echo "" echo "=============================================================" echo "Dear valued, frustrated Matrox user." echo "Please don't use this script anymore, as it is _OUTDATED_." echo "" echo "If you are looking for support on your Matrox graphics hardware," echo "please visit the Unofficial Matrox Technical Support Forum where you" echo "can download recent unofficial driver versions and get help to all" echo "your Matrox related problems" echo "" echo "If you are sure that you want to use this script despite this message," echo "feel free to have a look at the sourcecode to see how to enable this" echo "script." echo "" echo " http://matrox.tuxx-home.at/" echo "" exit 255 PROGNAME="$(basename $0)" LOGFILE="/tmp/$PROGNAME.log" VERSION="1.1.3" DEB_PACKAGES_NEEDED="wget tar gzip make gcc g++ binutils coreutils pkg-config xserver-xorg-dev x11proto-core-dev libxau-dev x11proto-fonts-dev x11proto-input-dev x11proto-randr-dev x11proto-render-dev x11proto-video-dev x11proto-xext-dev libdrm-dev x11proto-xf86dri-dev x11proto-gl-dev mesa-common-dev libtool xutils-dev libgl1-mesa-dri" FC5_PACKAGES_NEEDED="wget tar gzip make gcc gcc-c++ binutils coreutils pkgconfig xorg-x11-server-sdk xorg-x11-proto-devel libdrm-devel mesa-libGL-devel libtool imake mesa-libGL libXau-devel" PACKAGES_2_INSTALL="" UBUNTU_PACKAGES_NEEDED="imake" PACKAGES_NOT_AVAILABLE="" NEWCWD= ANSWER= DO_AUTOINSTALL=1 XORG_DRV_PATH="/usr/lib/xorg/modules/drivers" XORG_MGA_DRV_FILE="xf86-video-mga-1.2.1.3.tar.gz" XORG_MGA_DRV_MD5="418641e5e9ae77da793db63dc20f87bb" XORG_MGA_DRV_DIR="xf86-video-mga-1.2.1.3" MTX_MGA_BIN_FILE="mgadriver-4.1.tar.gz" MTX_MGA_BIN_DIR="mgadriver-4.1" MTX_MGA_BIN_MD5="f1075e3e2c8053aef73c0522f4a4ee90" MTX_MGA_SRC_FILE="mgadriver-4.1-1-src.tar.gz" MTX_MGA_SRC_DIR="mgadriver-4.1-1-src" MTX_MGA_SRC_MD5="5376fed39733b605191cf4dbb138a3ff" CURDATE="$(date +"%Y-%m-%d_%H:%M:%S")" TEMPFILE="/tmp/mga.$CURDATE" if [ "$(id -u)" != "0" ]; then echo "You are not root, so you loose..." exit 255 fi # Check, if the correct X version is installed... XVERSION=`X -version 2>&1 | grep -s "X Protocol Version" | sed -e "s/Revision[^0-9]*\([0-9]*\), Release[^0-9]*\([0-9.]*\)/\2\.\1/" | cut -d" " -f 5-` if [ "$XVERSION" != "7.0.0" ]; then echo "This script needs Xorg v7.0.0 installed on your system." echo "You don't seem to have this version installed, so I'm exiting now..." exit 255 fi usage() { echo "$PROGNAME, Version $VERSION" echo "-----------------------------------------------------------" echo "Usage: $PROGNAME [OPTION]" echo "" echo "Options can be:" echo " --help display this help and exit" echo "" echo "Report bugs to " exit 0 } if [ "$#" != "0" ]; then usage fi try() { if [ "$NEWCWD" != "" ]; then OLDCWD="$(pwd)" cd $NEWCWD fi if $* >>$LOGFILE 2>&1; then echo "done." else echo "failed." echo "Please check the file $LOGFILE for further information." exit 1 fi if [ "$NEWCWD" != "" ]; then cd $OLDCWD fi } # $1: Filename # $2: MD5-Sum file_doesnot_exist() { if [ -f $1 ]; then echo "File $1 already exists, skipping download." if [ "$(md5sum $1)" != "$2 $1" ]; then echo "Your locally installed version of $1 differs from the one in the web." echo "Please check this or use a different installation directory." echo "Exiting now..." exit 255 fi return 1 fi return 0 } echo "Installation started at $CURDATE..." >$LOGFILE RPM_check_packages() { # Chache the output of `yum list` to $TEMPFILE yum list >$TEMPFILE 2>/dev/null for p in $FC5_PACKAGES_NEEDED; do if ! grep -q "^$p\..*installed" $TEMPFILE; then PACKAGES_2_INSTALL="$PACKAGES_2_INSTALL $p" fi done } DEB_check_packages() { # Chache the output of `dpkg --get-selections` to $TEMPFILE dpkg --get-selections >$TEMPFILE 2>/dev/null for p in $DEB_PACKAGES_NEEDED; do if ! grep -q "^$p\>.*\$TEMPFILE 2>/dev/null UBUNTU_DETECTED=0 for p in $PACKAGES_2_INSTALL; do if ! grep -q "^$p$" $TEMPFILE; then # qnd workaround for Ubuntu distributions # they have the package "imake" instead of "xutils-dev" if [ "$p" = "xutils-dev" ]; then UBUNTU_DETECTED=1 continue fi PACKAGES_NOT_AVAILABLE="$PACKAGES_NOT_AVAILABLE $p" fi done if [ "$UBUNTU_DETECTED" = "1" ]; then PACKAGES_2_INSTALL="$PACKAGES_2_INSTALL $UBUNTU_PACKAGES_NEEDED" PACKAGES_2_INSTALL="$(echo $PACKAGES_2_INSTALL | sed -e 's/\//')" fi } RPM_install_packages() { yum install $PACKAGES_2_INSTALL } DEB_install_packages() { apt-get install $PACKAGES_2_INSTALL } GENERAL_check_packages() { echo -n "Checking for installed packages, this may take a while..." if [ "$METHOD" = "deb" ]; then DEB_check_packages else RPM_check_packages fi echo "done." if [ "$PACKAGES_2_INSTALL" = "" ]; then echo "All needed packages are currently installed." return 0 fi echo -n "Checking for available packages, this may take a while..." if [ "$METHOD" = "deb" ]; then DEB_check_packages_available else RPM_check_packages_available fi echo "done." echo "The following packages need to be installed:" echo "$PACKAGES_2_INSTALL" if [ "$PACKAGES_NOT_AVAILABLE" != "" ]; then echo "The following packages are not available at the moment, so I" echo "cannot install them." echo "$PACKAGES_NOT_AVAILABLE" echo read -p "Do you still want to continue? (y/N)" ANSWER if [ "$ANSWER" != "y" ] && [ "$ANSWER" != "Y" ]; then echo "Exiting now." exit 255 fi fi # Don't bug the user twice... if [ "$ANSWER" = "" ]; then read -p "Do you want me to install the packages for you? (y/N)" ANSWER fi if [ "$ANSWER" = "y" ] || [ "$ANSWER" = "Y" ]; then echo "Installing the necessary packages..." if [ "$METHOD" = "deb" ]; then DEB_install_packages else RPM_install_packages fi else echo "Please install these packages manually and run this script again" echo "after you completed the installation." exit 1 fi } if [ -f /etc/debian_version ]; then OS="Debian" METHOD="deb" if ! [ -x "$(which dpkg)" ] || ! [ -x "$(which apt-get)" ] || ! [ -x "$(which apt-cache)" ]; then DO_AUTOINSTALL=0 fi else OS="Unknown" METHOD="rpm" if ! [ -x "$(which yum)" ] || ! [ -x "$(which rpm)" ]; then DO_AUTOINSTALL=0 fi if [ -f /etc/redhat-release ]; then if grep -q "Fedora Core release 5" /etc/redhat-release; then OS="FC5" fi fi fi if [ "$DO_AUTOINSTALL" = "0" ]; then echo "Missing binaries for installing packages automatically." echo -n "The following packages are needed: " if [ "$METHOD" = "deb" ]; then echo "dpkg, apt-get, apt-cache" else echo "rpm, yum" fi echo "Automatic package installation will be disabled." echo "" read -p "Press any key to continue, CTRL-C to exit..." fi echo "=============================================================" echo "Welcome to the automatic mga installer for Xorg 7.0" echo "" echo "This script tries to install a compatible mga driver for your" echo "Xorg 7.0 installation by installing missing operating sytem" echo "packages, downloading driver repositories and compiling some" echo "stuff as well as copying some libraries around." echo "" echo "If you don't want this script to do that, feel free to" echo "CTRL-C here..." echo "" echo "There will also be a logfile available for some operations" echo "during this installation process. This file is located here:" echo "$LOGFILE" echo "" read -p "Press any key to continue, CTRL-C to exit..." if [ "$OS" = "Unknown" ]; then echo "This script is only able to check for the correct packages on" echo "certain predefined distributions. If you see this message, " echo "your distribution is not predefined. Please help me to provide" echo "support for your distribution and contact me for more details." echo "" echo "Please verify, that the following list of packages resp. their" echo "pendants on your distribution are installed before continuing." echo "" echo "$DEB_PACKAGES_NEEDED" echo "" read -p "Press any key to continue, CTRL-C to exit..." else if [ "$DO_AUTOINSTALL" = "1" ]; then GENERAL_check_packages fi fi TMPDIR="/root/mga_xorg7_tmp" read -p "Please enter the installation directory ($TMPDIR): " TMPDIR1 if [ "$TMPDIR1" != "" ]; then TMPDIR=$TMPDIR1 fi if ! [ -d $TMPDIR ]; then echo -n "Creating temporary directory..." try mkdir $TMPDIR fi cd $TMPDIR if file_doesnot_exist $MTX_MGA_BIN_FILE $MTX_MGA_BIN_MD5; then echo -n "Downloading the compatible binary mgadrivers from ftp.matrox.com..." try wget -q ftp://ftp.matrox.com/pub/mga/archive/linux/2004/$MTX_MGA_BIN_FILE fi if file_doesnot_exist $MTX_MGA_SRC_FILE $MTX_MGA_SRC_MD5; then echo -n "Downloading the compatible mgadriver source from ftp.matrox.com..." try wget -q ftp://ftp.matrox.com/pub/mga/archive/linux/2004/$MTX_MGA_SRC_FILE fi if file_doesnot_exist $XORG_MGA_DRV_FILE $XORG_MGA_DRV_MD5; then echo -n "Downloading the latest compatible Xorg mga driver package..." try wget -q http://xorg.freedesktop.org/releases/individual/driver/$XORG_MGA_DRV_FILE fi if ! [ -d "$XORG_MGA_DRV_DIR" ]; then echo -n "Extracting Xorg mga driver package..." try tar -xzf $XORG_MGA_DRV_FILE fi if ! [ -d "$MTX_MGA_BIN_DIR" ]; then echo -n "Extracing Matrox binary driver package..." try tar -xzf $MTX_MGA_BIN_FILE fi if ! [ -d "$MTX_MGA_SRC_DIR" ]; then echo -n "Extracting Matrox source package..." try tar -xzf $MTX_MGA_SRC_FILE fi echo -n "Configuring the mga driver package..." NEWCWD="$XORG_MGA_DRV_DIR" try ./configure echo -n "Checking the state of USEMGAHAL in config.h ..." if grep -q "^#define USEMGAHAL" $XORG_MGA_DRV_DIR/config.h; then echo "already set." else if ! echo -e "\n/* Enable the use of the MGA HAL library */\n#define USEMGAHAL" >>$XORG_MGA_DRV_DIR/config.h; then echo "failed." exit 1 fi echo "now activated." fi echo -n "Cleaning up in the mga driver package directory..." NEWCWD="$XORG_MGA_DRV_DIR" try make clean echo -n "Compiling the mga driver package..." NEWCWD="$XORG_MGA_DRV_DIR" try make echo -n "Stripping ddcparam.o from mgaHALlib.a..." NEWCWD="$MTX_MGA_SRC_DIR/6.8.1/mga/HALlib" try ar -d ddcparam.o mgaHALlib.a echo -n "Stripping vparmhal.o from mgaHALlib.a..." NEWCWD="$MTX_MGA_SRC_DIR/6.8.1/mga/HALlib" try ar -d vparmhal.o mgaHALlib.a echo -n "Copying over the stripped mgaHALlib.a..." NEWCWD= try cp $MTX_MGA_SRC_DIR/6.8.1/mga/HALlib/mgaHALlib.a \ $XORG_MGA_DRV_DIR/src/.libs echo -n "Linking mga_drv.so with mgaHALlib.a..." NEWCWD="$XORG_MGA_DRV_DIR/src/.libs" try libtool --mode=link gcc --shared -DXFree86Server -DIN_MODULE -DXFree86Module -DXFree86LOADER -I/usr/include/xorg -I/usr/include/drm -I/usr/include/X11/dri -g -O2 -module -avoid-version --whole-archive clientlx.o libmga_storm16_la-mga_storm.o libmga_storm24_la-mga_storm.o libmga_storm32_la-mga_storm.o libmga_storm8_la-mga_storm.o mga_arc.o mga_bios.o mga_dac3026.o mga_dacG.o mga_dga.o mga_dh.o mga_dri.o mga_driver.o mga_esc.o mga_g450pll.o mga_halmod.o mga_hwcurs.o mga_merge.o mga_shadow.o mga_video.o mgaHALlib.a -o mga_drv.so NEWCWD= if [ -f $XORG_DRV_PATH/mga_drv.so ]; then echo -n "Backing up your existing mga_drv.so..." try mv $XORG_DRV_PATH/mga_drv.so $XORG_DRV_PATH/mga_drv.so.$CURDATE fi if [ -f $XORG_DRV_PATH/mga_hal.o ]; then echo -n "Backing up your existing mga_hal.o..." try mv $XORG_DRV_PATH/mga_hal.o $XORG_DRV_PATH/mga_hal.o.$CURDATE fi echo -n "Installing new mga_drv.so..." try cp $XORG_MGA_DRV_DIR/src/.libs/mga_drv.so $XORG_DRV_PATH echo -n "Installing the new mga_hal.o..." try cp $MTX_MGA_BIN_DIR/xfree86/6.8.1/mga_hal_drv.o $XORG_DRV_PATH/mga_hal.o # Remove the temporary file rm -f $TEMPFILE echo "=============================================================" echo "Congratulations, everything went successful." echo "You may now try out your new configuration." echo "" echo "In case of any troubles please contact me or post your question" echo "to the Matrox General Linux Discussion forums." echo "" echo "(c) 2006 by Alexander Griesser " echo "Forum-Link: http://forum.matrox.com/mga/viewforum.php?f=64" echo "" echo "$PROGNAME by tuxx-home.at, Version $VERSION" echo "Check for updates on http://tuxx-home.at" echo "=============================================================" exit 0