Skip to content

Commit

Permalink
feat: Organize code for better reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
takusuman committed Jul 12, 2023
1 parent 7573055 commit 4b4eb5e
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions lemount.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ function noninteractive {
&& success
}

function print_help {
printmsg '%s: illegal option "%s"\n[usage]: %s -D /dev/disk1 -t %s\n' \
$program_name $1 $program_name "$(echo ${mount_points[*]} | tr ' ' '|')"
}

function create_mounting_points {
printmsg 'Creating mount points...\n' 1>&2 &
for (( i=0; i<${#mount_points[@]}; i++ )); do
Expand Down Expand Up @@ -103,24 +98,6 @@ function check_virtual_disk {
fi
}


function mount_block {
# Kinda "gambiarrado", but since export -f isn't avaible and typeset -xf wasn't
# working either, I decided to do this.
printdbg '%s() debugging:\ndisk=%s\ntarget=%s\n' "$0" "$1" "$2" 1>&2
if [ isloop == 'y' ]; then
# This may will break compatibility with other UNIXes, but who
# cares? This is used officially only on Copacabana.
# Also, for disks which have multiple partitions, it would be
# cool to re-display them offering to mount again if needed.
mount -o loop "$1" "$2"; ec=$?
else
mount "$1" "$2"; ec=$?
fi

return $ec
}

function count_lemounted_disks {
# This function counts directories already created and creates a new
# directory for the new mounted disk
Expand Down Expand Up @@ -153,6 +130,24 @@ function count_lemounted_disks {
return 0
}


function mount_block {
# Kinda "gambiarrado", but since export -f isn't avaible and typeset -xf wasn't
# working either, I decided to do this.
printdbg '%s() debugging:\ndisk=%s\ntarget=%s\n' "$0" "$1" "$2" 1>&2
if [ isloop == 'y' ]; then
# This may will break compatibility with other UNIXes, but who
# cares? This is used officially only on Copacabana.
# Also, for disks which have multiple partitions, it would be
# cool to re-display them offering to mount again if needed.
mount -o loop "$1" "$2"; ec=$?
else
mount "$1" "$2"; ec=$?
fi

return $ec
}

function link_from_type2mnt {
# Check if the variables are being actually exported
printdbg \
Expand Down Expand Up @@ -192,6 +187,17 @@ function realpath {
echo "$(cd "${file_dirname}"; pwd)/${file_basename}"
}

# Errare humanum est.
function errare {
rc="$?"
printf 'Exit code: %s\n' "$rc"
# Delete the directory only if it in fact exists, to avoid the
# "rmdir: //0: No such file or directory" error.
[ -z "${root}${type}/${base_number}${disk_postfix}" ] \
&& rmdir "${root}${type}/${base_number}${disk_postfix}"
exit "$rc"
}

# printf(1), but for stderr per default.
# This helps us a lot when eval'ng $ledisk on a script.
function printmsg {
Expand All @@ -207,15 +213,9 @@ function printdbg {
fi
}

# Errare humanum est.
function errare {
rc="$?"
printf 'Exit code: %s\n' "$rc"
# Delete the directory only if it in fact exists, to avoid the
# "rmdir: //0: No such file or directory" error.
[ -z "${root}${type}/${base_number}${disk_postfix}" ] \
&& rmdir "${root}${type}/${base_number}${disk_postfix}"
exit "$rc"
function print_help {
printmsg '%s: illegal option "%s"\n[usage]: %s -D /dev/disk1 -t %s\n' \
$program_name $1 $program_name "$(echo ${mount_points[*]} | tr ' ' '|')"
}

main $@

0 comments on commit 4b4eb5e

Please sign in to comment.