1#!/bin/bash 2 3# $1: path to fs_get_stats program 4# $2: start dir 5# $3: subdir to tar up (from $2) 6# $4: target tar name 7# $5: target tarball name (usually $(3).bz2) 8# $6: TARGET_OUT path to query device specific FS configs 9 10if [ $# -ne 6 ]; then 11 echo "Error: wrong number of arguments in cmd: $0 $* " 12 exit 1 13fi 14 15fs_get_stats=`readlink -f $1` 16start_dir=`readlink -f $2` 17dir_to_tar=$3 18target_tar=`readlink -f $4` 19target_tarball=`readlink -f $5` 20target_out=`readlink -f $6` 21 22cd $2 23 24#tar --no-recursion -cvf ${target_tar} ${dir_to_tar} 25rm ${target_tar} > /dev/null 2>&1 26 27# do dirs first 28subdirs=`find ${dir_to_tar} -type d -print` 29files=`find ${dir_to_tar} \! -type d -print` 30for f in ${subdirs} ${files} ; do 31 curr_perms=`stat -c 0%a $f` 32 [ -d "$f" ] && is_dir=1 || is_dir=0 33 new_info=`${fs_get_stats} ${curr_perms} ${is_dir} ${f} ${target_out}` 34 new_uid=`echo ${new_info} | awk '{print $1;}'` 35 new_gid=`echo ${new_info} | awk '{print $2;}'` 36 new_perms=`echo ${new_info} | awk '{print $3;}'` 37# echo "$f: dir: $is_dir curr: $curr_perms uid: $new_uid gid: $new_gid "\ 38# "perms: $new_perms" 39 tar --no-recursion --numeric-owner --owner $new_uid \ 40 --group $new_gid --mode $new_perms -p -rf ${target_tar} ${f} 41done 42 43if [ $? -eq 0 ] ; then 44 case "${target_tarball}" in 45 *.bz2 ) 46 bzip2 -c ${target_tar} > ${target_tarball} 47 ;; 48 *.gz ) 49 gzip -c ${target_tar} > ${target_tarball} 50 ;; 51 esac 52 success=$? 53 [ $success -eq 0 ] || rm -f ${target_tarball} 54 rm -f ${target_tar} 55 exit $success 56fi 57 58rm -f ${target_tar} 59exit 1 60