Skip to content

Commit

Permalink
init_image now uses a random dir as a mount point like shrinkwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
GIJack committed Aug 24, 2020
1 parent f2c8ad0 commit b0515ec
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions init_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FILL_SRC=/dev/zero

LOOP_DEV=$(losetup -f)
PART_N=1
MOUNT_POINT="${HOME}/mnt"
MOUNT_POINT="$(mktemp -d)"
ROOT_METHOD="sudo"
# /Defaults #

Expand All @@ -27,11 +27,11 @@ parameter, filename.
Default file size is 20GB.
USAGE:
USAGE:
init_image [-s <size>] <filename.img>
OPTIONS:
OPTIONS:
-s,--size Size of image, in Megabytes, defaults to 20GB
Expand Down Expand Up @@ -89,8 +89,10 @@ switch_checker() {
}

abort_cleanup() {
# If this fails or is aborted, cleanup before we exit
rm "${OUTFILE}"
as_root losetup -d ${LOOP_DEV} &> /dev/null
rmdir "${MOUNT_POINT}"
exit_with_error 2 "INTERRUPT: ABORT!"
}

Expand Down Expand Up @@ -164,6 +166,21 @@ main() {
"Couldn't remove loop device. Clean up mantually"
errors+=1
fi

# Clean up last random mount point
rmdir "${MOUNT_POINT}"
if [ ${?} -ne 0 ];then
warn "couldn't delete ${MOUNT_POINT}, clean up manually"
errors+=1
fi

if [ $errors -gt 0 ];then
message "Done, but with ${errors} errors"
exit 1
else
message "Done"
exit 0
fi
}

PARMS=""
Expand Down

0 comments on commit b0515ec

Please sign in to comment.