gitbarrerepos.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. while [ "$_bare_name" = "" ]
  14. do
  15. read -p "enter the bare repos folder name ? " _bare_name
  16. if [ "$_bare_name" != "" ]; then
  17. read -p "is bare folder name $_bare_name correcte [y|n] " validated
  18. if [ "$validated" = "y" ]; then
  19. break
  20. else
  21. _bare_name=""
  22. fi
  23. fi
  24. done
  25. while [ "$_prod_folder_path" = "" ]
  26. do
  27. read -p "enter the prod folder path (must be a public_html parent's) ? " _prod_folder_path
  28. if [ "$_prod_folder_path" != "" ]; then
  29. # TODO check if path exists
  30. read -p "is prod folder path $_prod_folder_path correcte [y|n] " validated
  31. if [ "$validated" = "y" ]; then
  32. break
  33. else
  34. _prod_folder_path=""
  35. fi
  36. fi
  37. done
  38. # ask for simple php conf or drupal conf
  39. while [ "$_drupal" != "yes" ] && [ "$_drupal" != "no" ]
  40. do
  41. echo -n "Is your site is a drupal one? [yes|no] "
  42. read _drupal
  43. done
  44. # setup bare repositorie to push to
  45. mkdir ~/git-repositories
  46. mkdir ~/git-repositories/"$_bare_name".git
  47. cd ~/git-repositories/"$_bare_name".git
  48. git init --bare
  49. # add deploy script
  50. if [ "$_drupal" = "yes" ]; then
  51. cp "$_cwd"/assets/deploy-drupal.sh "$_prod_folder_path"/deploy.sh
  52. else
  53. cp "$_cwd"/assets/deploy-simple.sh "$_prod_folder_path"/deploy.sh
  54. fi
  55. # setup git repo on site folder
  56. cd "$_prod_folder_path"
  57. git init
  58. # link to the bare repo
  59. git remote add origin /home/"$USER"/git-repositories/"$_bare_name".git
  60. # create hooks that will update the site repo
  61. cd ~
  62. cp "$_cwd"/assets/git-pre-receive /home/"$USER"/git-repositories/"$_bare_name".git/hooks/pre-receive
  63. cp "$_cwd"/assets/git-post-receive /home/"$USER"/git-repositories/"$_bare_name".git/hooks/post-receive
  64. sed -ir "s/PRODDIR=\"www\"/PRODDIR=$_prod_folder_path/g" /home/"$USER"/git-repositories/"$_bare_name".git/hooks/pre-receive
  65. sed -ir "s/PRODDIR=\"www\"/PRODDIR=$_prod_folder_path/g" /home/"$USER"/git-repositories/"$_bare_name".git/hooks/post-receive
  66. cd /home/"$USER"/git-repositories/"$_bare_name".git/hooks/
  67. chmod +x post-receive pre-receive
  68. # done
  69. echo "git repos for $_bare_name install succeed"
  70. echo "your site stay now to $_prod_folder_path"
  71. echo "you can push updates on prod branch through $USER@IP.IP.IP.IP:git-repositories/$_bare_name.git"
  72. echo "* * *"