deliver.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/zsh
  2. makefile_header="# **************************************************************************** #
  3. # #
  4. # ::: :::::::: #
  5. # Makefile :+: :+: :+: #
  6. # +:+ +:+ +:+ #
  7. # By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ #
  8. # +#+#+#+#+#+ +#+ #
  9. # Created: 2017/03/04 15:35:21 by mazimi #+# #+# #
  10. # Updated: 2017/03/04 15:35:21 by mazimi ### ########.fr #
  11. # #
  12. # **************************************************************************** #\n"
  13. c_header="/* ************************************************************************** */
  14. /* */
  15. /* ::: :::::::: */
  16. /* file.c :+: :+: :+: */
  17. /* +:+ +:+ +:+ */
  18. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  19. /* +#+#+#+#+#+ +#+ */
  20. /* Created: 2017/03/04 15:35:21 by mazimi #+# #+# */
  21. /* Updated: 2017/03/04 15:35:21 by mazimi ### ########.fr */
  22. /* */
  23. /* ************************************************************************** */\n"
  24. question() {
  25. echo $1 "[y/n]"
  26. read yes
  27. if [ $yes != "y" ]; then
  28. return
  29. fi
  30. }
  31. add_42_headers() {
  32. for file in "src"/*; do
  33. add_42_header "$file"
  34. done
  35. add_42_header "Makefile"
  36. git status
  37. git diff
  38. git add src Makefile
  39. git commit -m "[mod] add 42 headers on top of files."
  40. }
  41. add_42_header() {
  42. src_file=$1
  43. tmp="/tmp/42_header"
  44. if [ $src_file = "Makefile" ]; then
  45. echo $makefile_header > $tmp
  46. else
  47. echo $c_header > $tmp
  48. fi
  49. cat $src_file >> $tmp
  50. cp $tmp $src_file
  51. }
  52. clean_repository() {
  53. make fclean
  54. git rm -rf --ignore-unmatch doc non_use_src leaks.sh deliver.sh
  55. rm -f toto
  56. question "Did you clean the Makefile?"
  57. git add Makefile
  58. git commit -m "[mod] remove non used elements."
  59. }
  60. prepare_git_repository() {
  61. tmp_repo="/tmp/21sh_delivery"
  62. rm -rf $tmp_repo
  63. cp -r ../21sh $tmp_repo
  64. git checkout master
  65. git branch -D deliver
  66. git stash pop
  67. cd $tmp_repo
  68. rm -rf .git
  69. git init
  70. echo "What's the repository URL?"
  71. read repo_url
  72. git remote add origin $repo_url
  73. git add .
  74. git commit -m "21sh delivery"
  75. }
  76. ready() {
  77. norminette **/**.[ch]
  78. make run
  79. question "Publish?"
  80. git push -u origin master
  81. }
  82. git stash save "Deliver stash"
  83. git checkout -b deliver
  84. add_42_headers
  85. clean_repository
  86. prepare_git_repository
  87. ready