Last active
December 2, 2021 16:14
-
-
Save oblaser/43666c28371f16cb99357d0de45c67ed to your computer and use it in GitHub Desktop.
Renames the split (multi-volume) RAR files from the old naming scheme to one of the newer ones.
This file contains 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
#!/bin/bash | |
# Oliver Blaser - gist.github.com/oblaser | |
# 02.12.2021 | |
# Renames the split (multi-volume) RAR files from the old | |
# naming scheme to one of the newer ones. | |
# Useage: Edit the following parts of the script | |
# - Set the variables "orig" and "dest" to the filenames without | |
# the extension (stem names) | |
# - Select the command (un-/comment) | |
# - Select the scheme | |
# - Set the number of the last *.rNN file (eg. it's *.r09 set last=9) | |
orig=the-original-rar-archives # the-original-rar-archives.rar the-original-rar-archives.r00 *.r01 ... | |
dest=archive | |
command="echo -e \"\033[91mselect the right command!\033[39m\" \" \"" | |
#command="mv" | |
#command="cp -i" | |
# 0: *.NNN.rar | |
# 1: *.partNN.rar | |
scheme=-1 | |
last=-1 | |
errCnt=0 | |
function onError() | |
{ | |
((++errCnt)) | |
if [ $1 == "rar" ]; then | |
echo -e "\033[91merror:\033[39m *.rar" | |
else | |
echo -e "\033[91merror:\033[39m *.r$(printf "%02d" $1)" | |
fi | |
} | |
if [ $scheme -eq 0 ]; then | |
echo "$orig.rar -> $dest.000.rar" | |
eval $command $orig.rar $dest.000.rar | |
if [ $? -ne 0 ]; then onError "rar"; fi; | |
for ((i=0; i<=$last; ++i)) | |
do | |
tmpOrig=$orig.r$(printf "%02d" $i) | |
tmpDest=$dest.$(printf "%03d" $((i+1))).rar | |
echo "$tmpOrig -> $tmpDest" | |
eval $command $tmpOrig $tmpDest | |
if [ $? -ne 0 ]; then onError $i; fi; | |
done | |
else # [ $scheme -eq 0 ] | |
if [ $scheme -eq 1 ]; then | |
echo "$orig.rar -> $dest.part01.rar" | |
eval $command $orig.rar $dest.part01.rar | |
if [ $? -ne 0 ]; then onError "rar"; fi; | |
for ((i=0; i<=$last; ++i)) | |
do | |
tmpOrig=$orig.r$(printf "%02d" $i) | |
tmpDest=$dest.part$(printf "%02d" $((i+2))).rar | |
echo "$tmpOrig -> $tmpDest" | |
eval $command $tmpOrig $tmpDest | |
if [ $? -ne 0 ]; then onError $i; fi; | |
done | |
else # [ $scheme -eq 1 ] | |
echo -e "\033[91munknown scheme: $scheme\033[39m" | |
fi # [ $scheme -eq 1 ] | |
fi # [ $scheme -eq 0 ] | |
if [ $last -lt 0 ]; then echo -e "\033[91minvalid last *.rNN: $last\033[39m"; fi; | |
if [ $errCnt -ne 0 ]; then | |
if [ $errCnt -eq 1 ]; then | |
echo -e "\n \033[91m$errCnt error\033[39m\n" | |
else | |
echo -e "\n \033[91m$errCnt errors\033[39m\n" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment