jump to navigation

Maxcompression reloaded 3 Febbraio 2008

Posted by fripp in Bash, GNU/Linux, Informatica, Scripting.
Tags: , , , , , , ,
trackback

Ho migliorato lo script maxcompression in modo da poter comprimere più file alla volta. Nella prima versione dello script non avevo previsto questa possibilità.

Il codice dello script è il seguente:


#!/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=""
input=""

if [[ "$1" == "-p" ]]; then
	password=$1
	output=$
	until [ -z "$3" ]
	do

		if [[ -f "$3" || -d "$3" ]]; then
			input="$input $3"
			shift
		else
			echo -e "\nInsert a valid input file/directory name\n"
			echo "$3 is not a file/directoryA"
			exit 1
		fi
	done

else
	output=$1

	until [ -z $2 ]
	do

		if [[ -f "$2" || -d "$2" ]]; then
			input="$input $2"
			shift
		else
			echo -e "\nInsert a valid input file/directory name\n"
			echo "$2 is not a file/directory"
			exit 1
		fi
	done
fi

7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on $password $output $input 2>/dev/null
if [[ $? -ne 0 ]]; then
	echo "Error while compressing files"
	exit 1
fi

Il sorgente può esser scaricato da qui

Commenti»

1. maxcompression revolution « frammenti di razionalità - 25 Febbraio 2008

[...] sono vulnerabili nella gestione dei file il cui nome contiene degli spazi. Ecco una versione dello script di compressione che non è afflitta da tale [...]