gitbarrerepos.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # bachir soussi chiadmi
  3. # get the current position
  4. _cwd="$(pwd)"
  5. while [ "$_bare_name" = "" ]
  6. do
  7. read -p "enter the bare repos folder name ? " _host_name
  8. if [ "$_bare_name" != "" ]; then
  9. read -p "is bare folder name $_bare_name correcte [y|n] " validated
  10. if [ "$validated" = "y" ]; then
  11. break
  12. else
  13. _bare_name=""
  14. fi
  15. fi
  16. done
  17. while [ "$_prod_folder_path" = "" ]
  18. do
  19. read -p "enter the prod folder path folder name ? " _host_name
  20. if [ "$_bare_name" != "" ]; then
  21. read -p "is prod folder path $_prod_folder_path correcte [y|n] " validated
  22. if [ "$validated" = "y" ]; then
  23. break
  24. else
  25. _prod_folder_path=""
  26. fi
  27. fi
  28. done
  29. # setup bare repositorie to push to
  30. mkdir ~/git-repositories
  31. mkdir ~/git-repositories/"$_bare_name".git
  32. cd ~/git-repositories/"$_bare_name".git
  33. git init --bare
  34. # setup git repo on site folder
  35. cd "$_prod_folder_path"
  36. git init
  37. # link to the bare repo
  38. git remote add origin /home/"$USER"/git-repositories/"$_bare_name".git
  39. # create hooks that will update the site repo
  40. cd ~
  41. cp "$_cwd"/assets/git-pre-receive /home/"$USER"/git-repositories/"$_bare_name".git/hooks/pre-receive
  42. cp "$_cwd"/assets/git-post-receive /home/"$USER"/git-repositories/"$_bare_name".git/hooks/post-receive
  43. sed -ir "s/PRODDIR=\"www\"/PRODDIR=\/srv\/www\/$_bare_name\/public_html/g" /home/"$USER"/git-repositories/"$_bare_name".git/hooks/pre-receive
  44. sed -ir "s/PRODDIR=\"www\"/PRODDIR=\/srv\/www\/$_bare_name\/public_html/g" /home/"$USER"/git-repositories/"$_bare_name".git/hooks/post-receive
  45. cd /home/"$USER"/git-repositories/"$_bare_name".git/hooks/
  46. chmod +x post-receive pre-receive
  47. # done
  48. echo "git repos for $_bare_name install succeed"
  49. echo "your site stay now to /home/$USER/www/$_bare_name"
  50. echo "you can push updates on prod branch through $USER@IP.IP.IP.IP:git-repositories/$_bare_name.git"
  51. echo "* * *"