NewStack
NewStack

Reputation: 990

How to write build phase run script to encrypt image files in the sub directoryies

I need to encrypt my resource image files in my project so I used NK-Encrypter and I write run script like this

DIRNAME=ImageFiles/Images
RESOURCES=Resources
ENC_KEY="abcdefghijklmnopqrstuvwxyz123456"

INDIR=$PROJECT_DIR/$DIRNAME
OUTDIR=$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/$RESOURCES/$DIRNAME

if [ ! -d "$OUTDIR" ]; then
mkdir -p "$OUTDIR"
fi

for file in "$INDIR"/*
                     do
                     echo "Encrypting $file"
                     "$PROJECT_DIR/crypt" -e -k $ENC_KEY -i "$file" -o "$OUTDIR/`basename "$file"`"
                     done

it will encrypt the image files contains in Images folder. Now I need to encrypt ImageFiles directory it contain lot of sub directory.The above script is encrypt only one sub directory I need to encrypt all sub directories in one script. How would you do this?

Update:

DIRNAME=ImageFiles/Images
        RESOURCES=Resources
        ENC_KEY="abcdefghijklmnopqrstuvwxyz123456"

        INDIR=$PROJECT_DIR/$DIRNAME
        OUTDIR=$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/$RESOURCES/$DIRNAME

        if [ ! -d "$OUTDIR" ]; then
        mkdir -p "$OUTDIR"
        fi

     for file in $`find $INDIR -type f`
        do
        echo "Encrypting $file"
        "$PROJECT_DIR/crypt" -e -k $ENC_KEY -i "$file" -o "$OUTDIR/`basename "$(dirname ${file})"`/`basename "$file"`"
        done

Finally I got encrypt sub directory using above code. I have faced another problem when the directoryh or file contain space it shows error Shell Script Invocation Error Command /bin/sh failed with exit code 1 how can I fix this.

Upvotes: 1

Views: 219

Answers (1)

devnull
devnull

Reputation: 123628

Replace the line

for file in "$INDIR"/*

with

for file in `find "$INDIR" -type f`

Upvotes: 1

Related Questions