#!/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 . /usr/share/porteus/porteus-functions txtsize(){ echo '' } ## Set httpfs path rmnt=`which httpfs2` ## Set variables DRIVER=$1 get_server || { echo "Could not get Porteus server."; cleanup; exit; } case `uname -m` in x86_64) NARCH=amd64 ARCH=x86_64 LIB=lib64 ;; i?86) NARCH=x86 ARCH=i586 LIB=lib ;; esac case $DRIVER in vbox ) ICON=vbox.png DRIVERURL=http://download.virtualbox.org/virtualbox HEADING="Porteus VirtualBox compiler" BLURBFILE="Virtualbox .run file" ;; vboxguest ) ICON=vbox.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 LVER=$(cut -d- -f2- /etc/porteus-version) PVER=` '`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=/Porteus-$LVER || MREL=current #KSRCLINK=$SERVER/$ARCH/kernel/porteus-$KR/05-devel.xzm KSRCLINK=$SERVER/$ARCH/current/kernel/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 ## Check for crippled sources required for compilation if [ ! -e /usr/src/linux/System.map ]; then gtk_yesno 500 36 $PIXMAPS/error.png "No kernel source 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=/Porteus-$LVER || MREL=current #KSRCLINK=$SERVER/$ARCH/kernel/porteus-$KR/crippled_sources.xzm KSRCLINK=$SERVER/$ARCH/current/kernel/crippled_sources.xzm KSRCP=${KSRCLINK##*/} sleep 2 kill_manual_progress export STATE=DOWNLOAD manual_progress "Downloading kernel sources module" rm -f /tmp/$KSRCP wget -o /tmp/.message -P /tmp $KSRCLINK sleep 2 kill_manual_progress gtk_message "The kernel sources were 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 [ ! -e /usr/src/linux/System.map ] && 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 2>/dev/null [ -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/vbox.png 64 '`txtsize 400 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 if [ $ARCH = "x86_64" ]; then VBOXVER=`lynx -dump $DRIVERURL/LATEST.TXT` else VBOXVER=`lynx -dump $DRIVERURL/LATEST-32BIT.TXT` fi FILELINK=`lynx -dump -nonumbers -listonly $DRIVERURL/$VBOXVER|grep .run|grep $NARCH` BLURBFILE="VirtualBox $VBOXVER" ;; vboxguest ) echo "Getting vbox links ..." > /tmp/.message if [ $ARCH = "x86_64" ]; then VBOXVER=`lynx -dump $DRIVERURL/LATEST.TXT` else VBOXVER=`lynx -dump $DRIVERURL/LATEST-32BIT.TXT` fi FILELINK=$DRIVERURL/$VBOXVER/VBoxGuestAdditions_$VBOXVER.iso BLURBFILE="VirtualBox $VBOXVER guest addons" cleanup [ ! -d /mnt/guestiso ] && mkdir /mnt/guestiso ;; esac FNAME=${FILELINK##*/} ## Download the file sleep 2 kill_manual_progress export STATE=DOWNLOAD manual_progress "Downloading $BLURBFILE" export 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-$ARCH-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 ## Create the command dfile if [ "$ARCH" == "x86_64" ]; then LIB="lib64"; else LIB="lib"; fi LOG=/var/log/vbox-log.log cat > $WRK/commands << EOF clear sh $FULLPATH &>/dev/null WRK=/tmp/gtk-driver-builder BUILD=$WRK/build find /etc /lib /usr /sbin | egrep "vbox|virtualbox|VBox|VirtualBox" | xargs -n1 -i cp -r --parents {} $BUILD/ cp -r --parents /sbin/{vbox*,rcvbox*} $BUILD/ cp -r --parents /opt/VirtualBox $BUILD/ cp -r --parents /usr/bin/rdesktop-vrdp $BUILD/ for a in \`seq 0 6\`; do cp -r --parents /etc/rc.d/rc${a}.d/{K[0-9][0-9]vbox*,S[0-9][0-9]vbox*} $BUILD/ 2>/dev/null done clear ### Please click the OK button to continue EOF chmod 777 $WRK/commands chmod +x $WRK/commands ;; vboxguest ) TARGMOD=/tmp/vbox-guest-$VBOXVER-porteus-$LVER-$ARCH-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. /opt/VBoxGuestAdditions-$VBOXVER/sbin/VBoxService --pidfile /opt/VBoxGuestAdditions-$VBOXVER/init/vboxadd # 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. /opt/VBoxGuestAdditions-$VBOXVER/sbin/VBoxService --pidfile /opt/VBoxGuestAdditions-$VBOXVER/init/vboxadd-service # 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. /opt/VBoxGuestAdditions-$VBOXVER/sbin/VBoxService --pidfile /opt/VBoxGuestAdditions-$VBOXVER/init/vboxadd-x11 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 &>/dev/null WRK=/tmp/gtk-driver-builder BUILD=$WRK/build if [ $ARCH == "x86_64" ]; then LIB="lib64"; else LIB="lib"; fi cp -r --parents /etc/rc.d/{rc.vboxadd,rc.vboxadd-service,rc.vboxadd-x11} $BUILD/ cp -r --parents /etc/rc.d/init.d/{vboxdrv,vboxballoonctrl-service,vboxautostart-service,vboxweb-service} $BUILD/ cp -r --parents /etc/rc.d/rc0.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc1.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc2.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc3.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc4.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc5.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/rc.d/rc6.d/K[0-9][0-9]vbox* $BUILD/ cp -r --parents /etc/vbox/vbox.cfg $BUILD/ cp -r --parents /etc/vbox/filelist $BUILD/ cp -r --parents /etc/udev/rules.d/60-vbox* $BUILD/ cp -r --parents /etc/xdg/autostart/vboxclient.desktop $BUILD/ cp -r $BUILD/etc/xdg/autostart/vboxclient.desktop $BUILD/usr/share/autostart/ cp -r --parents /lib/modules/`uname -r`/misc/{vboxguest.ko,vboxsf.ko,vboxvideo.ko,vboxpci.ko,vboxnetadp.ko,vboxnetflt.ko,vboxdrv.ko} $BUILD/ cp -r --parents /opt/VBoxGuestAdditions-* $BUILD/ cp -r --parents /sbin/mount.vboxsf $BUILD/ cp -r --parents /usr/bin/{VBoxClient,VBoxClient-all,VBoxControl} $BUILD/ cp -r --parents /usr/$LIB/dri/vboxvideo_dri.so $BUILD/ cp -r --parents /usr/$LIB/xorg/modules/dri/vboxvideo_dri.so $BUILD cp -r --parents /usr/$LIB/xorg/modules/drivers/vboxvideo_drv.so $BUILD/ cp -r --parents /usr/$LIB/VBoxGuestAdditions $BUILD/ cp -r --parents /usr/$LIB/VBoxOGL* $BUILD/ cp -r --parents /usr/sbin/VBoxService $BUILD/ cp -r --parents /usr/share/VBoxGuestAdditions $BUILD/ cp -r --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 '`txtsize 450 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; } ## Create user(guest) config create_config () { mkdir -p $BUILD/home/guest/.config/VirtualBox echo ' ' > $BUILD/home/guest/.config/VirtualBox/VirtualBox.xml } ## Build the final module export STATE=BUILDMODULE manual_progress "$BLURBFILE module building ..." create_config find $BUILD -type d | xargs -n1 -i chmod 755 {} chown -R guest:users $BUILD/home/guest chown root:root $BUILD/opt/VirtualBox/VirtualBox chmod -s $BUILD/opt/VirtualBox/VirtualBox chmod +s $BUILD/opt/VirtualBox/VirtualBoxVM 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 /opt/VirtualBox/uninstall.sh cleanup