Skip to content

Instantly share code, notes, and snippets.

@gavinHuang
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save gavinHuang/65a61ed270e60e500293 to your computer and use it in GitHub Desktop.

Select an option

Save gavinHuang/65a61ed270e60e500293 to your computer and use it in GitHub Desktop.
shell
env_source=$(ping `hostname` -c 1 |grep "gramws.com ping statistics")
is_cq=$(echo $env_source |grep "cq-core" -c)
is_dev=$(echo $env_source |grep "dev-core" -c)
is_prod=$(echo $env_source |grep "prod-core" -c)
if [ "$is_cq" == "1" ]
then
ENV="CQ"
CPCODE=$CQ_CPCODE
RIGHTS=$CQ_RIGHTS
elif [ "$is_prod" == "1" ]
then
ENV="PROD"
CPCODE=$PROD_CPCODE
RIGHTS=$PROD_RIGHTS
else
ENV="DEV"
CPCODE=$DEV_CPCODE
RIGHTS=$DEV_RIGHTS
fi
echo "running on $ENV"
#step 1.1: download from cdn
echo "start to download plist files at:$(echo `date`)"
export RSYNC_PASSWORD=${CDN_PWD}
/usr/bin/rsync -r --include '*.plist' --include '*/' --exclude '*' --prune-empty-dirs $CDN_USER@$CDN_HOST::$CDN_USER/$CPCODE/protected/$RIGHTS/ $WORKSPACE/cdn
echo "done with rsync at:$(echo `date`)"
#step 1.2: back up
/bin/cp -fr $WORKSPACE/cdn/* $WORKSPACE/cdn_backup
ls $WORKSPACE/cdn/*/*/*.plist > $WORKSPACE/plist_cdn.txt
echo "task file generated"
#step 1.3: replace
while read line; do
if [[ $line ]]
then
#replace text and save it back right away.
sed -i "s/$DOMAIN_OLD/$DOMAIN_NEW/g" $line
echo "done with:[$line]"
fi
done < $WORKSPACE/plist_cdn.txt
#step 1.4: update to cdn
echo "begin to rsync to cdn"
/usr/bin/rsync -arz $WORKSPACE/cdn/* $CDN_USER@$CDN_HOST::$CDN_USER/$CPCODE/protected/$RIGHTS/
echo "done with rsync to cdn"
#step 2.1: begin to deal with local zip files
echo "start to process nas file"
ls $NAS_DIR/*/*/*/*.zip > $WORKSPACE/plist_nas.txt
echo "task file generated!"
cd "$WORKSPACE/extracted/"
while read line; do
#sample:$NAS_DIR/a/a7.95ff9a56-b723-4881-94e6-f0b0da90a979/1.0.0/a7.95ff9a56-b723-4881-94e6-f0b0da90a979-1.0.0.zip
plist=$(unzip -l $line | grep -o ".*\.plist" | cut -d ':' -f 2 |cut -b 6-)
#e.g:
#/f7.1fac6e08-40a1-473c-a0be-8bbcbb22ddf2/1.0.0/config/ioswebservice1.0.0.plist
#1.0.0/config/ioswebservice1.0.0.plist
if [[ $plist ]]
then
#only unzip the plist file
echo "y" | unzip -q $line $plist -d $WORKSPACE/extracted
flag=$(echo "$plist" |cut -b 1)
if [ $flag == '/' ]
then
plist=$(echo "$plist" |cut -b 1-)
fi
#replace text and save it back right away.
sed -i "s/$DOMAIN_OLD/$DOMAIN_NEW/g" "$WORKSPACE/extracted/$plist"
#zip it back
zip -qu $line $plist
echo "done with:[$line]"
fi
done < $WORKSPACE/plist_nas.txt
export RSYNC_PASSWORD=""
echo "mission completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment