"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "extra/to-7zip.in" between
littleutils-1.2.3.tar.lz and littleutils-1.2.4.tar.lz

About: littleutils are a collection of small and simple utilities (rename files, search for duplicate files, ...).

to-7zip.in  (littleutils-1.2.3.tar.lz):to-7zip.in  (littleutils-1.2.4.tar.lz)
#! PROGBASH #! PROGBASH
# vim: set filetype=bash: # vim: set filetype=bash:
# to-7zip: Converts .Z, .zip, .rar, .gz, .lzo, .bz2, and .zst files to 7-zip # to-7zip: Converts .Z, .zip, .rar, .gz, .lzo, .bz2, and .zst files to 7-zip
# format. # format.
# Copyright (C) 2006-2020 by Brian Lindholm. This file is part of the # Copyright (C) 2006-2021 by Brian Lindholm. This file is part of the
# littleutils utility set. # littleutils utility set.
# #
# The to-7zip utility is free software; you can redistribute it and/or modify # The to-7zip utility is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free # it under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later version. # Software Foundation; either version 3, or (at your option) any later version.
# #
# The to-7zip utility is distributed in the hope that it will be useful, but # The to-7zip utility is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# the littleutils. If not, see <https://www.gnu.org/licenses/>. # the littleutils. If not, see <https://www.gnu.org/licenses/>.
# set up traps
trap 'rm -f ${TMPFILE} ; exit 1' 1 2 3 13 15
trap 'rm -f ${TMPFILE} ; exit 0' 0
# get command-line options # get command-line options
DELORIG='no' DELORIG='n'
MAXCOMP='no' MAXCOMP='n'
OVERWRITE='yes' OVERWRITE='y'
PREFER='' PREFER=''
RETAINTIME='no' RETAINTIME='n'
while getopts 46dhkmnt opts while getopts 46dhkmnt opts
do do
case $opts in case $opts in
4) PREFER='--prefer-family=IPv4' ;; 4) PREFER='--prefer-family=IPv4' ;;
6) PREFER='--prefer-family=IPv6' ;; 6) PREFER='--prefer-family=IPv6' ;;
d) DELORIG='yes' ;; d) DELORIG='y' ;;
h) echo 'to-7zip LU_VERSION' h) echo 'to-7zip LU_VERSION'
echo 'usage: to-7zip [-(IPv)4] [-(IPV)6] [-d(elete_original)] [-k(eep_sma llest)]' echo 'usage: to-7zip [-(IPv)4] [-(IPV)6] [-d(elete_original)] [-k(eep_sma llest)]'
echo ' [-m(ax_compression)] [-n(o_overwrite)] [-t(imestamp retain)]' echo ' [-m(ax_compression)] [-n(o_overwrite)] [-t(imestamp retain)]'
echo ' [-h(elp)] filename ...' echo ' [-h(elp)] filename ...'
exit 0 ;; exit 0 ;;
k) DELORIG='small' ;; k) DELORIG='small' ;;
m) MAXCOMP='yes' ;; m) MAXCOMP='y' ;;
n) OVERWRITE='no' ;; n) OVERWRITE='n' ;;
t) RETAINTIME='yes' ;; t) RETAINTIME='y' ;;
*) echo 'to-7zip LU_VERSION' *) echo 'to-7zip LU_VERSION'
echo 'usage: to-7zip [-(IPv)4] [-(IPV)6] [-d(elete_original)] [-k(eep_sma llest)]' echo 'usage: to-7zip [-(IPv)4] [-(IPV)6] [-d(elete_original)] [-k(eep_sma llest)]'
echo ' [-m(ax_compression)] [-n(o_overwrite)] [-t(imestamp retain)]' echo ' [-m(ax_compression)] [-n(o_overwrite)] [-t(imestamp retain)]'
echo ' [-h(elp)] filename ...' echo ' [-h(elp)] filename ...'
exit 1 ;; exit 1 ;;
esac esac
done done
shift `expr ${OPTIND} - 1` shift $((${OPTIND}-1))
if [ "$MAXCOMP" = 'yes' ]; then
# compute ancillary parameters
if [ "$MAXCOMP" = 'y' ]; then
OPTSLZMA='-mx=9' OPTSLZMA='-mx=9'
else else
OPTSLZMA='-mx=7' OPTSLZMA='-mx=7'
fi fi
# set up traps
trap 'rm -f $TMPFILE ; exit 1' 1 2 3 13 15
# run through files # run through files
declare -i S0=0 S1=0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
# if file is actually a URL, attempt to download, otherwise verify that it alr eady exists # if file is actually a URL, attempt to download, otherwise verify that it alr eady exists
NAME="$1" NAME="$1"
if [ "${NAME:0:8}" = 'https://' -o "${NAME:0:7}" = 'http://' -o "${NAME:0:6}" = 'ftp://' ]; then if [ "${NAME:0:8}" = 'https://' -o "${NAME:0:7}" = 'http://' -o "${NAME:0:6}" = 'ftp://' ]; then
wget ${PREFER} -q ${NAME} wget ${PREFER} -q "$NAME"
NAME=${NAME##*/} NAME="${NAME##*/}"
if [ ! -f "$NAME" -o ! -r "$NAME" ]; then if [ ! -f "$NAME" -o ! -r "$NAME" ]; then
echo "${NAME} failed to download!" echo "$NAME failed to download!"
shift; continue shift; continue
fi fi
elif [ ! -f "$NAME" -o ! -r "$NAME" ]; then elif [ ! -f "$NAME" -o ! -r "$NAME" ]; then
echo "${NAME} is not a readable file!" echo "$NAME is not a readable file!"
shift; continue shift; continue
fi fi
echo -n "${NAME}... " echo -n "${NAME}... "
# determine filepath and check for writeability # determine filepath and check for writeability
FILENAME="${NAME##*/}" FILENAME="${NAME##*/}"
FILEPATH="${NAME%${FILENAME}}" FILEPATH="${NAME%${FILENAME}}"
FILEPATH="${FILEPATH%/}" FILEPATH="${FILEPATH%/}"
if [ "X$FILEPATH" = 'X' ]; then if [ "X$FILEPATH" = 'X' ]; then
FILEPATH='.' FILEPATH='.'
skipping to change at line 117 skipping to change at line 119
NEWNAME="${NAME%.Z}.7z" NEWNAME="${NAME%.Z}.7z"
elif [ "${NAME#${NAME%.zip}}" = '.zip' ]; then elif [ "${NAME#${NAME%.zip}}" = '.zip' ]; then
NEWNAME="${NAME%.zip}.tar.7z" NEWNAME="${NAME%.zip}.tar.7z"
elif [ "${NAME#${NAME%.ZIP}}" = '.ZIP' ]; then elif [ "${NAME#${NAME%.ZIP}}" = '.ZIP' ]; then
NEWNAME="${NAME%.ZIP}.tar.7z" NEWNAME="${NAME%.ZIP}.tar.7z"
elif [ "${NAME#${NAME%.zst}}" = '.zst' ]; then elif [ "${NAME#${NAME%.zst}}" = '.zst' ]; then
NEWNAME="${NAME%.zst}.7z" NEWNAME="${NAME%.zst}.7z"
else else
NEWNAME="${NAME}.7z" NEWNAME="${NAME}.7z"
fi fi
if [ "$OVERWRITE" = 'no' -a -e "$NEWNAME" ]; then if [ "$OVERWRITE" = 'n' -a -e "$NEWNAME" ]; then
echo 'skipped because target already exists' echo 'skipped because target already exists'
shift; continue shift; continue
fi fi
# recompress based on filetype # recompress based on filetype
FILETYPE=`file -b "$NAME" | cut -b1-4 | tr '[:upper:]' '[:lower:]'` FILETYPE=$(file -b "$NAME" | cut -b1-4 | tr '[:upper:]' '[:lower:]')
# create temporary target name (note that this is currently insecure, # create temporary target name (note that this is currently insecure,
# as p7zip annoyingly refuses to overwrite a zero-length file) # as p7zip annoyingly refuses to overwrite a zero-length file)
TMPFILE=`tempname -c -d "$FILEPATH" -s .7z .to-7zip_$$` || exit 99 TMPFILE=$(tempname -c -d "$FILEPATH" -s .7z .to-7zip_$$) || exit 99
if [ "X$FILETYPE" = 'X7-zi' ]; then if [ "X$FILETYPE" = 'X7-zi' ]; then
echo 'already converted to 7zip' echo 'already converted to 7zip'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
elif [ "X$FILETYPE" = 'Xbzip' ]; then elif [ "X$FILETYPE" = 'Xbzip' ]; then
bzip2 -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null bzip2 -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on bzip2-to-7zip conversion' echo 'failed on bzip2-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xgzip' ]; then elif [ "X$FILETYPE" = 'Xgzip' ]; then
gzip -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null gzip -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on gzip-to-7zip conversion' echo 'failed on gzip-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xlzop' ]; then elif [ "X$FILETYPE" = 'Xlzop' ]; then
lzop -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null lzop -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on lzop-to-7zip conversion' echo 'failed on lzop-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xcomp' ]; then elif [ "X$FILETYPE" = 'Xcomp' ]; then
gzip -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null gzip -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on compress-to-7zip conversion' echo 'failed on compress-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xrar ' ]; then elif [ "X$FILETYPE" = 'Xrar ' ]; then
rar2tarcat "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null rar2tarcat "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on rar-to-7zip conversion' echo 'failed on rar-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xzip ' ]; then elif [ "X$FILETYPE" = 'Xzip ' ]; then
zip2tarcat "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null zip2tarcat "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on zip-to-7zip conversion' echo 'failed on zip-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xzsta' ]; then elif [ "X$FILETYPE" = 'Xzsta' ]; then
zstd -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA "$TMPFILE" > /dev/null zstd -c -d -q "$NAME" | PROG7Z a -si -bd $OPTSLZMA $TMPFILE > /dev/null
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on zst-to-7zip conversion' echo 'failed on zst-to-7zip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
else else
echo 'skipped on unrecognized filetype' echo 'skipped on unrecognized filetype'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
# perform the final move, deleting old or new if necessary # perform the final move, deleting old or new if necessary
chmod --reference="$NAME" "$TMPFILE" chmod --reference="$NAME" $TMPFILE
mv "$TMPFILE" "$NEWNAME" mv $TMPFILE "$NEWNAME"
if [ "$RETAINTIME" = 'yes' ]; then if [ "$RETAINTIME" = 'y' ]; then
touch --reference="$NAME" "$NEWNAME" touch --reference="$NAME" "$NEWNAME"
fi fi
S0=`filesize "$NAME"` S0=$(filesize "$NAME")
S1=`filesize "$NEWNAME"` S1=$(filesize "$NEWNAME")
if [ "$S1" -lt "$S0" ]; then if [ $S1 -lt $S0 ]; then
if [ "$DELORIG" != 'no' ]; then if [ "$DELORIG" != 'n' ]; then
rm -f "$NAME" rm -f "$NAME"
echo "${S0} vs. ${S1} (deleting original)" echo "$S0 vs. $S1 (deleting original)"
else else
echo "${S0} vs. ${S1}" echo "$S0 vs. $S1"
fi fi
else else
if [ "$DELORIG" = 'no' ]; then if [ "$DELORIG" = 'n' ]; then
echo "${S0} vs. ${S1} (warning: new file is not smaller)" echo "$S0 vs. $S1 (warning: new file is not smaller)"
elif [ "$DELORIG" = 'yes' ]; then elif [ "$DELORIG" = 'y' ]; then
rm -f "$NAME" rm -f "$NAME"
echo "${S0} vs. ${S1} (deleting original: new file is not smaller)" echo "$S0 vs. $S1 (deleting original: new file is not smaller)"
else else
rm -f "$NEWNAME" rm -f "$NEWNAME"
echo 'new file deleted (not smaller than old)' echo 'new file deleted (not smaller than old)'
fi fi
fi fi
shift shift
done done
 End of changes. 37 change blocks. 
65 lines changed or deleted 60 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)