get-repository.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. #
  3. # Licence: this file is in the public domain.
  4. #
  5. # Download and configure the repositories of the website or wiki.
  6. repository=$1
  7. github_remote=$2
  8. #
  9. # TODO
  10. #
  11. final_note () {
  12. cat <<EOF
  13. Now, you can fork the repository into Github from $2
  14. and add a reference to it in your local copy:
  15. <fork at Github>
  16. $ cd ./$1
  17. $ git remote add myfork https://github.com/<username>/.git
  18. EOF
  19. }
  20. setup () {
  21. target_dir=$1
  22. remote_url=$2
  23. # Adjust $PWD if necessary.
  24. test -d scripts || cd ..
  25. if test ! -d scripts
  26. then
  27. echo "cannot figure the correct workdir..."
  28. exit 2
  29. fi
  30. if test -d $target_dir
  31. then
  32. echo "Directory '$target_dir' already exists..."
  33. exit 3
  34. fi
  35. git clone "${remote_url}.git" "$1"
  36. echo ''
  37. if test $? -gt 0
  38. then
  39. echo "Cannot fork $remote_url to $1"
  40. exit 4
  41. fi
  42. }
  43. configure_website () {
  44. renderer='./render.sh'
  45. echo "Found Github username: '$1'"
  46. echo "If it's wrong, please fix the script ./website/render.sh"
  47. cd ./website
  48. if test $? -eq 0
  49. then
  50. sed -r -i -e "s,{{USERNAME}},$1," "$renderer"
  51. cd ..
  52. else
  53. echo "ERROR: could not enter ./website. (?)"
  54. fi
  55. }
  56. configure_wiki () {
  57. : # noop
  58. }
  59. test n$github_remote = 'n' && github_remote='origin'
  60. # Get Github username.
  61. #offlineimap_url="$(git config --local --get remote.origin.url)"
  62. offlineimap_url="$(git config --local --get remote.nicolas33.url)"
  63. username=$(echo $offlineimap_url | sed -r -e 's,.*github.com.([^/]+)/.*,\1,')
  64. case n$repository in
  65. nwebsite)
  66. upstream=https://github.com/OfflineIMAP/offlineimap.github.io
  67. setup website "$upstream"
  68. configure_website "$username"
  69. final_note website "$upstream"
  70. ;;
  71. nwiki)
  72. upstream=https://github.com/OfflineIMAP/offlineimap.wiki
  73. setup wiki "$upstream"
  74. configure_wiki
  75. final_note wiki "$upstream"
  76. ;;
  77. *)
  78. cat <<EOF
  79. Usage: ./get-repository.sh {website|wiki} [origin|<repository>]
  80. <repository>: The name of the Git repository of YOUR fork at Github.
  81. Default: origin
  82. EOF
  83. exit 1
  84. ;;
  85. esac