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