Update fix-diffusers-root-directory.sh
This commit is contained in:
parent
44dd0f05b5
commit
a2e4b9511a
|
@ -5,17 +5,10 @@
|
||||||
# named "archive". This script renames the root directory to "archive".
|
# 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
|
if [ -z "$1" ]; then echo -e "Usage:\n./fix-diffusers-root-directory.sh [file or directory of files]" && exit 1; fi
|
||||||
TARGET_PATH="$1"
|
TARGET_PATH="$@"
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
test_zip () {
|
test_zip () {
|
||||||
unzip -l "$1"
|
unzip -l "$1" > /dev/null
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,18 +17,10 @@ do_convert () {
|
||||||
FILENAME=$(basename "$TARGET_FILE")
|
FILENAME=$(basename "$TARGET_FILE")
|
||||||
NAME="${FILENAME%.*}"
|
NAME="${FILENAME%.*}"
|
||||||
EXT="${FILENAME##*.}"
|
EXT="${FILENAME##*.}"
|
||||||
|
NEW_NAME="${NAME}_fixed.$EXT"
|
||||||
7z x "$TARGET_FILE" -o"$TMP"
|
echo "$TARGET_FILE -> $NEW_NAME"
|
||||||
|
# Passing the file back through torch seems to fix it
|
||||||
# There should only be one file in this tmp directory.
|
python3 -c "import torch; torch.save(torch.load('$TARGET_FILE', map_location='cpu'), '$NEW_NAME')"
|
||||||
# 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -d "$TARGET_PATH" ]; then
|
if [ -d "$TARGET_PATH" ]; then
|
||||||
|
@ -45,9 +30,9 @@ if [ -d "$TARGET_PATH" ]; then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
if test_zip "$TARGET_PATH"; then
|
for file in $TARGET_PATH; do
|
||||||
do_convert "$TARGET_PATH"
|
if test_zip "$file"; then
|
||||||
|
do_convert "$file"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$TMP"
|
|
||||||
|
|
Loading…
Reference in New Issue