#!/bin/bash ## Script to build the following kernel dependent files ## Virtualbox, vbox-guest-addons, ATI fglrx, nvidia ## Author Hamza & Brokenman SUN=http://dlc.sun.com.edgesuite.net/virtualbox . /usr/lib/librokenman ## Set httpfs path rmnt=`which httpfs2` ## Set variables DRIVER=$1 case $DRIVER in vbox ) ICON=virtualbox.png DRIVERURL=http://download.virtualbox.org/virtualbox HEADING="Porteus VirtualBox compiler" BLURBFILE="Virtualbox .run file" ;; vboxguest ) ICON=virtualbox.png DRIVERURL=http://download.virtualbox.org/virtualbox HEADING="VirtualBox guest addons" BLURBFILE="VirtualBox guest addons ISO" ;; esac SCRIPT="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" WRK=/tmp/gtk-driver-builder PIXMAPS=/usr/share/pixmaps/porteus DUMP=$WRK/.dump MURL=http://dl3.porteus.org LVER=$(cut -d- -f2- /etc/porteus-version) KR=$(uname -r | cut -d- -f1) if [ $(uname -m) != "x86_64" ]; then ARCH="x86"; else ARCH="amd64"; fi if [ $(uname -m) != "x86_64" ]; then MARCH="i486"; else MARCH="x86_64"; fi if [ $MARCH == "x86_64" ]; then LIB="lib64"; else LIB="lib"; fi gtk_yesno(){ w=${1} let width=$(( w-60 )) echo ' '`start_window "Choose yes or no" cdr $1`' '`pixmapfile $2 $2 $3`' '`txtmarkup $width "$4"`' '`txtmarkup $width ""`' '`txtmarkup $width "$5"`' '`end_window`' '|gtkdialog -s > $WRK/yesno.tmp if [ `grep -o abort $WRK/yesno.tmp` ]; then answ=no elif [ `grep -o No $WRK/yesno.tmp` ]; then answ=no else answ=yes fi rm $WRK/yesno.tmp }; export -f gtk_yesno check_development(){ ## Check for development xzm required for compilation if [ ! -d /mnt/live/memory/images/05-devel.xzm ]; then gtk_yesno 500 36 $PIXMAPS/error.png "No development module was found on your system. You will need to activate it or download from the server before you can continue." "Would you like to download it now?" if [ "$answ" == "no" ]; then cleanup exit else export STATE=MANUAL echo "Checking internet ..." > /tmp/.message manual_progress "Processing ..." has_internet if [ $answ -eq 0 ]; then hasinternet=1 && unset answ echo "Getting source URL ..." > /tmp/.message echo $LVER | grep -q - && MREL=testing/Porteus-$LVER || MREL=current KSRCLINK=$MURL/$MARCH/$MREL/modules/05-devel.xzm KSRCP=${KSRCLINK##*/} sleep 2 kill_manual_progress export STATE=DOWNLOAD manual_progress "Downloading Porteus development module" rm -f /tmp/$KSRCP wget -o /tmp/.message -P /tmp $KSRCLINK sleep 2 kill_manual_progress gtk_message "The development module was downloaded into /tmp. Click OK to activate it now." 450 gtk-dialog warning activate /tmp/$KSRCP sleep 2 else kill_manual_progress sleep 2 gtk_message "It appears you have no internet connection!" 450 gtk-dialog warning cleanup exit fi fi fi ## Failsafe for no development module [ ! -d /mnt/live/memory/images/05-devel.xzm ] && exit }; export -f check_development cleanup(){ rm -rf $WRK /tmp/.message /tmp/.cdload /tmp/vboxguest-Module.symvers 2>/dev/null [ -d /mnt/loop ] && umount /mnt/loop [ -d /mnt/guestiso ] && umount /mnt/guestiso [ -d /mnt/guestiso ] && rm -rf /mnt/guestiso 2>/dev/null }; export -f cleanup ## Setup dir structure [ -d $WRK ] && rm -rf $WRK mkdir $WRK main_screen(){ export MAIN_DIALOG=' /usr/share/pixmaps/porteus/'$ICON' 64 '`txtcolor 400 darkred x-large bold " $HEADING"`' '`hsep`' '`txtmarkup 460 "Choose an existing $BLURBFILE or download the latest $BLURBFILE from the website. The file will then be compiled and converted into a Porteus module."`' '`blankline`' CHFILE '`chkbox false chkbox "I want to download the $BLURBFILE"`' '`butcancel`' '`butok`' ' gtkdialog -p MAIN_DIALOG > $DUMP ## Check for user cancel if [ `egrep "Cancel|abort|Abort" $DUMP` ]; then cleanup exit fi ## Make sure something was chosen CHKBOX=`grep chkbox $DUMP|cut -d'"' -f2` CHOSENFILE=`grep CHFILE $DUMP|cut -d'"' -f2` if [ "$CHKBOX" == "false" ]; then if [ "$CHOSENFILE" == "" ]; then gtk_message "You must choose one option!" 450 gtk-dialog-warning $FUNCNAME exit fi fi }; export -f main_screen check_development main_screen ################## Get the usable file if [ "$CHKBOX" == "true" ]; then DOWNLOADFILE=1 FILEPATH=/tmp export STATE=MANUAL echo "Checking internet ..." > /tmp/.message manual_progress "Downloading file" has_internet if [ $answ -eq 1 ]; then kill_manual_progress gtk_message "It appears you have no internet connection!" 500 gtk-dialog-warning cleanup exit fi case $DRIVER in vbox ) echo "Getting vbox links ..." > /tmp/.message VBOXVER=`lynx -dump $DRIVERURL/LATEST.TXT` FILELINK=`lynx -dump -nonumbers -listonly $DRIVERURL/$VBOXVER|grep .run|grep $ARCH` BLURBFILE="VirtualBox $VBOXVER" ;; vboxguest ) echo "Getting vbox links ..." > /tmp/.message VBOXVER=`lynx -dump $DRIVERURL/LATEST.TXT` FILELINK=$SUN/$VBOXVER/VBoxGuestAdditions_$VBOXVER.iso BLURBFILE="VirtualBox $VBOXVER guest addons" [ ! -d /mnt/guestiso ] && mkdir /mnt/guestiso ;; esac ## Download the file sleep 2 kill_manual_progress export STATE=DOWNLOAD manual_progress "Downloading $BLURBFILE" FILENAME=${FILELINK##*/} ## If httpfs(2) is available then mount guest addons to local file system. if [ ! -f $FILEPATH/$FILENAME ]; then if [ `grep -o ".iso" <<<$FILENAME` ]; then $rmnt $FILELINK /mnt/guestiso FILEPATH=/mnt/guestiso/ else wget -o /tmp/.message -P $FILEPATH $FILELINK fi fi sleep 2 kill_manual_progress else ## User chose the file manually FULLPATH=${CHOSENFILE} FILEPATH=${FULLPATH%/*} FILENAME=${FULLPATH##*/} fi ################# End of getting usable file ## Full path to target file export FULLPATH=$FILEPATH/$FILENAME ## Set permissions for root chown root:root $FULLPATH chmod 644 $FULLPATH chmod +x $FULLPATH ## Create a directory to build Porteus module in BUILD=$WRK/build mkdir $BUILD ## Create driver specific subfolders/files case $DRIVER in vbox ) FILEVER=`awk -F- '{print$2}' <<<$FILENAME` TARGMOD=/tmp/VirtualBox-$FILEVER-porteus-$LVER-$MARCH-1prt.xzm mkdir -p $BUILD/etc/rc.d/init.d $BUILD/etc/rc.d/rc4.d cat > $BUILD/etc/rc.d/init.d/rc.virtualbox << EOF #!/bin/sh # # VirtualBox Linux kernel modules init script # # Copyright (C) Sun Microsystems, Inc. # # http://www.virtualbox.org # /sbin/depmod -A /sbin/modprobe vboxdrv /sbin/modprobe vboxnetadp /sbin/modprobe vboxnetflt EOF chmod +x $BUILD/etc/rc.d/init.d/rc.virtualbox ln -sf /etc/rc.d/init.d/rc.virtualbox $BUILD/etc/rc.d/rc4.d/S99virtualbox cat > $WRK/commands << EOF clear sh $FULLPATH WRK=/tmp/gtk-driver-builder BUILD=$WRK/build cp -a --parents /etc/rc.d/{rc.vboxautostart-service,rc.vboxballoonctrl-service,rc.vboxdrv,rc.vboxweb-service} $BUILD/ cp -a --parents /etc/udev/rules.d/60-vboxdrv.rules $BUILD/ cp -a --parents /etc/vbox $BUILD/ cp -a --parents -R /lib/modules/`uname -r`/misc/{vboxdrv.ko,vboxnetadp.ko,vboxnetflt.ko,vboxpci.ko} $BUILD/ cp -a --parents /opt/VirtualBox $BUILD/ cp -a --parents /usr/bin/{VBoxBalloonCtrl,VBoxHeadless,VBoxManage,VBoxSDL,VBoxVRDP,VirtualBox,rdesktop-vrdp,vboxheadless,vboxmanage,vboxsdl,vboxwebsrv,virtualbox} $BUILD/ cp -a --parents /usr/share/applications/virtualbox.desktop $BUILD/ find /usr/share/icons/ -name "virtualbox*" -exec cp -a --parents {} $BUILD/ \; cp -a --parents /usr/share/pixmaps/{VBox.png,virtualbox.png} $BUILD/ clear ### Please click the OK button to continue EOF ;; vboxguest ) TARGMOD=/tmp/vbox-guest-$VBOXVER-porteus-$LVER-$MARCH-1prt.xzm mloop $FULLPATH mkdir -p $BUILD/etc/rc.d/init.d $BUILD/etc/rc.d/rc4.d $BUILD/etc/X11 $BUILD/usr/share/autostart/ cat > $BUILD/etc/rc.d/init.d/rc.vbox-add << EOF #!/bin/sh # Start vboxadd # If you do not wish this to be executed here then comment it out, # and the installer will skip it next time. if [ -x /etc/rc.d/rc.vboxadd ]; then /etc/rc.d/rc.vboxadd start fi # Start vboxadd-service # If you do not wish this to be executed here then comment it out, # and the installer will skip it next time. if [ -x /etc/rc.d/rc.vboxadd-service ]; then /etc/rc.d/rc.vboxadd-service start fi # Start vboxadd-x11 # If you do not wish this to be executed here then comment it out, # and the installer will skip it next time. if [ -x /etc/rc.d/rc.vboxadd-x11 ]; then /etc/rc.d/rc.vboxadd-x11 start fi EOF chmod +x $BUILD/etc/rc.d/init.d/rc.vbox-add ln -sf /etc/rc.d/init.d/rc.vbox-add $BUILD/etc/rc.d/rc4.d/S99vbox-add cat > $BUILD/etc/X11/xorg.conf << EOF # VirtualBox generated configuration file # based on /etc/X11/xorg.conf. Section "Monitor" Identifier "Monitor[0]" ModelName "VirtualBox Virtual Output" VendorName "Oracle Corporation" EndSection Section "Device" BoardName "VirtualBox Graphics" Driver "vboxvideo" Identifier "Device[0]" VendorName "Oracle Corporation" EndSection Section "Screen" SubSection "Display" Depth 24 EndSubSection Device "Device[0]" Identifier "Screen[0]" Monitor "Monitor[0]" EndSection EOF ## Create commands file cat > $WRK/commands << EOF clear sh /mnt/loop/VBoxLinuxAdditions.run WRK=/tmp/gtk-driver-builder BUILD=$WRK/build if [ $MARCH == "x86_64" ]; then LIB="lib64"; else LIB="lib"; fi cp -a --parents /etc/rc.d/{rc.vboxadd,rc.vboxadd-service,rc.vboxadd-x11} $BUILD/ cp -a --parents /etc/udev/rules.d/60-vboxadd.rules $BUILD/ cp -a --parents /etc/xdg/autostart/vboxclient.desktop $BUILD/ cp -a $BUILD/etc/xdg/autostart/vboxclient.desktop $BUILD/usr/share/autostart/ cp -a --parents /lib/modules/`uname -r`/misc/{vboxguest.ko,vboxsf.ko,vboxvideo.ko} $BUILD/ cp -a --parents /opt/VBoxGuestAdditions-* $BUILD/ cp -a --parents /sbin/mount.vboxsf $BUILD/ cp -a --parents /usr/bin/{VBoxClient,VBoxClient-all,VBoxControl} $BUILD/ cp -a --parents /usr/$LIB/dri/vboxvideo_dri.so $BUILD/ cp -a --parents /usr/$LIB/xorg/modules/dri/vboxvideo_dri.so $BUILD cp -a --parents /usr/$LIB/xorg/modules/drivers/vboxvideo_drv.so $BUILD/ cp -a --parents /usr/$LIB/VBoxGuestAdditions $BUILD/ cp -a --parents /usr/$LIB/VBoxOGL* $BUILD/ cp -a --parents /usr/sbin/VBoxService $BUILD/ cp -a --parents /usr/share/VBoxGuestAdditions $BUILD/ cp -a --parents /var/lib/VBoxGuestAdditions $BUILD/ clear ### Please press OK to continue building module EOF ;; esac ## Create the streaming output dialog export TERMOUT=' /usr/share/pixmaps/porteus/'$ICON' 64 '`txtcolor 450 darkred x-large bold " $HEADING"`' '`txtmarkup 500 "Please wait for a message in the window below to press OK"`' porteusvte '$WRK'/commands '`butok`' ' gtkdialog -p TERMOUT >$DUMP [ `grep "abort" $DUMP` ] && { rm $WRK; exit; } ## Build the final module export STATE=BUILDMODULE manual_progress "$BLURBFILE module building ..." dir2xzm $BUILD $TARGMOD > /tmp/.message rm /tmp/.message 2>/dev/null sleep 2 kill_manual_progress rm -Rf "$WRK" gtk_message "$TARGMOD is ready!" 500 gtk-yes cleanup