From a2e4b9511ad54d4f06473529bb5546cdac057043 Mon Sep 17 00:00:00 2001 From: Cyberes <64224601+Cyberes@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:22:58 -0700 Subject: [PATCH] Update fix-diffusers-root-directory.sh --- other/fix-diffusers-root-directory.sh | 37 ++++++++------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/other/fix-diffusers-root-directory.sh b/other/fix-diffusers-root-directory.sh index a6a59be..68d3aa7 100644 --- a/other/fix-diffusers-root-directory.sh +++ b/other/fix-diffusers-root-directory.sh @@ -5,17 +5,10 @@ # named "archive". This script renames the root directory to "archive". if [ -z "$1" ]; then echo -e "Usage:\n./fix-diffusers-root-directory.sh [file or directory of files]" && exit 1; fi -TARGET_PATH="$1" - -# Prompt the user to install 7zip if they don't have it insalled -if [ $(dpkg-query -W -f='${Status}' p7zip-full 2>/dev/null | grep -c "ok installed") = 0 ]; then - sudo apt update && sudo apt install p7zip-full -fi - -TMP=$(mktemp -d) +TARGET_PATH="$@" test_zip () { - unzip -l "$1" + unzip -l "$1" > /dev/null return $? } @@ -24,18 +17,10 @@ do_convert () { FILENAME=$(basename "$TARGET_FILE") NAME="${FILENAME%.*}" EXT="${FILENAME##*.}" - - 7z x "$TARGET_FILE" -o"$TMP" - - # There should only be one file in this tmp directory. - # We don't know what its name is so we will do one loop - # which will be only our target directory. - for file in "$TMP"/*; do - mv "$file" "$TMP/archive" - NEW_NAME="${NAME}_fixed.zip" - 7z a -tzip -mx=9 "${NAME}_fixed.$EXT" "$TMP/archive" - break - done + NEW_NAME="${NAME}_fixed.$EXT" + echo "$TARGET_FILE -> $NEW_NAME" + # Passing the file back through torch seems to fix it + python3 -c "import torch; torch.save(torch.load('$TARGET_FILE', map_location='cpu'), '$NEW_NAME')" } if [ -d "$TARGET_PATH" ]; then @@ -45,9 +30,9 @@ if [ -d "$TARGET_PATH" ]; then fi done else - if test_zip "$TARGET_PATH"; then - do_convert "$TARGET_PATH" - fi + for file in $TARGET_PATH; do + if test_zip "$file"; then + do_convert "$file" + fi + done fi - -rm -rf "$TMP"