Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Commit

Permalink
run example shell script file
Browse files Browse the repository at this point in the history
  • Loading branch information
nonylene committed Apr 26, 2016
1 parent ed84e23 commit affec4c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

cd `dirname $0`

## set remote server ip address or alias name
server=""

set -e

while getopts a?t:m:p: OPT; do
case $OPT in
a) arguments=$OPTARG
;;
t) tasks=$OPTARG
;;
m) module_dir=$OPTARG
;;
p) project_dir=$OPTARG
;;
esac
done

# unescape
gradle_args=`echo $arguments | perl -pe "s/(?<!\\\\\\),/ /g; s/\,/,/g"`
gradle_tasks=`echo $tasks | perl -pe "s/(?<!\\\\\\),//g; s/\,/,/g"`

echo "Tasks: $gradle_tasks"
echo "Args: $gradle_args"
echo "Project Dir: $project_dir"
echo "Module Dir: $module_dir"

project_relative=`realpath --relative-to=$HOME $project_dir`
module_relative=`realpath --relative-to=$HOME $module_dir`

ctl_path="$HOME/.ssh/ctl/%L-%r@%h:%p"
rsync_ssh="ssh -S $ctl_path"
mkdir -p ~/.ssh/ctl/

# create session with Control Master
echo "Opening session..."
ssh -fNM -S "$ctl_path" "$server"

# sync source files
echo "Syncing source files..."
ssh -S "$ctl_path" "$server" mkdir -p "~/$project_relative"
rsync -Cavz --delete --filter=":- .gitignore" -e "$rsync_ssh" $project_dir/ "$server":$project_relative/

echo "Starting Build..."
ssh -S $ctl_path "$server" "
export ANDROID_HOME=~/android-sdk-linux
cd ~/$project_relative
./gradlew $gradle_tasks $gradle_args"

echo "Syncing output files..."
rsync -CavzS --delete -e "$rsync_ssh" --exclude='*unaligned.apk' "$server":$project_relative/build/ $project_dir/build/
rsync -CavzS --delete -e "$rsync_ssh" --exclude='*unaligned.apk' "$server":$module_relative/build/ $module_dir/build/

# close session with Control Master
echo "Closing session..."
ssh -O exit -S "$ctl_path" "$server"

echo "Remote build and sync finished."

exit 0

0 comments on commit affec4c

Please sign in to comment.