Last active
November 13, 2020 23:35
-
-
Save espoelstra/d89d305e015ccc6996d810407233e506 to your computer and use it in GitHub Desktop.
Mount and extract zip in Crosh shell without needing Files app or unzip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Executed with bash unzip-file.sh someFiles.zip [destpath] | |
# Destination by default is ~/Downloads/ you can override but may end up with extra folders if the zip contains one at the root | |
# For long term use mkdir -p /usr/local/bin/ and put this file in that folder as `unzip` and `chmod a+x /usr/local/bin/unzip` | |
ZIP_MOUNT_DIR=/media/archive/user | |
ensure_archive_user_exists() { | |
sudo mkdir -p ${ZIP_MOUNT_DIR} | |
sudo chmod a+rwx ${ZIP_MOUNT_DIR} | |
} | |
ensure_archive_user_exists | |
fusermount -q -u ${ZIP_MOUNT_DIR} || true # making sure there aren't any other open zips here | |
fuse-zip ${1:?'need to supply a zip file'} ${ZIP_MOUNT_DIR} | |
# TODO: Add an option like "strip path" to allow copying from one level deeper to avoid double directories if zip contains only 1 folder at the root? | |
cp -RT ${ZIP_MOUNT_DIR} ${2:-~/Downloads} # /${1%.*} # Some zips already have a folder inside them, assume that for now | |
fusermount -u ${ZIP_MOUNT_DIR} || true # unmount after we've copied things out because we are done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment