Guest User

Untitled

a guest
Dec 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # remove trailing slashes
  4. targetdir=$(echo $PWD | sed 's/\/*$//g')
  5.  
  6. # get list of all changed files
  7. changes=$(git status --porcelain 2>&1)
  8.  
  9. # exit if git status returned an error code
  10. if [ $? -ne 0 ]
  11. then
  12. echo
  13. echo " $changes"
  14. echo
  15. exit 1
  16. fi
  17.  
  18. # file length counters
  19. maxfilelength=0
  20. filelength=0
  21.  
  22. # extract added and modified files
  23. files_modified=$(echo "$changes" | awk '{if($1~"A|M") print $2}')
  24. if [ "$files_modified" == "" ]
  25. then
  26. echo
  27. echo "Nothing to sync"
  28. echo
  29. exit 0
  30. fi
  31. echo "-- modified files --"
  32. for file in $files_modified;
  33. do
  34. echo "$file"
  35. done
  36. echo
  37.  
  38. # selected server
  39. echo "-- What server do you deploy? --"
  40. ans1="test@dev.klab.net:var/www/tst"
  41. ans1="test@dev.klab.net:var/www/dev"
  42. ans1="test@klab.net:var/www/target"
  43.  
  44. select ANS in "$ans1" "$ans2" "$ans3"
  45. do
  46. if [ -z "$ANS" ]; then
  47. continue
  48. else
  49. break
  50. fi
  51. done
  52. echo
  53.  
  54. serverno=$REPLY
  55. servername=$ANS
  56.  
  57. # dry run
  58. for file in $files_modified;
  59. do
  60. cmd="scp -Cpr $file $servername/$file"
  61. echo "$cmd"
  62. done
  63.  
  64. echo
  65. echo -n 'Do you want to continue (yes/no)?: '
  66. read answer
  67.  
  68. # exit it "yes" or "y" not received
  69. if [ "$answer" != "yes" ] && [ "$answer" != "y" ]
  70. then
  71. echo
  72. exit 1
  73. fi
  74.  
  75. echo
  76.  
  77. # copy files
  78. for file in $files_modified;
  79. do
  80. cmd="scp -Cpr $file $servername/$file"
  81. echo "$cmd"
  82. output=$($cmd 2>&1)
  83.  
  84. if [ $? -eq 0 ]
  85. then
  86. echo "ok"
  87. else
  88. echo "failed ($output)"
  89. fi
  90. echo
  91. done
  92.  
  93. echo
Add Comment
Please, Sign In to add comment