#!/bin/sh NameArh=DirArhiv.tgz if [ $# != 2 ]; then echo "No enought of parameters. Must be 2."; exit 1; fi i=`ls -1 $2 | wc -l` k=1 cd $2 if [ $1 = 0 ]; then echo "Pack $2 dir struct" while [ $k -le $i ] do cur_el=`ls $2 -1 | sed -n ${k}p`; echo Element $cur_el; if [ -d "$cur_el" ]; then cd "${cur_el}"; if [ -e "$NameArh" ]; then echo "Already packed"; else tar cvzf $NameArh ./* > /dev/null; if [ $? != "0" ]; then echo "Error packed"; exit 1; fi l_k=1 l_i=`ls -1 | wc -l`; while [ $l_k -le $l_i ] do l_cur_el=`ls -1 | sed -n ${l_k}p` # echo Check elem $l_k: $l_cur_el ; if [ ! "$l_cur_el" = "$NameArh" ]; then # echo Del elem: $l_cur_el; rm -fr "$l_cur_el" if [ $? != "0" ]; then echo "Delete $l_cur_el impossible!"; exit 1; fi let l_i=l_i-1; continue; fi let l_k=l_k+1; done fi cd ..; fi let k=k+1; done fi if [ $1 = 1 ]; then echo "Unpack $2 dir struct" while [ $k -le $i ] do cur_el=`ls $2 -1 | sed -n ${k}p`; echo Element $cur_el; if [ -d "$cur_el" ]; then cd "${cur_el}"; if [ `ls -1 | wc -l` -gt 1 ]; then echo "Element no pack or error pack!"; exit 1; fi if [ ! -e "$NameArh" ]; then echo " Element no pack!"; else tar xvzf "$NameArh" > /dev/null; if [ $? != "0" ]; then echo "Error unpacked"; exit 1; fi rm -f "$NameArh"; if [ $? != "0" ]; then echo "Delete $NameArh impossible!"; exit 1; fi fi cd ..; fi let k=k+1; done fi