maxcompression revolution 25 Febbraio 2008
Posted by fripp in Bash, Debian, GNU/Linux, Gnome, Informatica, Mac OS X, Programmazione, Scripting, Sistemi Operativi, Ubuntu, Unix.Tags: 7-zip, 7z, archive format, compression, lzma, m0, mfb, mx
trackback
Come al solito i miei script sono vulnerabili nella gestione dei file il cui nome contiene degli spazi. Ecco una versione dello script di compressione che non è afflitta da tale vulnerabilità:
#!/bin/bash
# maxcompression2.sh
# Copyright (C) 2007 Calogero Sanfilippo sanfilippo.calogero@gmail.com
#
# This program 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 Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
function usage(){
echo -e "\nmaxcompression: usage: maxcompression [-p] output_filename.7z input_filename1 input_filename2 ….."
exit 1
}
if [[ $# -le 1 ]]; then
usage
fi
password=""
output=""
if [[ "$1" == "-p" ]]; then
password=$1
output=$2
shift
shift
else
output=$1
shift
fi
for i in "$@"; do
if [[ ! -f "$i" && ! -d "$i" ]]; then
echo "$i is not a valid file/directory"
exit 1
fi
done
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on $password $output "$@" 2>/dev/null
if [[ $? -ne 0 ]]; then
echo "Error while compressing files"
exit 1
fi















Commenti»
No comments yet — be the first.