summaryrefslogtreecommitdiff
path: root/localvcshinit
blob: 9f9da81e5ee2eba97ece4b9ceef2b0e0b75dfce7 (plain)
  1. #!/bin/sh
  2. # Copyright © 2014-2015 Jonas Smedegaard <dr@jones.dk>
  3. # Description: initialize vcsh local + remote git repository
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Depends: vcsh git
  19. set -eu
  20. skel_url=https://github.com/RichiH/vcsh_mr_template
  21. PRG=$(basename "$0")
  22. showhelp() {
  23. cat <<EOF
  24. Usage: $PRG REPO BASE_URL
  25. Examples:
  26. $PRG project git+ssh://source.example.org/srv/git/project
  27. EOF
  28. }
  29. exit1() {
  30. response="${1:+Error: }${1:-Internal error!}"
  31. echo >&2 "$response"
  32. exit 1
  33. }
  34. repo=${1:-mr}
  35. base_url="$2"
  36. url="$base_url/$repo"
  37. if [ $# -ne 2 ]; then
  38. showhelp
  39. exit1 "wrong parameters"
  40. fi
  41. if ! vcsh list | grep -Fxq "$repo"; then
  42. if [ vcsh = "$repo" ]; then
  43. url="$base_url"
  44. vcsh clone $skel_url mr
  45. vcsh "$repo" remote set-url origin "$url"
  46. else
  47. vcsh init "$repo"
  48. vcsh "$repo" remote add origin "$url"
  49. fi
  50. fi
  51. host=$(echo "$url" | sed -e 's/:.*//')
  52. path=$(echo "$url" | sed -e 's/.*://')
  53. if ssh "$host" test -d "$path.git"; then
  54. echo "Skipping vcsh remote \"$repo\" already pushed"
  55. else
  56. ssh "$host" mkdir -p "$(dirname "$path")"
  57. ssh "$host" git init --bare "$path.git"
  58. vcsh "$repo" push --set-upstream origin master
  59. fi
  60. printf 'Done (press return)'
  61. read foo