~ubuntu-branches/ubuntu/precise/fs2ram/precise

« back to all changes in this revision

Viewing changes to lib/fs2ram/unmount-scripts/keep_folder_structure

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Le Brouster
  • Date: 2011-03-20 19:41:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110320194139-gsu65ys04aprln3s
Tags: 0.3.10
* First release in the debian archive (Closes: #600840)
* Fix bashisms (dash)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
 
 
3
DIR=$1
 
4
shift
 
5
OPTIONS=$*
 
6
 
 
7
FIND=/usr/bin/find
 
8
STAT=/usr/bin/stat
 
9
 
 
10
# Decode the options given in parameters
 
11
IGNORE_FILE_REGEXP=""
 
12
IGNORE_FOLDER_REGEXP=""
 
13
 
 
14
for opt in $options; do
 
15
    case $opt in
 
16
        ignore_file=*)
 
17
            IGNORE_FILE_REGEXP=$(echo $opt | sed -e "s/^ignore_file=\(.*\)$/\1/")
 
18
            ;;
 
19
        ignore_folder=*)
 
20
            IGNORE_FOLDER_REGEXP=$(echo $opt | sed -e "s/^ignore_folder=\(.*\)$/\1/")
 
21
            ;;
 
22
        *)
 
23
            ;;
 
24
    esac
 
25
done
 
26
 
 
27
# This function filter the file to ignore according to the regexp given in
 
28
# parameter.
 
29
filter_ignore() {
 
30
    local ignore_regexp
 
31
    ignore_regexp=$1
 
32
    while read line; do
 
33
        if [ -z "$ignore_regexp" ] || [ "$(printf "$line" | sed -e "s/'$//" | egrep "$ignore_regexp")" = "" ]; then
 
34
            echo "$line"
 
35
        fi
 
36
    done
 
37
}
 
38
 
 
39
# This function create a shell script that will generate the structure of
 
40
# the folder $dir
 
41
generate_folder_structure() {
 
42
    $FIND $DIR -type d -exec echo "mkdir -p '{}'" \; | filter_ignore $IGNORE_FOLDER_REGEXP
 
43
 
 
44
    $FIND $DIR -type d -exec $STAT --format "chown %U '{}'" {} \; | filter_ignore "$IGNORE_FOLDER_REGEXP"
 
45
    $FIND $DIR -type d -exec $STAT --format "chgrp %G '{}'" {} \; | filter_ignore "$IGNORE_FOLDER_REGEXP"
 
46
    $FIND $DIR -type d -exec $STAT --format "chmod %a '{}'" {} \; | filter_ignore "$IGNORE_FOLDER_REGEXP"
 
47
}
 
48
 
 
49
generate_folder_structure
 
50
 
 
51