Skip to content

Commit

Permalink
add --redownload
Browse files Browse the repository at this point in the history
  • Loading branch information
grass committed Nov 22, 2022
1 parent 966f51e commit ecae899
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
8 changes: 8 additions & 0 deletions auto-generated-man-pages/installer-dist.1
Expand Up @@ -93,6 +93,14 @@ Guest and Interface can be set by changing the script name to the format \fIgues
.fi
.IP "" 0
.P
\fB\-\-redownload\fR
.IP "" 4
.nf
Set option to force download even if flag that files were
successfully download before already exist\.
.fi
.IP "" 0
.P
\fB\-D\fR, \fB\-\-dev\fR
.IP "" 4
.nf
Expand Down
5 changes: 5 additions & 0 deletions man/installer-dist.1.ronn
Expand Up @@ -76,6 +76,11 @@ Guest and Interface can be set by changing the script name to the format
Set non-interactive mode, instead of questions, defaults will be
assumed, including accepting the license and starting the guest.

`--redownload`

Set option to force download even if flag that files were
successfully download before already exist.

`-D`, `--dev`

Set development mode. Set default version to download empty
Expand Down
53 changes: 40 additions & 13 deletions usr/bin/installer-dist
Expand Up @@ -791,7 +791,8 @@ check_license(){
--title "${dialog_title}" \
--yes-label "Agree" \
--no-label "Disagree" \
--yesno "${license}" 640 480
--yesno "${license}" 640 480 || return 1
log notice "User agreed with the license."
;;
whiptail)
## When text is too long and scrolltext is needed, the yesno box
Expand All @@ -802,15 +803,16 @@ check_license(){
--title "${dialog_title}" \
--yes-button "Agree" \
--no-button "Disagree" \
--yesno "${license}" 24 80
--yesno "${license}" 24 80 || return 1
log notice "User agreed with the license."
;;
*)
printf '%s\n' "${license}"
printf '%s' "Do you agree with the license(s)? (yes/no): "
read -r license_agreement
case "${license_agreement}" in
[yY][eE][sS])
true
log notice "User agreed with the license."
;;
*)
log warn "User replied '${license_agreement}'."
Expand Down Expand Up @@ -1333,10 +1335,29 @@ get_download_links(){
die 1 "KVM code is unfinished."
;;
esac
}


## Test if files should be downloaded
should_download(){
if test "${redownload}" = "1"; then
## Do not print further messages as it was already printed before.
## Occurs if the should_download() function was called more than once.
test "${download_msg_done:-}" = "1" && return 0
download_msg_done=1
## Download if redownload option is set.
log notice "Downloading files because redownload is set."
return 0
elif test -f "${download_flag:-}"; then
## Do not download if flag exists.
log notice "Skipping download because flag exists: ${download_flag}."
return 1
fi
## Download as not obstacles prohibit it.
return 0
}


## Self explanatory name, make everything after option parsing.
main(){
set_trap
Expand All @@ -1357,7 +1378,6 @@ main(){
fi
## The license function sleeps for some seconds to give time to abort
check_license || die 100 "User disagreed with the license."
log notice "User agreed with the license."

if test "${dry_run}" = "1"; then
pre_check || true
Expand All @@ -1375,18 +1395,15 @@ main(){
check_vm_exists
fi

## Skip making internet requests if flag already exists and user
## specified the desired version.
## If version is set, use it now to set the download flag path.
if test -n "${guest_version}"; then
guest_file="${guest_pretty}-${interface_all_caps}-${guest_version}"
download_flag="${directory_prefix}/${guest_file}.${guest_file_ext}.flag"
fi

## Skip making internet requests if flag already exists and user specified
## the desired version.
if test -f "${download_flag:-}"; then
log notice "Version: ${guest_version}."
log notice "Skipping download because flag exists: ${download_flag}."
else
if should_download; then
if test "${dry_run}" != "1"; then
log info "Testing internet connection..."
# shellcheck disable=SC2046,SC2086
Expand All @@ -1404,11 +1421,11 @@ main(){
url_guest_file="${url_domain}/${guest_file}"

## Check again for download flag after version was queried.
if test -f "${download_flag}"; then
log notice "Skipping download because flag exists: ${download_flag}."
else
if should_download; then
download_files || die 103 "Failed to download files."
fi
else
log notice "Version: ${guest_version}."
fi

if test "${dry_run}" = "1"; then
Expand Down Expand Up @@ -1455,6 +1472,12 @@ usage(){
-V, --version Show version and quit.
-h, --help Show help for commands and quit.
Developer options:
--redownload Redo the download of the guest instead of stopping if it
was already succesfully downloaded. Won't import files
if already imported, see --reimport option.
--reimport Redo the import of the guest to the hypervisor. Will try
to import already existing files if found. To download
new files, see --redownload option.
-P, --directory-prefix=<dir>
Set directory prefix to save files to. The directory must
already exist and have read and write capabilities for
Expand Down Expand Up @@ -1501,6 +1524,7 @@ set_default(){
getversion=""
getopt=""
skip_guest_boot=""
redownload=""
}


Expand Down Expand Up @@ -1560,6 +1584,9 @@ parse_opt(){
m|hypervisor)
get_arg hypervisor
;;
redownload)
set_arg redownload 1
;;
n|non-interactive)
set_arg non_interactive 1
;;
Expand Down
4 changes: 2 additions & 2 deletions usr/share/bash-completion/completions/installer-dist
Expand Up @@ -13,8 +13,8 @@ _installer_dist()

case $prev in
--guest-version | --socks-proxy | --onion | --non-interactive | \
--skip-guest-boot | --dev | --dry-run | --getopt | --version | \
--help )
--skip-guest-boot | --redownload | --dev | --dry-run | \
--getopt | --version | --help )
return
;;
--directory-prefix )
Expand Down
1 change: 1 addition & 0 deletions usr/share/zsh/vendor-completions/_installer-dist
Expand Up @@ -20,6 +20,7 @@ args=(
'(- *)'{-h,--help}'[Get help for commands and quit]'
'(-l --log-level)'{-l,--log-level=}'[Set logging level]:<level>:->loglevels'
'(-k --skip-guest-boot)'{-k,--skip-guest-boot}'[Set booting guest]'
'(--redownload)'{--redownload}'[Force redownload]'
'(-n --non-interactive)'{-n,--non-interactive}'[Set non-interactive mode]'
'(-D --dev)'{-D,--dev}'[Set dev mode]'
'(-d --dry-run)'{-d,--dry-run}'[Set dry-run mode]'
Expand Down

0 comments on commit ecae899

Please sign in to comment.