Created
August 24, 2012 11:15
-
-
Save kensei/3449277 to your computer and use it in GitHub Desktop.
git-scp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# remove trailing slashes | |
targetdir=$(echo $PWD | sed 's/\/*$//g') | |
# get list of all changed files | |
changes=$(git status --porcelain 2>&1) | |
# exit if git status returned an error code | |
if [ $? -ne 0 ] | |
then | |
echo | |
echo " $changes" | |
echo | |
exit 1 | |
fi | |
# file length counters | |
maxfilelength=0 | |
filelength=0 | |
# extract added and modified files | |
files_modified=$(echo "$changes" | awk '{if($1~"A|M") print $2}') | |
if [ "$files_modified" == "" ] | |
then | |
echo | |
echo "Nothing to sync" | |
echo | |
exit 0 | |
fi | |
echo "-- modified files --" | |
for file in $files_modified; | |
do | |
echo "$file" | |
done | |
echo | |
# selected server | |
echo "-- What server do you deploy? --" | |
ans1="test@dev.klab.net:var/www/tst" | |
ans1="test@dev.klab.net:var/www/dev" | |
ans1="test@klab.net:var/www/target" | |
select ANS in "$ans1" "$ans2" "$ans3" | |
do | |
if [ -z "$ANS" ]; then | |
continue | |
else | |
break | |
fi | |
done | |
echo | |
serverno=$REPLY | |
servername=$ANS | |
# dry run | |
for file in $files_modified; | |
do | |
cmd="scp -Cpr $file $servername/$file" | |
echo "$cmd" | |
done | |
echo | |
echo -n 'Do you want to continue (yes/no)?: ' | |
read answer | |
# exit it "yes" or "y" not received | |
if [ "$answer" != "yes" ] && [ "$answer" != "y" ] | |
then | |
echo | |
exit 1 | |
fi | |
echo | |
# copy files | |
for file in $files_modified; | |
do | |
cmd="scp -Cpr $file $servername/$file" | |
echo "$cmd" | |
output=$($cmd 2>&1) | |
if [ $? -eq 0 ] | |
then | |
echo "ok" | |
else | |
echo "failed ($output)" | |
fi | |
echo | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment