Advertisement
Kimarite

VBox.sh

Aug 30th, 2019
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. #!/bin/sh
  2. ## @file
  3. # Oracle VM VirtualBox startup script, Linux hosts.
  4. #
  5.  
  6. #
  7. # Copyright (C) 2006-2017 Oracle Corporation
  8. #
  9. # This file is part of VirtualBox Open Source Edition (OSE), as
  10. # available from http://www.virtualbox.org. This file is free software;
  11. # you can redistribute it and/or modify it under the terms of the GNU
  12. # General Public License (GPL) as published by the Free Software
  13. # Foundation, in version 2 as it comes in the "COPYING" file of the
  14. # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
  15. # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  16. #
  17.  
  18. PATH="/usr/bin:/bin:/usr/sbin:/sbin"
  19.  
  20. # The below is GNU-specific. See slightly further down for a version which
  21. # works on Solaris and OS X.
  22. TARGET=`readlink -e -- "${0}"` || exit 1
  23. MY_DIR="${TARGET%/[!/]*}"
  24.  
  25. # (
  26. # path="${0}"
  27. # while test -n "${path}"; do
  28. # # Make sure we have at least one slash and no leading dash.
  29. # expr "${path}" : / > /dev/null || path="./${path}"
  30. # # Filter out bad characters in the path name.
  31. # expr "${path}" : ".*[*?<>\\]" > /dev/null && exit 1
  32. # # Catch embedded new-lines and non-existing (or path-relative) files.
  33. # # $0 should always be absolute when scripts are invoked through "#!".
  34. # test "`ls -l -d "${path}" 2> /dev/null | wc -l`" -eq 1 || exit 1
  35. # # Change to the folder containing the file to resolve relative links.
  36. # folder=`expr "${path}" : "\(.*/\)[^/][^/]*/*$"` || exit 1
  37. # path=`expr "x\`ls -l -d "${path}"\`" : "[^>]* -> \(.*\)"`
  38. # cd "${folder}"
  39. # # If the last path was not a link then we are in the target folder.
  40. # test -n "${path}" || pwd
  41. # done
  42. # )
  43.  
  44. if test -f /usr/lib/virtualbox/VirtualBox &&
  45. test -x /usr/lib/virtualbox/VirtualBox; then
  46. INSTALL_DIR=/usr/lib/virtualbox
  47. elif test -f "${MY_DIR}/VirtualBox" && test -x "${MY_DIR}/VirtualBox"; then
  48. INSTALL_DIR="${MY_DIR}"
  49. else
  50. echo "Could not find VirtualBox installation. Please reinstall."
  51. exit 1
  52. fi
  53.  
  54. # Note: This script must not fail if the module was not successfully installed
  55. # because the user might not want to run a VM but only change VM params!
  56.  
  57. if [ "$1" = "shutdown" ]; then
  58. SHUTDOWN="true"
  59. elif ! lsmod|grep -q vboxdrv; then
  60. cat << EOF
  61. WARNING: The vboxdrv kernel module is not loaded. Either there is no module
  62. available for the current kernel (`uname -r`) or it failed to
  63. load. Please recompile the kernel module and install it by
  64.  
  65. sudo /sbin/vboxconfig
  66.  
  67. You will not be able to start VMs until this problem is fixed.
  68. EOF
  69. elif [ ! -c /dev/vboxdrv ]; then
  70. cat << EOF
  71. WARNING: The character device /dev/vboxdrv does not exist. Try
  72.  
  73. sudo /sbin/vboxconfig
  74.  
  75. and if that is not successful, try to re-install the package.
  76.  
  77. You will not be able to start VMs until this problem is fixed.
  78. EOF
  79. fi
  80.  
  81. if [ -f /etc/vbox/module_not_compiled ]; then
  82. cat << EOF
  83. WARNING: The compilation of the vboxdrv.ko kernel module failed during the
  84. installation for some reason. Starting a VM will not be possible.
  85. Please consult the User Manual for build instructions.
  86. EOF
  87. fi
  88.  
  89. SERVER_PID=`ps -U \`whoami\` | grep VBoxSVC | awk '{ print $1 }'`
  90. if [ -z "$SERVER_PID" ]; then
  91. # Server not running yet/anymore, cleanup socket path.
  92. # See IPC_GetDefaultSocketPath()!
  93. if [ -n "$LOGNAME" ]; then
  94. rm -rf /tmp/.vbox-$LOGNAME-ipc > /dev/null 2>&1
  95. else
  96. rm -rf /tmp/.vbox-$USER-ipc > /dev/null 2>&1
  97. fi
  98. fi
  99.  
  100. if [ "$SHUTDOWN" = "true" ]; then
  101. if [ -n "$SERVER_PID" ]; then
  102. kill -TERM $SERVER_PID
  103. sleep 2
  104. fi
  105. exit 0
  106. fi
  107.  
  108. APP=`basename $0`
  109. case "$APP" in
  110. VirtualBox|virtualbox)
  111. exec "$INSTALL_DIR/VirtualBox" "$@"
  112. ;;
  113. VBoxManage|vboxmanage)
  114. exec "$INSTALL_DIR/VBoxManage" "$@"
  115. ;;
  116. VBoxSDL|vboxsdl)
  117. exec "$INSTALL_DIR/VBoxSDL" "$@"
  118. ;;
  119. VBoxVRDP|VBoxHeadless|vboxheadless)
  120. exec "$INSTALL_DIR/VBoxHeadless" "$@"
  121. ;;
  122. VBoxAutostart|vboxautostart)
  123. exec "$INSTALL_DIR/VBoxAutostart" "$@"
  124. ;;
  125. VBoxBalloonCtrl|vboxballoonctrl)
  126. exec "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
  127. ;;
  128. VBoxBugReport|vboxbugreport)
  129. exec "$INSTALL_DIR/VBoxBugReport" "$@"
  130. ;;
  131. VBoxDTrace|vboxdtrace)
  132. exec "$INSTALL_DIR/VBoxDTrace" "$@"
  133. ;;
  134. vboxwebsrv)
  135. exec "$INSTALL_DIR/vboxwebsrv" "$@"
  136. ;;
  137. *)
  138. echo "Unknown application - $APP"
  139. exit 1
  140. ;;
  141. esac
  142. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement