The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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) |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 8 | # $6: TARGET_OUT path to query device specific FS configs |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 9 | |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 10 | if [ $# -ne 6 ]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 11 | echo "Error: wrong number of arguments in cmd: $0 $* " |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | fs_get_stats=`readlink -f $1` |
| 16 | start_dir=`readlink -f $2` |
| 17 | dir_to_tar=$3 |
| 18 | target_tar=`readlink -f $4` |
| 19 | target_tarball=`readlink -f $5` |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 20 | target_out=`readlink -f $6` |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 21 | |
| 22 | cd $2 |
| 23 | |
| 24 | #tar --no-recursion -cvf ${target_tar} ${dir_to_tar} |
| 25 | rm ${target_tar} > /dev/null 2>&1 |
| 26 | |
| 27 | # do dirs first |
| 28 | subdirs=`find ${dir_to_tar} -type d -print` |
| 29 | files=`find ${dir_to_tar} \! -type d -print` |
| 30 | for f in ${subdirs} ${files} ; do |
| 31 | curr_perms=`stat -c 0%a $f` |
| 32 | [ -d "$f" ] && is_dir=1 || is_dir=0 |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 33 | new_info=`${fs_get_stats} ${curr_perms} ${is_dir} ${f} ${target_out}` |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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} |
| 41 | done |
| 42 | |
| 43 | if [ $? -eq 0 ] ; then |
Bruce Beare | 69ef5ce | 2010-06-11 12:05:57 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 52 | success=$? |
| 53 | [ $success -eq 0 ] || rm -f ${target_tarball} |
| 54 | rm -f ${target_tar} |
| 55 | exit $success |
| 56 | fi |
| 57 | |
| 58 | rm -f ${target_tar} |
| 59 | exit 1 |