Skip to content

Instantly share code, notes, and snippets.

@wangshijun
Created September 19, 2012 06:15
Show Gist options
  • Select an option

  • Save wangshijun/3747978 to your computer and use it in GitHub Desktop.

Select an option

Save wangshijun/3747978 to your computer and use it in GitHub Desktop.
shell: build application with tar, ignore certain patterns
#!/bin/bash
TMP_DIR="output"
PRODUCT_DIR="project-production"
IGNORE_FILE="$TMP_DIR build.sh tests"
OUTPUT_FILE="project-production.tar.gz"
# prepare tmp dir
mkdir -p $TMP_DIR
rm -rf $TMP_DIR/*
mkdir -p $TMP_DIR/$PRODUCT_DIR
# copy from source to tmp, ignore some files
for i in `ls`
do
boolUse=1
for j in $IGNORE_FILE
do
if [ $j == $i ]
then
boolUse=0
break
fi
done
if [ $boolUse == 1 ]
then
cp -r $i $TMP_DIR/$PRODUCT_DIR/
echo $i
fi
done
cd $TMP_DIR
# remove version control misc
find ./ -name CVS -exec rm -rf {} \;
find ./ -type d -name ".svn"|xargs rm -rf {}
find ./ -type d -name ".git"|xargs rm -rf {}
tar zcvf $OUTPUT_FILE $PRODUCT_DIR/*
rm -rf $PRODUCT_DIR
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment