diff options
author | Jesus <heckyel@hyperbola.info> | 2025-05-18 19:12:22 -0500 |
---|---|---|
committer | Jesus <heckyel@hyperbola.info> | 2025-05-18 19:12:22 -0500 |
commit | e31761a54ce72d9bda4c7d32ce92b064bb7ab1c5 (patch) | |
tree | 9f2cd483bf1151597aa8d570f16cf5a0d41e66da | |
parent | 580f139ba229684c93bae006fd08863a8ecf1106 (diff) | |
download | hyperterm-e31761a54ce72d9bda4c7d32ce92b064bb7ab1c5.tar.lz hyperterm-e31761a54ce72d9bda4c7d32ce92b064bb7ab1c5.tar.xz hyperterm-e31761a54ce72d9bda4c7d32ce92b064bb7ab1c5.zip |
update rar2zip
-rw-r--r-- | hyperterm/hyperterm.sha512 | 2 | ||||
-rw-r--r-- | hyperterm/tools/rar2zip.sh | 80 |
2 files changed, 59 insertions, 23 deletions
diff --git a/hyperterm/hyperterm.sha512 b/hyperterm/hyperterm.sha512 index f7f1a51..c4f0cd9 100644 --- a/hyperterm/hyperterm.sha512 +++ b/hyperterm/hyperterm.sha512 @@ -5,7 +5,7 @@ cdfe049ec07f02a1893cda29c13085d06709e09a30b0c2e1111585278315f03139d61080c883cb3f 2036a79215a5434e31f3406bea3f2ffa7e94ffef86c2d1ceb8865db29f19fe7f342f9cab93288f57c75daed36ef146f85d15f8d633931a27d55c3983f55ef15b ./core/git.sh 7447d3e167ab207d3ef4218e201a06bf5a3fc23281639f16f7f405f1d66b73923845d450fdb0a94672757866a9da0324f728564a1b61b2ed1678fe576eb565cf ./core/autocomplete.sh f3e00b2aa8ab9f3ab44570adaa2520408ed66fd00f551654d60b64a4be3546ec781b7efa39bcd774937e654b6ffb4c7af3f21eeb36caf9c01f82f85cf28e2b4d ./core/languages.sh -88b215a6c2df22bc84bda981b3ff1d27ba391f03e2b84b95adefe1e8885b079b0da7c885ec0ad3256b60b8da9efa9ba8ab28906ece76781b192ea474d579d143 ./tools/rar2zip.sh +b846a929844e74fc76ce65d2bd7aefcdeb03e058d9ce68a7f3f6bce6080a843d90eae78cecc2faac0c5b066a739a8328dfcd042cd25cb5aaa856e956a0c4d0c2 ./tools/rar2zip.sh 73becd983f15d68b3c459adb4fe847bbbd6343519640aa5e03bb530e61a59ed0545dd3b3621ad82da378bbf15c4d9ee63984004d3bfed26d9d9df643f1524de5 ./tools/proxy.sh 0b9671c851278cd6a5484ab95b62606b0b925f9606f4de400c5e15a66e35e86bb6bb15e4e1b599ca819c230604bce0ca755d599ec9cd59a14b41f352ef897997 ./tools/aliases.sh fab9d339a99c7d2e1809d1c44f533523c6bfcdcc8d63c62b335ce7d4c666c8bdd7ac319316bf71f043163a3a0184e25ecfe1ee32724627424d042a05fa80ce77 ./tools/vconverter.sh diff --git a/hyperterm/tools/rar2zip.sh b/hyperterm/tools/rar2zip.sh index eb13d80..54ec926 100644 --- a/hyperterm/tools/rar2zip.sh +++ b/hyperterm/tools/rar2zip.sh @@ -5,54 +5,90 @@ # Usage: rar2zip file [file ...] # Example: rar2zip file.rar +function check_and_install_7z() { + if command -v 7z &>/dev/null; then + return + fi + + echo "7z not found. Attempting to install..." + + INSTALLER="" + SUDO="" + USER_CMD=$(command -v sudo || command -v doas) + + [[ "$(id -u)" -ne 0 ]] && SUDO="$USER_CMD" + + OS_ID=$( + cat /etc/*release 2>/dev/null | + tr '[:upper:]' '[:lower:]' | + grep "^id=" | head -n1 | cut -d= -f2 | tr -d '"' + ) + + case "$OS_ID" in + arch|manjaro|artix|hyperbola) + INSTALLER="pacman -Sy --noconfirm p7zip" + ;; + debian|ubuntu|linuxmint|elementary|pop) + INSTALLER="apt-get update && apt-get install -y p7zip-full" + ;; + fedora) + INSTALLER="dnf install -y p7zip p7zip-plugins" + ;; + void) + INSTALLER="xbps-install -Sy p7zip" + ;; + gentoo) + INSTALLER="emerge app-arch/p7zip" + ;; + alpine) + INSTALLER="apk add p7zip" + ;; + *) + echo "Unsupported distro. Cannot install 7z automatically." + return 1 + ;; + esac + + if [ -n "$INSTALLER" ]; then + echo "Installing 7z using: $SUDO $INSTALLER" + $SUDO bash -c "$INSTALLER" + fi +} + function rar2zip() { + check_and_install_7z || { + echo "Failed to install 7z. Aborting." + exit 1 + } - echo "Converting RARs to ZIPs" + echo "Converting RAR files to ZIP..." - # Use RAM disk for temporary files. WORKDIR="/dev/shm/" for INFILE in "$@"; do - # Absolute path to old file OLDFILE=$(realpath "${INFILE}") - - # Get the file name without the extension BASENAME=$(basename "${OLDFILE%.*}") - - # Path for the file. The ".zip" file will be written there. DIRNAME=$(dirname "$OLDFILE") - - # Name of the .zip file NEWNAME="${DIRNAME}/$BASENAME.zip" if [ ! -e "${NEWNAME}" ]; then - # Set name for the temp dir. This directory will be created under WORKDIR TEMPDIR=$(mktemp -p "$WORKDIR" -d) - # Create a temporary folder for unRARed files echo "Extracting $OLDFILE" - unar "$OLDFILE" -o "${TEMPDIR}/" - # Zip the files with maximum compression 7z a -tzip -mx=9 "$NEWNAME" "${TEMPDIR}/*" - # Alternative. MUCH SLOWER, but better compression - # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" * - # Preserve file modification time touch -r "$OLDFILE" "$NEWNAME" - # Delete the temporary directory rm -r "$TEMPDIR" - # OPTIONAL. Safe-remove the old file - # Restore from "$HOME/.local/share/Trash" gio trash "$OLDFILE" - echo "${OLDFILE}: A backup was made on $HOME/.local/share/Trash" + echo "${OLDFILE}: Original file moved to trash" else - echo "${NEWNAME}: File exists!" + echo "${NEWNAME}: File already exists!" fi done - echo "Conversion Done" + echo "Conversion complete." } |