初投稿なのでこんにちは!私はプログラミングに関して完全な初心者だと言って始めましょう。私は非常に基本的なことを理解していますが、終了コードや適切な用語のチェックに関しては、途方に暮れています。どうやら私の searchfoo はこの分野では本当に弱いようです。用語の問題だと思います。
これを読んでくれたり、私の質問に答えてくれてありがとう!
説明: .cbr ファイルを .cbz ファイルに変換/再パックするスクリプトを見つけました。これらのファイルは基本的には普通のrarおよびzipファイルですが、コミックラック、qcomicbookなどの (コミック) ブック アプリケーションに使用されるため、別の拡張子に名前が変更されています。驚くべきことに、cbr -> cbz コンバーターはありません。.cbz の利点は、独自のrar ファイル形式をエスケープすることに加えて、e を使用してComic Vineからのメタデータを保存できることです。ぐコミタッガー。
問題: ファイルの再パッケージ化がうまく終わらない場合があり、整合性チェックと再実行によって軽減されることを願っています。上記のスクリプトを少し変更してp7zipを使用するようにしました。これは、 7z、 zip ファイル、およびその他のファイルの両方をパック/アンパックできるためです。オプションに最適です。p7zip は、次の方法でアーカイブをテストできます。
7z t comicfile.cbz tmpworkingdir
if & else here(?) を使用して整合性をチェックし、エラーがある場合はもう一度やり直してください。
質問/tl;dr: 以下のスクリプトに整合性ファイルのチェックを追加するための「最良の」/適切なアプローチは何ですか?
#!/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 になる前に 2 つ以上のリンクを投稿しなかったので、OP からがらくたをリンクしました.. [編集] ああ..
[編集 2] unrar を依存関係から削除し、代わりに p7zip を使用しました。これは、rar ファイルを抽出できるためです。