gitbarrerepos.sh 3.8 KB

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