Skip to content
Snippets Groups Projects
Verified Commit 1c57448c authored by Christoph Johannes Kleine's avatar Christoph Johannes Kleine
Browse files

installer.sh: improvements to comments and indentation

parent 8c4a30c5
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ export DISK_DEVICES ...@@ -15,7 +15,7 @@ export DISK_DEVICES
# convertSizeToByte - converts a given size to byte # convertSizeToByte - converts a given size to byte
# parameter: # parameter:
# $1 - size in "kB", "MB", "MiB", "GB", "GiB", "TB" or "TiB" # $1 - size in "kB", "kiB", "MB", "MiB", "GB", "GiB", "TB" or "TiB"
# return: # return:
# size in byte # size in byte
convertSizeToByte() { convertSizeToByte() {
...@@ -24,43 +24,43 @@ convertSizeToByte() { ...@@ -24,43 +24,43 @@ convertSizeToByte() {
local factor=1 local factor=1
case ${unit} in case ${unit} in
"B") factor=1;; "B") factor=1;;
"kB") factor=1000 ;; "kB") factor=1000 ;;
"MB") factor=1000000 ;; "MB") factor=1000000 ;;
"GB") factor=1000000000 ;; "GB") factor=1000000000 ;;
"TB") factor=1000000000000 ;; "TB") factor=1000000000000 ;;
"kiB") factor=1024 ;; "kiB") factor=1024 ;;
"MiB") factor=1048576 ;; "MiB") factor=1048576 ;;
"GiB") factor=1073741824 ;; "GiB") factor=1073741824 ;;
"TiB") factor=1099511627776 ;; "TiB") factor=1099511627776 ;;
*) factor=1 ;; *) factor=1 ;;
esac esac
res=$(dc -e "0k ${value} ${factor} * p") res=$(dc -e "0k ${value} ${factor} * p")
echo "${res%.*}" echo "${res%.*}"
} }
# convertByteToSize - converts a byte size to a given unit # convertByteToSize - converts a byte size to a given unit
# parameter: # parameter:
# $1 - size in byte # $1 - size in byte
# $2 - unit like "kB", "MB", "MiB", "GB", "GiB", "TB" or "TiB" # $2 - unit like "kB", "kiB", "MB", "MiB", "GB", "GiB", "TB" or "TiB"
# return: # return:
# rounded size with unit # rounded size with unit
convertByteToSize() { convertByteToSize() {
local factor=1 local factor=1
case $2 in case $2 in
"B") factor=1;; "B") factor=1;;
"kB") factor=1000 ;; "kB") factor=1000 ;;
"MB") factor=1000000 ;; "MB") factor=1000000 ;;
"GB") factor=1000000000 ;; "GB") factor=1000000000 ;;
"TB") factor=1000000000000 ;; "TB") factor=1000000000000 ;;
"kiB") factor=1024 ;; "kiB") factor=1024 ;;
"MiB") factor=1048576 ;; "MiB") factor=1048576 ;;
"GiB") factor=1073741824 ;; "GiB") factor=1073741824 ;;
"TiB") factor=1099511627776 ;; "TiB") factor=1099511627776 ;;
*) factor=1 ;; *) factor=1 ;;
esac esac
res=$(dc -e "2k $1 ${factor} / p") res=$(dc -e "2k $1 ${factor} / p")
...@@ -70,20 +70,20 @@ convertByteToSize() { ...@@ -70,20 +70,20 @@ convertByteToSize() {
# validateDiskScheme - checks the scheme of a disk device # validateDiskScheme - checks the scheme of a disk device
# parameter: # parameter:
# $1 - disk device name # $1 - disk device name
# retur: # return:
# 0 - no changes # 0 - no changes
# 1 - label has changed # 1 - label has changed
validateScheme() { validateScheme() {
local lbl=$(echo $diskdata[0] | cut -f 6 -d ":") local lbl=$(echo $diskdata[0] | cut -f 6 -d ":")
local retval=1 local retval=1
local scheme=$(eval echo \$DISK_$(echo $1 | tr [a-z] [A-Z])_SCHEME) local scheme=$(eval echo \$DISK_$(echo $1 | tr [a-z] [A-Z])_SCHEME)
if [ "x${scheme}" = "x${lbl}" ];
then
retval=0
fi
return ${retval} if [ "x${scheme}" = "x${lbl}" ];
then
retval=0
fi
return ${retval}
} }
# initialDiskScheme - initials the scheme of a disk device # initialDiskScheme - initials the scheme of a disk device
...@@ -111,38 +111,38 @@ initialDiskScheme() { ...@@ -111,38 +111,38 @@ initialDiskScheme() {
# 0 - no changes # 0 - no changes
# 1 - partions has changed # 1 - partions has changed
validateDiskPartitions() { validateDiskPartitions() {
declare -a parts=() declare -a parts=()
local retval=0 local retval=0
for part in $(eval "for p in \${DISK_$(echo $1 | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ") for part in $(eval "for p in \${DISK_$(echo $1 | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ")
do do
parts+=(${part}) parts+=(${part})
done done
if [ ${#parts[@]} -eq $((${#diskdata[@]} - 1)) ]; if [ ${#parts[@]} -eq $((${#diskdata[@]} - 1)) ];
then then
for idx in $(seq 1 1 ${#parts[@]}) for idx in $(seq 1 1 ${#parts[@]})
do do
gsize=$(convertSizeToByte $(echo ${parts[$((${idx} - 1))]} | cut -f 1 -d ":")) gsize=$(convertSizeToByte $(echo ${parts[$((${idx} - 1))]} | cut -f 1 -d ":"))
dsize=$(convertSizeToByte $(echo ${diskdata[${idx}]} | cut -f 4 -d ":")) dsize=$(convertSizeToByte $(echo ${diskdata[${idx}]} | cut -f 4 -d ":"))
diffperc=$(dc -e "2k $dsize $gsize - 100 * $gsize / p" | sed -e "s/^-//g") diffperc=$(dc -e "2k $dsize $gsize - 100 * $gsize / p" | sed -e "s/^-//g")
if [ -n "x${diffperc%.*}" ]; if [ -n "x${diffperc%.*}" ];
then then
diffperc=0 diffperc=0
fi fi
#if difference between current disk size and given disk size more than 1% then partitions has changed #if difference between current disk size and given disk size more than 1% then partitions has changed
if [ ${diffperc%.*} -gt 1 ]; if [ ${diffperc%.*} -gt 1 ];
then then
retval=1 retval=1
fi fi
done done
else else
retval=1 retval=1
fi fi
return ${retval} return ${retval}
} }
# initialDiskPartitions - initial the partitions of a disk device # initialDiskPartitions - initial the partitions of a disk device
...@@ -151,21 +151,21 @@ validateDiskPartitions() { ...@@ -151,21 +151,21 @@ validateDiskPartitions() {
# return: # return:
# none # none
initialDiskPartitions() { initialDiskPartitions() {
declare -a parts=() declare -a parts=()
local start=$(convertSizeToByte "1MiB") local start=$(convertSizeToByte "1MiB")
local fs="" local fs=""
local size="" local size=""
local end="" local end=""
for part in $(eval "for p in \${DISK_$(echo $1 | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ") for part in $(eval "for p in \${DISK_$(echo $1 | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ")
do do
fs=$(echo ${part} | cut -f 2 -d ":") fs=$(echo ${part} | cut -f 2 -d ":")
fsize=$(echo ${part} | cut -f 1 -d ":") fsize=$(echo ${part} | cut -f 1 -d ":")
size=$(convertSizeToByte $(echo ${part} | cut -f 1 -d ":")) size=$(convertSizeToByte $(echo ${part} | cut -f 1 -d ":"))
end=$((${start} + ${size})) end=$((${start} + ${size}))
parted -a optimal -s -m /dev/$1 mkpart primary ${fs} $(convertByteToSize ${start} "MiB") $(convertByteToSize ${end} "MiB") parted -a optimal -s -m /dev/$1 mkpart primary ${fs} $(convertByteToSize ${start} "MiB") $(convertByteToSize ${end} "MiB")
start=${end} start=${end}
done done
} }
for disk in ${DISK_DEVICES[@]} for disk in ${DISK_DEVICES[@]}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment