"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/to-lzip.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-lzip.in  (littleutils-1.2.3.tar.lz):to-lzip.in  (littleutils-1.2.4.tar.lz)
#! PROGBASH #! PROGBASH
# vim: set filetype=bash: # vim: set filetype=bash:
# to-lzip: Converts .Z, .lzo, .zip, .rar, .gz, .bz2, .zst, and .lzma files to # to-lzip: Converts .Z, .lzo, .zip, .rar, .gz, .bz2, .zst, and .lzma files to
# lz format. # lz format.
# Copyright (C) 2009-2020 by Brian Lindholm. This file is part of the # Copyright (C) 2009-2021 by Brian Lindholm. This file is part of the
# littleutils utility set. # littleutils utility set.
# #
# The to-lzip utility is free software; you can redistribute it and/or modify # The to-lzip 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-lzip utility is distributed in the hope that it will be useful, but # The to-lzip 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'
LZMAUTIL='PROGLZMA' LZMAUTIL='PROGLZMA'
MAXCOMP='no' MAXCOMP='n'
OVERWRITE='yes' OVERWRITE='y'
PREFER='' PREFER=''
RETAINTIME='no' RETAINTIME='n'
THREADS='1' declare -i THREADS=1
while getopts 46dhkmnp:t opts while getopts 46dhkmnp:t 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-lzip LU_VERSION' h) echo 'to-lzip LU_VERSION'
echo 'usage: to-lzip [-(IPv)4] [-(IPv)6] [-d(el_orig)] [-k(eep_smallest)] ' echo 'usage: to-lzip [-(IPv)4] [-(IPv)6] [-d(el_orig)] [-k(eep_smallest)] '
echo ' [-m(ax_compression)] [-n(o_overwrite)] [-p threads]' echo ' [-m(ax_compression)] [-n(o_overwrite)] [-p threads]'
echo ' [-t(imestamp retain)] [-h(elp)] filename ...' echo ' [-t(imestamp retain)] [-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' ;;
p) THREADS=${OPTARG} ;; p) THREADS=$OPTARG ;;
t) RETAINTIME='yes' ;; t) RETAINTIME='y' ;;
*) echo 'to-lzip LU_VERSION' *) echo 'to-lzip LU_VERSION'
echo 'usage: to-lzip [-(IPv)4] [-(IPv)6] [-d(el_orig)] [-k(eep_smallest)] ' echo 'usage: to-lzip [-(IPv)4] [-(IPv)6] [-d(el_orig)] [-k(eep_smallest)] '
echo ' [-m(ax_compression)] [-n(o_overwrite)] [-p threads]' echo ' [-m(ax_compression)] [-n(o_overwrite)] [-p threads]'
echo ' [-t(imestamp retain)] [-h(elp)] filename ...' echo ' [-t(imestamp retain)] [-h(elp)] filename ...'
exit 1 ;; exit 1 ;;
esac esac
done done
shift `expr ${OPTIND} - 1` shift $((${OPTIND}-1))
if [ "$MAXCOMP" = 'yes' ]; then if [ "$MAXCOMP" = 'y' ]; then
LZIP_OPTS='-9' LZIP_OPTS='-9'
else else
LZIP_OPTS='-6' LZIP_OPTS='-6'
fi fi
if [ "$THREADS" = '1' ]; then if [ $THREADS -eq 1 ]; then
ENGINE='lzip' ENGINE='lzip'
else else
command -v plzip > /dev/null command -v plzip > /dev/null
if [ "$?" = '0' ]; then if [ $? -eq 0 ]; then
if [ "$THREADS" = '0' ]; then if [ $THREADS -eq 0 ]; then
if [ -r /proc/cpuinfo ]; then if [ -r /proc/cpuinfo ]; then
NCORE=`grep -c '^processor' /proc/cpuinfo` NCORE=$(grep -c '^processor' /proc/cpuinfo)
else else
NCORE=`nproc` NCORE=$(nproc)
fi fi
ENGINE="plzip -n ${NCORE}" ENGINE="plzip -n $NCORE"
else else
ENGINE="plzip -n ${THREADS}" ENGINE="plzip -n $THREADS"
fi fi
else else
echo 'to-lzip warning: plzip not found; reverting to lzip' echo 'to-lzip warning: plzip not found; reverting to lzip'
ENGINE='lzip' ENGINE='lzip'
fi fi
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 142 skipping to change at line 142
NEWNAME="${NAME%.Z}.lz" NEWNAME="${NAME%.Z}.lz"
elif [ "${NAME#${NAME%.zip}}" = '.zip' ]; then elif [ "${NAME#${NAME%.zip}}" = '.zip' ]; then
NEWNAME="${NAME%.zip}.tar.lz" NEWNAME="${NAME%.zip}.tar.lz"
elif [ "${NAME#${NAME%.ZIP}}" = '.ZIP' ]; then elif [ "${NAME#${NAME%.ZIP}}" = '.ZIP' ]; then
NEWNAME="${NAME%.ZIP}.tar.lz" NEWNAME="${NAME%.ZIP}.tar.lz"
elif [ "${NAME#${NAME%.zst}}" = '.zst' ]; then elif [ "${NAME#${NAME%.zst}}" = '.zst' ]; then
NEWNAME="${NAME%.zst}.lz" NEWNAME="${NAME%.zst}.lz"
else else
NEWNAME="${NAME}.lz" NEWNAME="${NAME}.lz"
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:]')
# file versions before 5.03 cannot detect lzma # file 5.02 and earlier cannot detect lzma, listing "data" instead
if [ "$FILETYPE" = 'data' -a "${NAME#${NAME%.lzma}}" = '.lzma' ]; then if [ "$FILETYPE" = 'data' -a "${NAME#${NAME%.lzma}}" = '.lzma' ]; then
FILETYPE='lzma' FILETYPE='lzma'
fi fi
TMPFILE=`tempname -d "$FILEPATH" .to-lzip_$$` || exit 99 TMPFILE=$(tempname -d "$FILEPATH" .to-lzip_$$) || exit 99
if [ "X$FILETYPE" = 'Xlzip' ]; then if [ "X$FILETYPE" = 'Xlzip' ]; then
echo 'already converted to lz' echo 'already converted to lz'
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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" bzip2 -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on bzip2-to-lzip conversion' echo 'failed on bzip2-to-lzip 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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" gzip -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on gzip-to-lzip conversion' echo 'failed on gzip-to-lzip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
shift; continue shift; continue
fi fi
elif [ "X$FILETYPE" = 'Xlzma' ]; then elif [ "X$FILETYPE" = 'Xlzma' ]; then
if [ "X$LZMAUTIL" = 'Xlzma_alone' ]; then if [ "X$LZMAUTIL" = 'Xlzma_alone' ]; then
lzma_alone d "$NAME" -so | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" lzma_alone d "$NAME" -so | $ENGINE -q $LZIP_OPTS > $TMPFILE
else else
lzma -c -d -q "$NAME" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" lzma -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
fi fi
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on lzma-to-lzip conversion' echo 'failed on lzma-to-lzip conversion'
rm -f "$TMPFILE" rm -f $TMPFILE
else else
CONVERTED='yes' CONVERTED='y'
fi fi
elif [ "X$FILETYPE" = 'Xlzop' ]; then elif [ "X$FILETYPE" = 'Xlzop' ]; then
lzop -c -d -q "$NAME" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" lzop -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on lzop-to-lzip conversion' echo 'failed on lzop-to-lzip 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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" gzip -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on compress-to-lzip conversion' echo 'failed on compress-to-lzip 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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" rar2tarcat "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on rar-to-lzip conversion' echo 'failed on rar-to-lzip 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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" zip2tarcat "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on zip-to-lzip conversion' echo 'failed on zip-to-lzip 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" | ${ENGINE} -q $LZIP_OPTS > "$TMPFILE" zstd -c -d -q "$NAME" | $ENGINE -q $LZIP_OPTS > $TMPFILE
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo 'failed on zst-to-lzip conversion' echo 'failed on zst-to-lzip 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. 49 change blocks. 
81 lines changed or deleted 73 lines changed or added

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