mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
- Format all shell scripts using [shfmt] (https://github.com/mvdan/sh). Options used: * `-bn`: binary ops like && and | may start a line * `-sr`: redirect operators will be followed by a space * `-ci`: indent switch cases * `-i 4`: indent 4 spaces * `-s`: simplify the code * `-p`: parse for posix compliance - Add Github action to lint changes to scripts and enforce formatting going forward Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
46 lines
1.5 KiB
Bash
Executable File
46 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# A general, all-purpose extraction script. Not all extraction programs here
|
|
# are installed by LARBS automatically.
|
|
#
|
|
# Default behavior: Extract archive into new directory
|
|
# Behavior with `-c` option: Extract contents into current directory
|
|
|
|
while getopts "hc" o; do case "${o}" in
|
|
c) extracthere="True" ;;
|
|
*) printf 'Options:\n -c: Extract archive into current directory rather than a new one.\n' && exit 1 ;;
|
|
esac; done
|
|
|
|
if [ -z "$extracthere" ]; then
|
|
archive="$(readlink -f "$*")" \
|
|
&& directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" \
|
|
&& mkdir -p "$directory" \
|
|
&& cd "$directory" || exit 1
|
|
else
|
|
archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2> /dev/null)"
|
|
fi
|
|
|
|
[ -z "$archive" ] && printf 'Give archive to extract as argument.\n' && exit 1
|
|
|
|
if [ -f "$archive" ]; then
|
|
case "$archive" in
|
|
*.tar.bz2 | *.tbz2) tar xvjf "$archive" ;;
|
|
*.tar.xz) tar -xf "$archive" ;;
|
|
*.tar.gz | *.tgz) tar xvzf "$archive" ;;
|
|
*.tar.zst) tar -I zstd -xf "$archive" ;;
|
|
*.lzma) unlzma "$archive" ;;
|
|
*.bz2) bunzip2 "$archive" ;;
|
|
*.rar) unrar x -ad "$archive" ;;
|
|
*.gz) gunzip "$archive" ;;
|
|
*.tar) tar xvf "$archive" ;;
|
|
*.zip) unzip "$archive" ;;
|
|
*.Z) uncompress "$archive" ;;
|
|
*.7z) 7z x "$archive" ;;
|
|
*.xz) unxz "$archive" ;;
|
|
*.exe) cabextract "$archive" ;;
|
|
*) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
|
|
esac
|
|
else
|
|
printf 'File "%s" not found.\n' "$archive"
|
|
fi
|