rar2zip.sh
Publicado por Jarno Trulli 10/04/2008
[ Hits: 6.829 ]
Este é um script (ainda em construção!) que eu uso para transformar meus arquivos RAR para arquivos ZIP.
Eu o uso por que nem sempre eu tenho como abrir um arquivo RAR. Ele é bastante simples, meio monolítico, mas utilizável. Ainda precisa de umas melhorias, mas é bastante útil.
Usage: rar2zip.sh infile.rar
Dependências: unrar, zip, bash.
#!/bin/sh
#
# rar2zip.sh
# Transforms a single RAR file,
# passed under cmdline,
# to an equivalent ZIP file,
# storing it in the current directory
#
# Typical usage: rar2zip.sh infile.rar
#
#set -ex
function usage
{
cat <<EOF
Usage: rar2zip.sh infile.rar [-f] [-o outfile.zip]
Modifies a RAR file to a ZIP file
Options:
-f force continuation (e.g. if RAR file is damaged)
-o outfile Destination file (defaults to same filename as application, with .zip extension)
-- Break cmdline parsing (useful if the filename starts with -)
EOF
}
function cleanup
{
echo "Cleaning $1.."
rm -rfv $1
}
trap 'cleanup $TMPDIR' 2 15
CWD=$(pwd)
TMPDIR=$(mktemp -d -p /tmp/ rar2zip.XXXXXX)
if [ "$TMPDIR" = "" ]
then
echo "Error creating temporary dir!"
exit 1
fi
# Parse cmdline args
while :
do
case $1 in
-o)
OUTFILE=$2
shift 2
;;
-f)
FORCE=1
shift 1
;;
--)
shift 1
break
;;
*)
echo "A fix to it in the future!"
break
;;
esac
done
if [ "$1" = "" ]
then
usage
cleanup $TMPDIR
exit 1
fi
DEFAULT_ZIP_OPT="-v -9 -b /tmp/"
ZIP_OPT=${ZIP_OPT:-$DEFAULT_ZIP_OPT}
FILE_NAME=$1
BASE_NAME=$(basename $1)
DIR_NAME=$(dirname $1)
# If the target name doesn't start with /,
# it is NOT the 'absolute' pathname --
# It is needed (or something equivalent)
if [ "$(echo $DIR_NAME|grep -c -e'^/' )" = "0" ]
then
DIR_NAME=${CWD}/${DIR_NAME}
fi
ZIP_NAME=$(echo $BASE_NAME|sed -e's/\.[a-zA-Z0-9]\{1,\}$/\.zip/g')
if [ "$(file $DIR_NAME/$BASE_NAME|grep -c -e'RAR archive')" != "1" ]
then
echo "The file $DIR_NAME/$BASE_NAME doesn't appear to be a RAR archive!"
cleanup $TMPDIR
exit 1
fi
cd $TMPDIR
rm -fr ${BASE_NAME}-dir
mkdir -p ${BASE_NAME}-dir
cd ${BASE_NAME}-dir
unrar x $DIR_NAME/$BASE_NAME ||
{
if [ "FORCE" != "yes" ]
then
echo "The file $TARGET_NAME/$BASE_NAME appears to be damaged. I will stop now"
exit 1
else
echo "The file $TARGET_NAME/$BASE_NAME appears to be damaged. I will continue anyway..."
fi ;
}
#Zip the directory contents
find . -type f| sort | zip -@ $ZIP_OPT $ZIP_NAME
mv -- $ZIP_NAME $CWD
rm -fr $TMPDIR
Zinxi - exibir informações do hardware
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
Ubunto não reconhece rede ethernet (0)
Secure boot, artigo interessante, nada técnico. (3)
Instalação dualboot Windows 11 e Debian 13 (11)









