force erasing source directory even if it was not mounted

pull/63/head
TomasM 2018-11-23 07:50:10 -05:00
parent 15c130f76a
commit af5288c7af
1 changed files with 26 additions and 18 deletions

View File

@ -8,43 +8,51 @@ usage()
echo "Usage: $0 [source_directory.sb] [[target_file.sb]]" echo "Usage: $0 [source_directory.sb] [[target_file.sb]]"
echo " If source_directory does not have .sb suffix and it is not 'squashfs-root'," echo " If source_directory does not have .sb suffix and it is not 'squashfs-root',"
echo " then the source_directory itself is included in the module and" echo " then the source_directory itself is included in the module and"
echo " then the target_file.sb parameter is required" echo " then the target_file.sb parameter is required."
echo " If target_file.sb is not specified, the source_directory is erased"
echo " and replaced by the newly generated module file."
} }
SB=$(echo "$1" | grep -o "[.]sb/*\$") P1="$(readlink -f "$1")"
if [ "$(echo "$1" | grep -o "/squashfs-root/*\$")" != "" ]; then P2="$(readlink -f "$2")"
if [ "$P1" = "$P2" ]; then
P2=""
fi
SB=$(echo "$P1" | grep -o "[.]sb/*\$")
if [ "$(echo "$P1" | grep -o "/squashfs-root/*\$")" != "" ]; then
SB="true" SB="true"
fi fi
if [ "$SB" = "" ]; then if [ "$SB" = "" ]; then
KEEP="-keep-as-directory" KEEP="-keep-as-directory"
if [ "$2" = "" ]; then if [ "$P2" = "" ]; then
usage usage
exit exit 1
fi fi
else else
KEEP="" KEEP=""
fi fi
if [ ! -d "$P1" ]; then
if [ ! -d "$1" ]; then echo "Not a directory: $P1" >&2
echo "Not a directory: $1" >&2
exit 2 exit 2
fi fi
if [ "$2" = "" ]; then if [ "$P2" = "" ]; then
TARGET="$1".sb TARGET="$P1".sb
while [ -e "$TARGET" ]; do TARGET="$TARGET"x; done while [ -e "$TARGET" ]; do TARGET="$TARGET"x; done
mksquashfs "$1" "$TARGET" -comp xz -b 512K $KEEP >/dev/null mksquashfs "$P1" "$TARGET" -comp xz -b 512K $KEEP >/dev/null || exit 3
umount "$1" 2>/dev/null umount "$P1" 2>/dev/null
rmdir "$1" 2>/dev/null && mv "$TARGET" "$1" && exit rm -Rf "$P1"
echo "Created file $TARGET" mv "$TARGET" "$P1"
else else
if [ -e "$2" ]; then if [ -e "$P2" ]; then
echo "Target exists: $2" >&2 echo "Target exists: $P2" >&2
exit 3 exit 4
fi fi
mksquashfs "$1" "$2" -comp xz -b 512K $KEEP >/dev/null mksquashfs "$P1" "$P2" -comp xz -b 512K $KEEP >/dev/null
fi fi