gitbarrerepos.sh 2.6 KB

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