gitdeploy.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. # bachir soussi chiadmi
  3. # get the current position
  4. _cwd="$(pwd)"
  5. echo -e '
  6. _ _
  7. __ _(_) |_
  8. / _` | | _|
  9. \__, |_|\__|
  10. |___/
  11. '
  12. echo -e "Create new git barre repos and deploy script"
  13. echo "Git barre repo will be installed in chosen user home directory"
  14. echo "git prod repos will be installed in app directory of provided domain, the domain have to exists as shortcut in chosen /home/user/www before running this script. Please run first bin/vhost.sh script and say yes to the question create a shortcut !"
  15. . bin/checkroot.sh
  16. while [ "$yn" != "yes" ] && [ "$yn" != "no" ]
  17. do
  18. echo -n "Should we installl git deployement? [yes|no] "
  19. read yn
  20. # yn=${yn:-y}
  21. done
  22. if [ "$yn" = "yes" ]; then
  23. # get the current position
  24. _cwd="$(pwd)"
  25. # check for assets forlder
  26. _assets="$_cwd/assets"
  27. if [ ! -d "$_assets" ]; then
  28. _assets="$_cwd/../assets"
  29. if [ ! -d "$_assets" ]; then
  30. echo "!! can't find assets directory !!"
  31. exit
  32. fi
  33. fi
  34. # if $user var does not exists (gitdeploy.sh ran directly) ask for it
  35. if [ -z ${user+x} ]; then
  36. while [ "$user" = "" ]
  37. do
  38. read -p "enter an existing user name ? " user
  39. if [ "$user" != "" ]; then
  40. # check if user already exists
  41. if id "$user" >/dev/null 2>&1; then
  42. read -p "is user name $user correcte [y|n] " validated
  43. if [ "$validated" = "y" ]; then
  44. break
  45. else
  46. user=""
  47. fi
  48. else
  49. echo -e "user $user doesn't exists, you must provide an existing user"
  50. user=""
  51. fi
  52. fi
  53. done
  54. fi
  55. # if $_domain var does not exists (gitdeploy.sh ran directly) ask for it
  56. if [ -z ${_domain+x} ]; then
  57. while [ "$_domain" = "" ]
  58. do
  59. read -p "enter a domain name ? " _domain
  60. if [ "$_domain" != "" ]; then
  61. if [ ! -d /home/"$user"/www/"$_domain" ]; then
  62. echo "/home/$user/www/$_domain does not exists !"
  63. # exit
  64. _domain=""
  65. else
  66. read -p "is domain $_domain correcte [y|n] " validated
  67. if [ "$validated" = "y" ]; then
  68. break
  69. else
  70. _domain=""
  71. fi
  72. fi
  73. fi
  74. done
  75. fi
  76. # ask for simple php conf or drupal conf
  77. while [ "$_drupal" != "yes" ] && [ "$_drupal" != "no" ]
  78. do
  79. echo -n "Is your site is a drupal 8 instance? [yes|no] "
  80. read _drupal
  81. done
  82. # setup bare repositorie to push to
  83. mkdir /home/"$user"/git-repos
  84. mkdir /home/"$user"/git-repos/"$_domain".git
  85. cd /home/"$user"/git-repos/"$_domain".git
  86. git init --bare
  87. echo "adding deploy script"
  88. if [ "$_drupal" = "yes" ]; then
  89. cp "$_assets"/gitdeploy/deploy-drupal.sh /home/"$user"/www/"$_domain"/deploy.sh
  90. else
  91. cp "$_assets"/gitdeploy/deploy-simple.sh /home/"$user"/www/"$_domain"/deploy.sh
  92. fi
  93. echo "creating hooks that will update the site repo"
  94. cp "$_assets"/gitdeploy/git-post-receive /home/"$user"/git-repos/"$_domain".git/hooks/post-receive
  95. sed -i -r "s#PRODDIR=\"www\"#PRODDIR=\"/home/$user/www/$_domain\"#g" /home/"$user"/git-repos/"$_domain".git/hooks/post-receive
  96. chown -R "$user":"$user" /home/"$user"/git-repos
  97. chmod +x /home/"$user"/git-repos/"$_domain".git/hooks/post-receive
  98. # setup git repo on site folder
  99. cd /home/"$user"/www/"$_domain"/app
  100. rm ./*
  101. git init
  102. # link to the bare repo
  103. git remote add origin /home/"$user"/git-repos/"$_domain".git
  104. chown -R www:"$user" /home/"$user"/www/"$_domain"/app
  105. chmod -R g+rw /home/"$user"/www/"$_domain"/app
  106. _cur_ip=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
  107. cd "$_cwd"
  108. # done
  109. echo "git repos for $_domain install succeed"
  110. echo "your site stay now to /home/$user/www/$_domain/app"
  111. echo "you can push updates on prod branch through $user@$_cur_ip:git-repositories/$_domain.git"
  112. echo "* * *"
  113. else
  114. echo "Git barre repo creation aborted"
  115. fi