Created
June 13, 2026 16:23
-
-
Save anoduck/cb60fdc2aa1de7a736704d015f9603a6 to your computer and use it in GitHub Desktop.
extract zip archives
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # vim: set sw=4 sts=4 et ft=sh : | |
| # -*- mode:bash; -*- | |
| # ------------------------------------------------------- | |
| # Copyright (C) 2026 by Anoduck, The Anonymous Duck | |
| # ------------------------------------------------------- | |
| # https://anoduck.mit-license.org | |
| # ------------------------------------------------------- | |
| LOGDIR="$HOME/log" | |
| source /usr/local/src/logging.sh | |
| if [[ ! -d "$LOGDIR" ]]; then | |
| mkdir -p "$LOGDIR" | |
| fi | |
| init_logger -d 7 -l "$LOGDIR/extract-archives.log" | |
| source /usr/local/src/beddu.sh | |
| TRGDIR=$1 | |
| check_dir () { | |
| iter=1 | |
| while [[ -d "$newdir" ]]; do | |
| newdir="$newdir-$iter" | |
| log_debug "New Name: $newdir" | |
| iter="$iter"+1 | |
| log_debug "New Iter: $iter" | |
| done | |
| log_debug "Final New name $newdir" | |
| } | |
| check_name () { | |
| if [[ -f "$archive" ]]; then | |
| detoxd=$(detox -n "$archive" | gcut --delimiter='>' --fields=2 | tr -d "[:space:]") | |
| detox -v "$archive" | |
| if [[ -z "$detoxd" ]]; then | |
| archive_name="$archive"; | |
| else | |
| archive_name="$detoxd" | |
| fi | |
| fi | |
| } | |
| for archive in *.zip; do | |
| log_info "working on $archive" | |
| check_name | |
| log_info "New archive name $archive_name" | |
| test ! -f "$archive_name" && echo "$archive_name does not exist" && exit 1 | |
| dirtyname="${archive_name%.zip}" | |
| log_info "Directory name will be $dirtyname" | |
| newdir="$TRGDIR/$dirtyname" | |
| test -z "$newdir" && echo "empty string" && exit | |
| if [[ -d "$newdir" ]]; then | |
| log_debug "$newdir exists" | |
| now=$(gdate +%s) | |
| newdir="$newdir-$now" | |
| fi | |
| mkdir -p "$newdir" | |
| log_debug "Making new directory $newdir" | |
| unzip -d "$newdir" "$archive_name" | |
| log_debug "Unzipping $archive_name $newdir" | |
| test -f "$archive_name" && rm "$archive_name" | |
| log_info "Removed zip archive $archive_name" | |
| done | |
| echo "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment