blob: ef0fe86db5564a9f706edbefcf6c006722853414 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#!/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)
Thierry Strudel74a81e62015-07-09 09:54:55 -07008# $6: TARGET_OUT path to query device specific FS configs
The Android Open Source Project88b60792009-03-03 19:28:42 -08009
Thierry Strudel74a81e62015-07-09 09:54:55 -070010if [ $# -ne 6 ]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -080011 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`
Thierry Strudel74a81e62015-07-09 09:54:55 -070020target_out=`readlink -f $6`
The Android Open Source Project88b60792009-03-03 19:28:42 -080021
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
Thierry Strudel74a81e62015-07-09 09:54:55 -070033 new_info=`${fs_get_stats} ${curr_perms} ${is_dir} ${f} ${target_out}`
The Android Open Source Project88b60792009-03-03 19:28:42 -080034 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
Bruce Beare69ef5ce2010-06-11 12:05:57 -070044 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080052 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