reimplemented dir2sb and sb2dir to act as 'conversion' utility
parent
5a090f6ac4
commit
edb710c1b3
|
|
@ -1,25 +1,52 @@
|
|||
#!/bin/bash
|
||||
# Author: Tomas M. <http://www.slax.org/>
|
||||
|
||||
if [ "$2" = "" ]; then
|
||||
echo "Usage: $0 [source_directory] [target_file.sb] [ -d ]"
|
||||
exit 1
|
||||
usage()
|
||||
{
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Convert directory to .sb compressed module"
|
||||
echo ""
|
||||
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 " then the source_directory itself is included in the module and"
|
||||
echo " then the target_file.sb parameter is required"
|
||||
}
|
||||
|
||||
SB=$(echo "$1" | grep -o "[.]sb/*\$")
|
||||
if [ "$(echo "$1" | grep -o "/squashfs-root/*\$")" != "" ]; then
|
||||
SB="true"
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d "$1" ]; then
|
||||
echo "Not a directory: $1"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -e "$2" ]; then
|
||||
echo "Target exists: $2"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [ "$3" = "-d" ]; then
|
||||
if [ "$SB" = "" ]; then
|
||||
KEEP="-keep-as-directory"
|
||||
if [ "$2" = "" ]; then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
else
|
||||
KEEP=""
|
||||
fi
|
||||
|
||||
mksquashfs "$1" "$2" -comp xz -b 512K $KEEP
|
||||
|
||||
if [ ! -d "$1" ]; then
|
||||
echo "Not a directory: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
if [ "$2" = "" ]; then
|
||||
TARGET="$1".sb
|
||||
while [ -e "$TARGET" ]; do TARGET="$TARGET"x; done
|
||||
mksquashfs "$1" "$TARGET" -comp xz -b 512K $KEEP >/dev/null
|
||||
umount "$1" 2>/dev/null
|
||||
rmdir "$1" 2>/dev/null && mv "$TARGET" "$1" && exit
|
||||
echo "Created file $TARGET"
|
||||
else
|
||||
if [ -e "$2" ]; then
|
||||
echo "Target exists: $2" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
mksquashfs "$1" "$2" -comp xz -b 512K $KEEP >/dev/null
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,13 +1,33 @@
|
|||
#!/bin/bash
|
||||
# convert .sb compressed Slax Bundle file into directory tree
|
||||
# Author: Tomas M. <http://www.slax.org/>
|
||||
#
|
||||
|
||||
if [ ! -d "$2" ]; then
|
||||
if [ ! -e "$1" ]; then
|
||||
echo
|
||||
echo "Convert .sb compressed module into directory tree"
|
||||
echo "usage: $0 source_file.sb existing_output_directory"
|
||||
echo "Convert .sb compressed module into directory with the same name"
|
||||
echo "usage: $0 [source_file.sb] [[optional output_directory]]"
|
||||
echo " If the output_directory is specified, it must exist"
|
||||
echo " If the output_directory is not specified, the name source_file.sb"
|
||||
echo " is used and the directory is overmounted with tmpfs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
unsquashfs -f -dest "$2" "$1" >/dev/null
|
||||
if [ ! -r "$1" ]; then
|
||||
echo "File does not exist: $1" >&2
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$2" = "" ]; then
|
||||
SOURCE="$1".x
|
||||
while [ -e "$SOURCE" ]; do SOURCE="$SOURCE"x; done
|
||||
mv "$1" "$SOURCE" || exit
|
||||
mkdir "$1"
|
||||
mount -t tmpfs tmpfs "$1"
|
||||
unsquashfs -f -dest "$1" "$SOURCE" >/dev/null || exit
|
||||
rm "$SOURCE"
|
||||
else
|
||||
if [ ! -d "$2" ]; then
|
||||
echo "Directory does not exist: $2" >&2
|
||||
exit
|
||||
fi
|
||||
unsquashfs -f -dest "$2" "$1" >/dev/null
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in New Issue