file#
File/dir helpers and download utilities.
Functions#
- command_exists name
-
Purpose: Return success if a command is available in PATH.
-
directory_exists path
- file_exists path
-
Purpose: Test for directory/file existence.
-
create_directory path
-
Purpose: Create a directory if missing; prints a message. Returns 0 on success or if it already exists.
-
download_file url [output]
- Purpose: Download a file using
curlorwget. - Behavior:
- If
dialogis installed andDOWNLOAD_USE_DIALOGis notfalse/0/never, automatically usesdialog::dialog_download_filefor a progress gauge. - Falls back silently to
curlorwgetwith minimal output.curlruns with-f, so an HTTP error (404, 500, ...) is a failure rather than an error page saved as the file. - The download goes to a temporary file beside the destination (
output.XXXXXX) and is moved into place only on success, with the mode the umask gives a new file. On failure the temporary file is removed: no partial or error-page file is left at the destination, and a file that was already there is left untouched.
- If
- Returns: 0 on success; the downloader's non-zero status on failure; 1 when neither
curlnorwgetis installed or the temporary file cannot be created. - Args:
- url - source URL.
- output - destination path; default derived from URL.
-
Env:
DOWNLOAD_USE_DIALOG:auto(default) |true/1|false/0/never.
-
is_valid_iso file
-
Purpose: Heuristically check if a file is an ISO image (via
file). -
is_valid_checksum file
-
Purpose: Heuristically check if a file looks like an ASCII checksum list.
-
verify_checksum iso_file checksum_file [checksum_type=sha256sum]
- Purpose: Verify checksum using the specified tool (e.g.,
sha256sum). - Behavior: Finds the entry for
iso_file's basename inchecksum_file(HASH name,HASH *name, or taggedALGO (name) = HASH; a listed path matches on its basename), hashesiso_filewithchecksum_type, and compares (case-insensitive). Other entries in the list do not matter. Withshasum, whose default is SHA-1, the algorithm is chosen from the length of the listed digest (40, 56, 64, 96, 128 hex digits: SHA-1, -224, -256, -384, -512), asshasum -cdoes. -
Returns: 0 when that entry exists and matches; 1 when it does not match, when the list has no entry for the file, or when the tool is missing; prints success/error.
-
download_iso distro_name
- Requires bash 4.0 or newer: it reads a
DISTROSassociative array supplied by the caller, and callsrequire_bash4when the shell is older. - Purpose: Download ISO based on a
DISTROSassociative array defined by the caller. - Behavior: When the output file already exists, the download is skipped (with a warning) and the existing file is validated; otherwise downloads it. Prints success/error; validates ISO structure.
Dependencies#
curlorwgetfor download,dialogfor optional UI,filefor validation.