All pastes #375939 Raw Edit

Archive files easier

public shellscript v1 · immutable
#375939 ·published 2007-02-28 18:52 UTC
rendered paste body
#!/bin/bash# Archive files easier by highnekoline="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"a="Zip all files and folders in current directory"b="Test all zip archives in current directory"c="Unzip all archives in current directory"d="Unrar all archives in current directory"e="Zip each folder in cd into an archive"f="Unzip archives directly into the current directory"g="Unzip using tests to check if directory exists"h="Backup a folder or file using tar gzip"i="Backup all files in current directory using tar gzip"function warning {	printf "$line\nCurrent Directory: $PWD\n$1\n$line\n"	read -p "Do you want to continue [Y/n]? " continue	case "$continue" in		"Y" | "y" )			echo "$line"		;;		"N" | "n" )			echo "$line"			exit 0		;;	esac}clear; printf "$line\\n[A] $a\\n[B] $b\\n[C] $c\\n[D] $d\\n[E] $e\\n[F] $f\\n[G] $g\\n[H] $h\\n[I] $i\\n$line\n"; read choicecase "$choice" in	"A" | "a" )		warning "$a"		# Zip all files and folders in current directory		zip -r ${PWD##*/}.zip *	;;	"B" | "b" )		warning "$b"		# Test all zip archives in current directory		for x in *.zip; do zip -T "$x"; done	;;	"C" | "c" )		warning "$c"		# Unzip all archives in current folder		for x in *.zip; do mkdir "${x%.zip}" && cd "${x%.zip}" && unzip "../$x" && cd ..; done	;;	"D" | "d" )		warning "$d"		# Unrars all archives in current folder		for x in *.rar; do mkdir "${x%.rar}" && cd "${x%.rar}" && unrar x "../$x" && cd ..; done	;;	"E" | "e" )		warning "$e"		# Zip each folder in cd into an archive		for x in *; do if [ -d "$x" ]; then cd "$x" && zip -r "../${x}.zip" * && cd ..; fi; done	;;	"F" | "f" )		warning "$f"		# Unzip archives directly into the current directory		for x in *.zip; do unzip "$x"; done	;;	"G" | "g" )		warning "$g"		# Unzip using tests to check if directory exists		for i in *.zip; do if zipinfo "$i" | grep -q '/'; then unzip "$i"; else mkdir "${i%.zip}" && cd "${i%.zip}" && unzip "../$i" && cd ..; fi; done	;;	"H" | "h" )		warning "$h"		# Backup a folder or file using tar gzip		read -p "Full path of file or folder to backup into cd? " answer		cd "$answer"; tar -czf "${PWD##*/}.tgz" *; echo "Save location: ${PWD}/${PWD##*/}.tgz"	;;	"I" | "i" )		warning "$i"		# Backup all files in current directory using tar gzip		tar -czf "${PWD##*/}.tgz" *	;;esacexit 0