Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ normalizeSize() {
local diskDesc="$2"
local dir="$3"

local gb free space
local dataSize spare=1073741824
local free dataSize
local spare=1073741824

if [[ "${diskSpace,,}" == "max" || "${diskSpace,,}" == "half" ]]; then

Expand All @@ -154,12 +154,12 @@ normalizeSize() {
fi

(( free < spare )) && free="$spare"
gb=$(( free / 1073741825 ))
local gb=$(( free / 1073741825 ))
diskSpace="${gb}G"

fi

space="${diskSpace// /}"
local space="${diskSpace// /}"
[ -z "$space" ] && space="64G"
[ -z "${space//[0-9. ]}" ] && space="${space}G"
space=$(echo "${space^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
Expand Down Expand Up @@ -618,13 +618,12 @@ addDisk () {
local diskCache="$9"

local fs dir used space
local diskExt diskFile
local dataSize missing
local diskExt dataSize
local available currentSize
local previousExt previousFmt
local previousExt

diskExt=$(fmt2ext "$diskFmt")
diskFile="$diskBase.$diskExt"
local diskFile="$diskBase.$diskExt"

dir=$(dirname "$diskFile")
[ ! -d "$dir" ] && return 0
Expand All @@ -647,9 +646,9 @@ addDisk () {
if [ ! -f "$diskFile" ] || [ ! -s "$diskFile" ]; then

if [[ "${diskFmt,,}" != "raw" ]]; then
previousFmt="raw"
local previousFmt="raw"
else
previousFmt="qcow2"
local previousFmt="qcow2"
fi

previousExt=$(fmt2ext "$previousFmt")
Expand Down Expand Up @@ -691,18 +690,18 @@ addDisk () {
currentSize=$(getSize "$diskFile") || exit 73
used=$(du -sB 1 "$diskFile" | cut -f1)
available=$(df --output=avail -B 1 "$dir" | tail -n 1)
missing=$(( currentSize - used - available ))
local missing=$(( currentSize - used - available ))
(( missing < 0 )) && missing=0

if (( missing > 0 )); then

local gb base msg
local gb base

gb=$(formatBytes "$available")
base=$(baseDir "$dir")
missing=$(formatBytes "$missing")
currentSize=$(formatBytes "$currentSize")
msg="The virtual size of the ${diskDesc,,} is $currentSize"
local msg="The virtual size of the ${diskDesc,,} is $currentSize"

if [ -n "$used" ] && [[ "$used" != "0" ]]; then
used=$(formatBytes "$used")
Expand Down
45 changes: 18 additions & 27 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ getBase() {

getFolder() {

local base=""
local base
local result="$1"

if [[ "$result" != *"."* ]]; then
Expand Down Expand Up @@ -70,8 +70,7 @@ bootFile() {
detectRawDiskMode() {

local file="$1"
local result=""
local mode=""
local result mode

if [ ! -r "$file" ]; then
error "Failed to read disk image \"$file\"!"
Expand Down Expand Up @@ -125,7 +124,7 @@ detectRawDiskMode() {
isLegacyIso() {

local file="$1"
local result=""
local result

if ! result=$(LC_ALL=C xorriso \
-no_rc \
Expand Down Expand Up @@ -205,19 +204,12 @@ detectQcow2Mode() {
local file="$1"
local found="N"
local protective="N"
local signature=""
local tmp=""
local type=""
local offset=""
local actual_size=0

local entry_lba=""
local entry_count=""
local entry_size=""
local entry_units=0
local table_size=0
local table_sectors=0
local expected_size=0
local tmp type offset
local signature actual_size

local entry_lba
local entry_count
local entry_size

if ! tmp=$(mktemp "$QEMU_DIR/boot-mode.XXXXXX"); then
error "Failed to create temporary boot detection file!"
Expand Down Expand Up @@ -316,7 +308,7 @@ detectQcow2Mode() {
return 1
fi

entry_units=$((entry_size / 128))
local entry_units=$((entry_size / 128))

if (( entry_lba < 2 ||
entry_count < 1 ||
Expand All @@ -330,7 +322,7 @@ detectQcow2Mode() {
return 1
fi

table_size=$((entry_count * entry_size))
local table_size=$((entry_count * entry_size))

# Protect against corrupt images requesting an excessive read.
if (( table_size > 16777216 )); then
Expand All @@ -339,8 +331,8 @@ detectQcow2Mode() {
return 1
fi

table_sectors=$(((table_size + 511) / 512))
expected_size=$((table_sectors * 512))
local table_sectors=$(((table_size + 511) / 512))
local expected_size=$((table_sectors * 512))

if ! readQcow2Sectors \
"$file" "$entry_lba" "$table_sectors" "$tmp"; then
Expand Down Expand Up @@ -450,13 +442,12 @@ downloadFile() {
local expected="${4:-0}"
local connections="${5:-1}"
local dest="$STORAGE/$base"
local msg

if [ -z "$name" ]; then
msg="Downloading image"
local msg="Downloading image"
info "Downloading $base..."
else
msg="Downloading $name"
local msg="Downloading $name"
info "Downloading $name..."
fi

Expand All @@ -476,7 +467,7 @@ convertImage() {
local dst_file=$3
local dst_fmt=$4
local dir base fs fa space space_gb
local cur_size cur_gb src_size disk_param
local cur_size cur_gb src_size

[ -f "$dst_file" ] && error "Conversion failed, destination file $dst_file already exists?" && return 1
[ ! -f "$source_file" ] && error "Conversion failed, source file $source_file does not exists?" && return 1
Expand Down Expand Up @@ -521,9 +512,9 @@ convertImage() {
local conv_flags="-p"

if [ -z "$ALLOCATE" ] || disabled "$ALLOCATE"; then
disk_param="preallocation=off"
local disk_param="preallocation=off"
else
disk_param="preallocation=falloc"
local disk_param="preallocation=falloc"
fi

if ! fs=$(stat -f -c %T "$dir"); then
Expand Down
Loading