Added archivemount support to cdz if present

This commit is contained in:
Sam Hardeman 2025-09-13 17:06:43 +02:00
parent a4438fe38e
commit b4b41660cf

43
cdz
View file

@ -20,6 +20,10 @@ then
exit 2
fi
# Check if archivemount is present
which archivemount 1>/dev/null 2>/dev/null
hasmounter=$?
file "$target" 1>/dev/null
exitcode=$?
report=$(file "$target")
@ -28,6 +32,8 @@ report=$(file "$target")
comm1=(:)
comm2=(echo "Unsupported archive type$add: \"$target\"")
comm3=(:)
comm4=(:)
comm5=(:)
echo $report | grep "tar archive" 1>/dev/null
istar=$?
@ -47,19 +53,31 @@ then
istar=0
fi
if (( $NO_ARCHIVEMOUNT == 1 )); then
hasmounter=1
fi
if (( $hasmounter == 0 )); then
echo "We have \`archivemount\`, so we'll use that!"
echo "If you'd prefer we not use it, please specify NO_ARCHIVEMOUNT=1"
istar=1
iszip=1
israr=1
fi
# Now we set the right command
if (( istar == 0 )); then
if (( $istar == 0 )); then
comm2=(tar xvf "$target" -C)
elif (( iszip == 0 )); then
elif (( $iszip == 0 )); then
which unzip 1>/dev/null
exitcode=$?
if (( exitcode == 0 )); then
if (( $exitcode == 0 )); then
comm2=(unzip -q "$target" -d)
else
comm1=(echo "The utility 'unzip' is missing, please install it")
comm3=(exit 1)
fi
elif (( israr == 0 )); then
elif (( $israr == 0 )); then
which unrar 1>/dev/null
exitcode=$?
if (( exitcode == 0 )); then
@ -68,6 +86,10 @@ elif (( israr == 0 )); then
comm1=(echo "The utility 'unrar' is missing, please install it")
comm3=(exit 1)
fi
elif (( $hasmounter == 0 )); then
comm2=(archivemount "$target")
comm4=(cd ..)
comm5=(umount)
fi
# Create the temp dir, usually
@ -80,9 +102,16 @@ dir=$(mktemp -d /tmp/extracted.XXXXXXXX)
currentpath=$(realpath .)
cd $dir
ln -s $currentpath ./link-back
echo "A symlink to your original path has been created under the name \`link-back\`."
echo "You can use this to copy out files, but you can also just access your filesystem regularly."
# With archivemount, making a symlink will alter the archive
if (( $hasmounter == 1 )); then
ln -s $currentpath ./link-back
echo "A symlink to your original path has been created under the name \`link-back\`."
echo "You can use this to copy out files, but you can also just access your filesystem regularly."
fi
echo "Type 'exit' to exit the extracted archive's folder and auto-delete it."
eval $SHELL
"${comm4[@]}"
"${comm5[@]}" $dir
rm -rf $dir