1. #!/bin/ash
  2. #110612 TazOC Based on install_virtualbox.sh by jamesbond 2011.02.11
  3. #110810 Improved the extension pack installer to dl the latest version
  4. #130311 Increased free space test to 220MiB
  5. #130319 TaZoC pfix=noautosave PUPMODE=14,15 (savefile writes on user request only.)
  6. APPTITLE="VirtualBox_Installer"
  7. APPNAME="virtualbox"
  8. ICON="/usr/share/icons/virtualbox.png"
  9. . /etc/DISTRO_SPECS
  10. . /etc/rc.d/PUPSTATE
  11. export LANG=C
  12. [ -f /etc/issue.net ] && [ "`grep Lighthouse /etc/issue.net`" ] && VERSION="`cat /etc/issue.net | tr -d '\n'`"
  13. [ -z "$VERSION" ] && VERSION="$DISTRO_NAME $DISTRO_VERSION"
  14. if [ -z "`echo $VERSION | grep 'Lighthouse64'`" ]; then # Test for L64 version
  15. ICON="/usr/local/lib/X11/pixmaps/info.xpm"
  16. MSG="\n This Pet requires Lighthouse 64.\n\n
  17. As $VERSION was detected the Pet \n may not work as intended and should be uninstalled\n with Puppy Package Manager. \n"
  18. Xdialog --title "$APPTITLE" --wmclass "$APPNAME" \
  19. --icon $ICON --left --cancel-label "Exit" \
  20. --left --msgbox "$MSG" 0 0 0
  21. exit
  22. fi
  23. f=`df -m / |tail -n1|tr -s ' ' | cut -d ' ' -f4`
  24. if [ $f -lt 220 ];then # TazOC #130311
  25. ICON="/usr/local/lib/X11/pixmaps/info.xpm"
  26. MSG="\n There is not enough free space to run $APPTITLE. \n\n Need: 220 MiB, have: $f MiB. \n"
  27. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --left --msgbox "$MSG" 0 0 0
  28. exit 1
  29. fi
  30. if ! which make || ! which gcc; then
  31. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --left --msgbox "\n make or gcc not found. Please install Devx-${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs first. \n" 0 0 0
  32. exit 1
  33. fi
  34. if [ "$1" != "--noprompt" ]; then
  35. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --no-buttons --left --yesno "\n Would you like to download and install the latest version? \n" 0 0 0
  36. case $? in
  37. 0) ;;
  38. 1) exit 0 ;; # Pressed cancel, end script
  39. 255) exit 0 ;; # Box closed, end script
  40. esac
  41. fi
  42. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --no-buttons --left --msgbox "\n Downloading, please wait... \n" 0 0 0 &
  43. PID=$!
  44. cd /tmp
  45. TMPFILE=$(mktemp)
  46. wget -O $TMPFILE http://dlc.sun.com/virtualbox/LATEST.TXT
  47. VERSION=$(cat $TMPFILE)
  48. wget -O $TMPFILE http://dlc.sun.com/virtualbox/$VERSION/
  49. FILE=$(sed -n '/amd64\.run/ {s/^.*"\(V.*_amd64.run\)".*$/\1/;p}' $TMPFILE | tail -1)
  50. EXTPACK=$(sed -n '/vbox-extpack/ {s/^.*"\(O.*vbox-extpack\)".*$/\1/;p}' $TMPFILE | tail -1)
  51. rm $TMPFILE
  52. [ "`which zenity`" ] && kill $PID
  53. wget -nd -c --read-timeout=300 --retry-connrefused --header "Accept-Encoding: gzip,deflate" "http://dlc.sun.com/virtualbox/$VERSION/$EXTPACK" 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ /\1\n# Downloading /' | zenity --width 620 --progress --auto-close --title="Downloading $EXTPACK to /tmp..."
  54. sleep .1
  55. wget -nd -c --read-timeout=300 --retry-connrefused --header "Accept-Encoding: gzip,deflate" "http://dlc.sun.com/virtualbox/$VERSION/$FILE" 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ /\1\n# Downloading /' | zenity --width 620 --progress --auto-close --title="Downloading $FILE to /tmp..." &
  56. PID=$!
  57. sleep .2
  58. [ "$PID" = "" ] && PID=`pidof zenity`
  59. # If user exits zenity progress box, kill wget
  60. while [ "$(ps | sed -e 's%^ *%%' | grep "$PID" | grep -v 'grep')" ]
  61. do
  62. sleep 1
  63. done
  64. sleep .1
  65. WGET_PID="$(ps l | tr -s ' ' | grep -E "wget.*VirtualBox" | grep -v 'grep' | cut -f3 -d' ')"
  66. if [ "$WGET_PID" ]; then
  67. kill $WGET_PID
  68. Xdialog --title "$APPTITLE" --wmclass $APPTITLE --left --no-buttons --msgbox "\n The download was interrupted. \n\n The partial download can be resumed later by restarting the installer. \n" 0 0 0 &
  69. exit 1
  70. fi
  71. sync
  72. chmod +x $FILE
  73. if [ -e /tmp/${EXTPACK} ]; then
  74. rm -fR /opt/VirtualBox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack
  75. mkdir -p /opt/VirtualBox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack
  76. cd /opt/VirtualBox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack
  77. tar -zxf /tmp/${EXTPACK}
  78. sleep .1
  79. cd ..
  80. chown -R root:root .
  81. cd /tmp
  82. fi
  83. [ -z "`which zenity`" ] && kill $PID
  84. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --left --no-buttons --msgbox "\n Installing, this will take a while... \n\n Please wait until the terminal window finishes, \n then click on it and press <Enter> to continue. \n" 0 0 0 &
  85. PID=$!
  86. ./$FILE
  87. kill $PID
  88. mkdir -p "$HOME/.VirtualBox"
  89. cp -f /usr/local/VirtualBox_Installer/virtualbox-uninstaller.desktop /usr/share/applications/
  90. if [ -z "$(echo $PUPMODE | grep -E '12|13|14|15')" ]; then #130319
  91. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --left --msgbox "\n Done. The installer is stored at /tmp/$FILE \n in case you want to keep it. \n\n VirtualBox can be started from the System Menu | Oracle VM VirtualBox. \n" 0 0 0
  92. else
  93. Xdialog --title "$APPTITLE" --wmclass $APPNAME --icon "$ICON" --left --yesno "\n OK, the installer is stored at /tmp/$FILE \n in case you want to keep it. \n\n VirtualBox can be started from the System Menu | Oracle VM VirtualBox. \n\n Would you like use frugal-symlink to move and link '$HOME/.VirtualBox' outside \n the ${DISTRO_FILE_PREFIX}save file? This directory will contain a large .vdi (virtual disk image) \n for each OS to be installed. \n" 0 0 0
  94. retval=$?
  95. case $retval in
  96. 0) if [ -s /etc/${DISTRO_FILE_PREFIX}/frugal-symlink ]; then
  97. # If f-s was disabled prior, need to re-enable...
  98. [ "`head -1 /etc/${DISTRO_FILE_PREFIX}/frugal-symlink`" != 'YES' ] && frugal-symlink "$HOME/.VirtualBox" .VirtualBox --setup
  99. fi
  100. frugal-symlink "$HOME/.VirtualBox" .VirtualBox &
  101. sleep .3
  102. ;;
  103. 1) ;; # Pressed cancel
  104. 255) ;; # Box closed
  105. esac
  106. frugal-symlink /opt/VirtualBox VirtualBox &
  107. fi