gitbarrerepos.sh 2.2 KB

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