Skip to content

Commit

Permalink
vboxmanage
Browse files Browse the repository at this point in the history
  • Loading branch information
adrelanos committed May 17, 2024
1 parent 52f445e commit 974286f
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions usr/bin/dist-installer-cli
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,8 @@ check_vm_running_virtualbox(){
## Paused state should be considered as running. Instead of grepping
## possible states, grep VM from list of running VMs.
# vboxmanage list runningvms | grep -q "^\"${vm}\" "
if $vboxmanage showvminfo "${vm}" 2>&1 | \
# shellcheck disable=SC2086
if ${vboxmanage_locale_english} showvminfo "${vm}" 2>&1 | \
grep -qE "^State:[[:space:]]+(running|paused)"
then
log error "Cannot proceed. You have the following VM running: ${vm}"
Expand All @@ -1360,11 +1361,13 @@ check_vm_registered_virtualbox(){
## Test if machine exists.
workstation_exists=0
gateway_exists=0
if $vboxmanage showvminfo "${guest_full_vm_name_gateway}" >/dev/null 2>&1 ; then
# shellcheck disable=SC2086
if ${vboxmanage_locale_english} showvminfo "${guest_full_vm_name_gateway}" >/dev/null 2>&1 ; then
gateway_exists=1
log info "Existing VM Check Result $extra_message: guest '${guest_full_vm_name_gateway}' exists."
fi
if $vboxmanage showvminfo "${guest_full_vm_name_workstation}" >/dev/null 2>&1 ; then
# shellcheck disable=SC2086
if ${vboxmanage_locale_english} showvminfo "${guest_full_vm_name_workstation}" >/dev/null 2>&1 ; then
workstation_exists=1
log info "Existing VM Check Result $extra_message: guest '${guest_full_vm_name_workstation}' exists."
fi
Expand All @@ -1389,7 +1392,8 @@ check_vm_registered_virtualbox(){
;;
kicksecure)
vm_or_vms_already_existing_test_result=false
if ! $vboxmanage showvminfo "${guest_full_vm_name_kicksecure}" >/dev/null 2>&1 ; then
# shellcheck disable=SC2086
if ! ${vboxmanage_locale_english} showvminfo "${guest_full_vm_name_kicksecure}" >/dev/null 2>&1 ; then
log info "Existing VM Check Result $extra_message: None existing yet, ok."
return 0
fi
Expand Down Expand Up @@ -1462,7 +1466,7 @@ File '$file_name_item' exists but there is no associated VM registered in Virtua

vm_delete_kicksecure() {
if test "${vm_or_vms_already_existing_test_result}" = "true"; then
log_run notice $vboxmanage unregistervm "${guest_full_vm_name_kicksecure}" --delete
log_run notice vboxmanage unregistervm "${guest_full_vm_name_kicksecure}" --delete
else
log notice "VM Deletion: Kicksecure VM does not exist, no need to delete, ok."
fi
Expand All @@ -1471,7 +1475,7 @@ vm_delete_kicksecure() {

vm_delete_gateway() {
if test "${gateway_exists}" = "1"; then
log_run notice $vboxmanage unregistervm "${guest_full_vm_name_gateway}" --delete
log_run notice vboxmanage unregistervm "${guest_full_vm_name_gateway}" --delete
else
log notice "VM Deletion: Gateway VM does not exist, no need to delete, ok."
fi
Expand All @@ -1480,7 +1484,7 @@ vm_delete_gateway() {

vm_delete_workstation() {
if test "${workstation_exists}" = "1"; then
log_run notice $vboxmanage unregistervm "${guest_full_vm_name_workstation}" --delete
log_run notice vboxmanage unregistervm "${guest_full_vm_name_workstation}" --delete
else
log notice "VM Deletion: Workstation VM does not exist, no need to delete, ok."
fi
Expand Down Expand Up @@ -1765,7 +1769,7 @@ import_virtualbox(){

local output
# shellcheck disable=SC2086
output=$(log_run notice $vboxmanage import "${directory_prefix}/${guest_file}.${guest_file_ext}" ${vbox_arg_normal} --dry-run) || \
output=$(log_run notice ${vboxmanage_locale_english} import "${directory_prefix}/${guest_file}.${guest_file_ext}" ${vbox_arg_normal} --dry-run) || \
die 105 "${underline}VM Import:${nounderline} Failed to import virtual machines."

case "${guest}" in
Expand Down Expand Up @@ -1794,14 +1798,15 @@ import_virtualbox(){

## import VirtualBox image
# shellcheck disable=SC2086
log_run notice $vboxmanage import "${directory_prefix}/${guest_file}.${guest_file_ext}" ${vbox_arg_general} || \
log_run notice ${vboxmanage_locale_english} import "${directory_prefix}/${guest_file}.${guest_file_ext}" ${vbox_arg_general} || \
die 105 "${underline}VM Import:${nounderline} Failed to import virtual machines."

## VirtualBox does not accept any command to import a single virtual system
## out from an ova with multiple ones.
## https://forums.virtualbox.org/viewtopic.php?f=1&t=107965
if test -n "${import_only}" && test "${import_only}" != "both"; then
log_run notice $vboxmanage unregistervm "${vm_purge}" --delete ||
# shellcheck disable=SC2086
log_run notice ${vboxmanage_locale_english} unregistervm "${vm_purge}" --delete ||
die 1 "${underline}VM Import:${nounderline} Failed to remove extraneous VM '${vm_purge}'."
fi

Expand Down Expand Up @@ -1841,14 +1846,14 @@ start_virtualbox_vm() {
case "${guest}" in
whonix)
if test "${gateway_exists}" = "1" ; then
log_run notice $vboxmanage startvm "${guest_full_vm_name_gateway}" || virtualbox_start_failed
log_run notice vboxmanage startvm "${guest_full_vm_name_gateway}" || virtualbox_start_failed
fi
if test "${workstation_exists}" = "1" ; then
log_run notice $vboxmanage startvm "${guest_full_vm_name_workstation}" || virtualbox_start_failed
log_run notice vboxmanage startvm "${guest_full_vm_name_workstation}" || virtualbox_start_failed
fi
;;
kicksecure)
log_run notice $vboxmanage startvm "${guest_full_vm_name_kicksecure}" || virtualbox_start_failed
log_run notice vboxmanage startvm "${guest_full_vm_name_kicksecure}" || virtualbox_start_failed
;;
esac
log notice "${underline}Virtual Machine Startup Result:${nounderline} 'success'"
Expand Down Expand Up @@ -3925,7 +3930,7 @@ set_default(){
install_pkg_fasttrack_extra_args_maybe=""
user_warned_potential_startup_issue=""
## 'vboxmanage' locale needs to be "C" (default, English) so output can be grepped.
vboxmanage="env LC_ALL=C.UTF-8 LANG=C.UTF-8 LANGUAGE=C vboxmanage"
vboxmanage_locale_english="env LC_ALL=C.UTF-8 LANG=C.UTF-8 LANGUAGE=C vboxmanage"
}


Expand Down

0 comments on commit 974286f

Please sign in to comment.