codekingpro/portable-devtools
114k
1#!/bin/sh2# zforce: force a gz extension on all gzip files so that gzip will not3# compress them twice.4#5# This can be useful for files with names truncated after a file transfer.6# 12345678901234 is renamed to 12345678901.gz7 8 9# Copyright (C) 2002, 2007, 2010-2025 Free Software Foundation, Inc.10# Copyright (C) 1993 Jean-loup Gailly11 12# This program is free software; you can redistribute it and/or modify13# it under the terms of the GNU General Public License as published by14# the Free Software Foundation; either version 3 of the License, or15# (at your option) any later version.16 17# This program is distributed in the hope that it will be useful,18# but WITHOUT ANY WARRANTY; without even the implied warranty of19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20# GNU General Public License for more details.21 22# You should have received a copy of the GNU General Public License23# along with this program. If not, see <https://www.gnu.org/licenses/>.24 25version="zforce (gzip) 1.1426Copyright (C) 2025 Free Software Foundation, Inc.27This is free software. You may redistribute copies of it under the terms of28the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.29There is NO WARRANTY, to the extent permitted by law.30 31Written by Jean-loup Gailly."32 33usage="Usage: $0 [FILE]...34Force a .gz extension on all compressed FILEs so that gzip will35not compress them twice.36 37Report bugs to <bug-gzip@gnu.org>."38 39if test $# = 0; then40 printf >&2 '%s\n' "$0: invalid number of operands; try \`$0 --help' for help"41 exit 142fi43 44res=045for i do46 case "$i" in47 --h*) printf '%s\n' "$usage" || exit 1; exit;;48 --v*) printf '%s\n' "$version" || exit 1; exit;;49 *[-.]z | *[-.]gz | *.t[ag]z) continue;;50 esac51 52 if test ! -f "$i" ; then53 printf '%s\n' "zforce: $i not a file"54 res=155 continue56 fi57 58 if gzip -lv < "$i" 2>/dev/null | grep '^defl' > /dev/null; then59 60 new="$i.gz"61 mv "$i" "$new" && printf '%s\n' "$i -- replaced with $new" || res=162 fi63done64exit $res65 