第一次发帖,嗨!首先让我说我是一个关于编程的菜鸟。我了解非常基本的东西,但是在检查退出代码或适当的术语是什么时,我不知所措。显然我的 searchfoo 在这方面真的很弱,我想这是一个术语问题。
提前感谢您花时间阅读本文/回答我的问题!
说明:我找到了一个将 .cbr 文件转换/重新打包为 .cbz 文件的脚本。这些文件基本上是您的普通rar和zip文件,但是重命名为另一个扩展名,因为它们用于(漫画)书应用程序,例如Comicrack、qcomicbook等等。令人惊讶的是,那里没有 cbr -> cbz 转换器。.cbz 的优点除了转义专有的rar 文件格式外,还可以使用 e存储来自Comic Vine的元数据。g漫画家。
问题:有时文件的重新打包并没有很好地结束,希望通过完整性检查和另一次尝试来缓解。我稍微修改了上述脚本以使用p7zip,因为它可以打包/解包7z、 zip-files 和其他一些文件,即。e 非常适合选择。p7zip 可以通过以下方式测试存档:
7z t comicfile.cbz tmpworkingdir
我想这是使用 if & else here(?) 来检查完整性然后再试一次的问题,如果有任何错误。
问题/tl;博士:向下面的脚本添加完整性文件检查的“最佳”/适当方法是什么?
#!/bin/bash
#Source: http://comicrack.cyolito.com/forum/13-scripts/30013-cbr3cbz-rar-to-zip-conversion-for-linux
echo "Converting CBRs to CBZs"
# Set the "field separator" to something other than spaces/newlines" so that spaces
# in the file names don't mess things up. I'm using the pipe symbol ("|") as it is very
# unlikely to appear in a file name.
IFS="|"
# Set working directory where to create the temp dir. The user you are using must have permission
# to write into this directory.
# For performance reasons I'm using ram disk (/dev/shm/) in Ubuntu server.
WORKDIR="/dev/shm/"
# Set name for the temp dir. This directory will be created under WORDDIR
TEMPDIR="cbr2cbz"
# The script should be invoked as "cbr2cbz {directory}", where "{directory}" is the
# top-level directory to be searched. Just to be paranoid, if no directory is specified,
# then default to the current working directory ("."). Let's put the name of the
# directory into a shell variable called SOURCEDIR.
# Note: "$1" = "The first command line argument"
if test -z "$1"; then
SOURCEDIR=`pwd`
else
SOURCEDIR="$1"
fi
echo "Working from directory $SOURCEDIR"
# We need an empty directory to work in, so we'll create a temp directory here
cd "$WORKDIR"
mkdir "$TEMPDIR"
# and step into it
cd "$TEMPDIR"
# Now, execute a loop, based on a "find" command in the specified directory. The
# "-printf "$p|" will cause the file names to be separated by the pipe symbol, rather than
# the default newline. Note the backtics ("`") (the key above the tab key on US
# keyboards).
for CBRFILE in `find "$SOURCEDIR" -name "*.cbr" -printf "%p|while read line; do
# Now for the actual work. First, extract the base file name (without the extension)
# using the "basename" command. Warning: more backtics.
BASENAME=`basename $CBRFILE ".cbr"`
# And the directory path for that file, so we know where to put the finished ".cbz"
# file.
DIRNAME=`dirname $CBRFILE`
# Now, build the "new" file name,
NEWNAME="$BASENAME.cbz"
# We use RAR file's name to create folder for unpacked files
echo "Processing $CBRFILE"
mkdir "$BASENAME"
# and unpack the rar file into it
7z x "$CBRFILE" -O"$BASENAME"
cd "$BASENAME"
# Lets ensure the permissions allow us to pack everything
sudo chmod 777 -R ./*
# Put all the extracted files into new ".cbz" file
7z a -tzip -mx=9 "$NEWNAME" *
# And move it to the directory where we found the original ".cbr" file
mv "$NEWNAME" $DIRNAME/"$NEWNAME"
# Finally, "cd" back to the original working directory, and delete the temp directory
# created earlier.
cd ..
rm -r "$BASENAME"
# Delete the RAR file also
rm "$CBRFILE"
done
# At the end we cleanup by removing the temp folder from ram disk
cd ..
echo "Conversion Done"
rm -r "$TEMPDIR"
哦,人性,在 10 个声望之前不要发布两个以上的链接,我把 OP 中的废话联系起来了。
[编辑 2]我删除了 unrar 作为依赖项并改用 p7zip,因为它可以提取 rar 文件。