Skip to content

Commit

Permalink
--destroy-all WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adrelanos committed Jan 8, 2024
1 parent 6457a15 commit 986472f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions man/dist-installer-cli.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ format <guest-interface-installer>.
Warning: This action poses a risk of data loss as it involves
a complete reinstallation of the VM(s). Proceed with caution.

`--destroy-all`

Deletes both VMs, gateway and workstation. Only if guest is Whonix.

`-P`, `--directory-prefix`=<directory>

Define the absolute path directory to store downloaded files. Defaults to
Expand Down
35 changes: 26 additions & 9 deletions usr/bin/dist-installer-cli
Original file line number Diff line number Diff line change
Expand Up @@ -1432,25 +1432,29 @@ vm_delete_maybe() {
if test "${destroy_existing_guest}" = "1"; then
## Remove Gateway if it exists when using --destroy-existing-guest.
if test "${gateway_exists}" = "1"; then
## Do not remove gateway if import_only is set to workstation
## Do not remove gateway if '--import-only' option is set to 'workstation'.
if test "${import_only}" = "workstation" ; then
log info "VM Deletion: 'no' - Although using '--destroy-existing-guest' option, not deleting previously imported gateway because '--import-only' option is set to 'workstation'."
log info "If you wish to reimport (re-install) both, gateway and workstation, do not specify the '--import-only' option."
else
log warn "VM Deletion: 'yes' - Deleting previously imported gateway via '--destroy-existing-guest' option..."
elif test "${destroy_all}" = "1" ; then
log warn "VM Deletion: 'yes' - Deleting previously imported gateway via '--destroy-all' option..."
log_run notice vboxmanage unregistervm "${guest_full_vm_name_gateway}" --delete
else
log warn "VM Deletion: 'no' - Not deleting previously imported gateway via because neither using '--import-only' nor '--destroy-all' option..."
fi
fi

## Remove Workstation if it exists when using --destroy-existing-guest.
## Remove Workstation if it exists when using '--destroy-existing-guest' option.
if test "${workstation_exists}" = "1" ; then
## Do not remove workstation if import_only is set to gateway
## Do not remove workstation if '--import-only' option is set to 'gateway'.
if test "${import_only}" = "gateway" ; then
log info "VM Deletion: 'no' - Although using '--destroy-existing-guest' option, not deleting previously imported workstation because '--import-only' option is set to 'gateway'."
log info "If you wish to reimport (re-install) both, gateway and workstation, do not specify the '--import-only' option."
else
log warn "VM Deletion: 'yes' - Deleting previously imported workstation via '--destroy-existing-guest' option."
elif test "${destroy_all}" = "1" ; then
log warn "VM Deletion: 'yes' - Deleting previously imported workstation via '--destroy-all' option..."
log_run notice vboxmanage unregistervm "${guest_full_vm_name_workstation}" --delete
else
log warn "VM Deletion: 'no' - Not deleting previously imported workstation via because neither using '--import-only' nor '--destroy-all' option..."
fi
fi
elif test -n "${import_only}" ; then
Expand All @@ -1459,7 +1463,7 @@ vm_delete_maybe() {
elif test "${workstation_exists}" = "1" && test "${import_only}" = "workstation" ; then
die 1 "${underline}Existing VM Check Result:${nounderline} '--import-only' option was set to 'workstation', but it already exists and '--destroy-existing-guest' option was not set."
fi
log info "${underline}Existing VM Check:${nounderline} '--destroy-existing-guest' was not set and import_only was also not set to the same machine that already exists, ok."
log info "${underline}Existing VM Check:${nounderline} '--destroy-existing-guest' option was not set. Neither '--import-only' option was set to the same machine that already exists, ok."
fi
;;
kicksecure)
Expand Down Expand Up @@ -3708,6 +3712,7 @@ Developer options:
--destroy-existing-guest Deletes any existing virtual machine(s) and re-imports them.
Warning: This action poses a risk of data loss as it involves
a complete reinstallation of the VM(s). Proceed with caution.
--destroy-all Deletes both VMs, gateway and workstation. Only if guest is Whonix.
-k, --no-boot Do not boot the guest after setup. Default is to start.
-P, --directory-prefix=<dir>
Specify the absolute path for the directory where
Expand Down Expand Up @@ -3766,6 +3771,7 @@ set_default(){
no_boot=""
redownload=""
import_only=""
destroy_all=""
destroy_existing_guest=""
testers=""
allow_errors=""
Expand Down Expand Up @@ -3862,6 +3868,9 @@ parse_opt(){
redownload)
set_arg redownload 1
;;
destroy-all)
set_arg destroy_all 1
;;
destroy-existing-guest)
set_arg destroy_existing_guest 1
;;
Expand Down Expand Up @@ -3934,7 +3943,15 @@ parse_opt(){
esac

if test "${guest}" != "whonix" && test -n "${import_only}"; then
die 1 "The option import_only can only be set when the guest is whonix."
die 1 "The option '--import-only' option can only be set when the guest is 'whonix'."
fi
if test "${guest}" != "whonix" && test -n "${destroy_all}}"; then
die 1 "The option '--destroy-all' option can only be set when the guest is 'whonix'."
fi
if test "${destroy_all}" = "1" && test -n "${import_only}"; then
## Maybe makes sense in theory but the code getting too complex.
## Best to run twice in this corner case.
die 1 "The option '--import-only' option cannot be combined with '--destroy-all'."
fi
test -n "${mirror}" && range_arg mirror 0 1 2

Expand Down
2 changes: 1 addition & 1 deletion usr/share/bash-completion/completions/dist-installer-cli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _dist_installer_cli()

case $prev in
--guest-version | --socks-proxy | --onion | --non-interactive | \
--no-import | --no-boot | --redownload | \
--no-import | --no-boot | --redownload | --destroy-all \
--destroy-existing-guest | --dev | --ci | --dry-run | \
--getopt | --no-show-errors | --allow-errors | --testers | \
--virtualbox-only | --oracle-repo | --version | --help )
Expand Down
1 change: 1 addition & 0 deletions usr/share/zsh/vendor-completions/_dist-installer-cli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ args=(
'(--import-only)'--import-only='[Set VM to import when using whonix]:<vms>:->vms'
'(-k --no-boot)'{-k,--no-boot}'[Do not boot guest]'
'(--redownload)'--redownload'[Redo download]'
'(--destroy-all)'--destroy-all'[Delete and re-import both, gateway and workstation.]'
'(--destroy-existing-guest)'--destroy-existing-guest'[Delete and re-import. Danger! Risk of data loss!]'
'(-n --non-interactive)'{-n,--non-interactive}'[Set non-interactive mode]'
'(--allow-errors)'--allow-errors'[Set dirty mode]'
Expand Down

0 comments on commit 986472f

Please sign in to comment.