Reputation: 6315
I am encrypting some resources in my Cocoa app using the following script (Source):
DIRNAME=EncryptedResources
ENC_KEY="abcdefghijklmnopqrstuvwxyz123456"
INDIR=$PROJECT_DIR/$DIRNAME
OUTDIR=$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/$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
However the script doesn't handle sub-directories within the EncryptedResources directory. I have several nested sub-directories so what would be the easiest way to modify the shell script to handle the sub-directories and have those output correctly.
Upvotes: 0
Views: 415
Reputation: 6315
FYI I used the following:
DIRNAME=ENCRYPTEDCONTENT
ENC_KEY="INSERT ENCRYPTION KEY HERE"
INDIR=$PROJECT_DIR/$DIRNAME
OUTDIR=$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/Resources/$DIRNAME
if [ ! -d "$OUTDIR" ]; then
mkdir -p "$OUTDIR"
fi
while IFS= read -r -d $'\0' dir;
do
DIRECTORY=`echo $dir | sed -e "s,$INDIR,$OUTDIR,g"`
mkdir -p "$DIRECTORY"
done < <(find "$INDIR" -type d -print0)
while IFS= read -r -d $'\0' file;
do
OUTFILE=`echo $file | sed -e "s,$INDIR,$OUTDIR,g"`
if [ ! -d "$file" ]; then
echo "Encrypting $file"
"$PROJECT_DIR/crypt" -e -k $ENC_KEY -i "$file" -o "$OUTFILE"
fi
done < <(find "$INDIR" -type f -print0)
Upvotes: 0
Reputation: 7899
You need to use the find
command instead of your for
loop.
find $INDIR -exec "$PROJECT_DIR/crypt"
-e -k $ENC_KEY -i {} -o "$OUTDIR/`basename {}`" \; # all on one line
might be a good approximation of what you need to do, but find
is very hard to use, and I'm working from memory.
Upvotes: 1