deliver.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. cd $tmp_repo
  65. rm -rf .git
  66. git init
  67. echo "What's the repository URL?"
  68. read repo_url
  69. git remote add origin $repo_url
  70. git add .
  71. git commit -m "21sh delivery"
  72. }
  73. ready() {
  74. norminette **/**.[ch]
  75. make run
  76. question "Publish?"
  77. git push -u origin master
  78. }
  79. git checkout -B deliver
  80. add_42_headers
  81. clean_repository
  82. prepare_git_repository
  83. ready