Set of scripts used for various projects.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

89 rindas
2.6 KiB

  1. #!/bin/sh -
  2. set -e
  3. set -x
  4. # using ssh-agent to make this quicker:
  5. # eval $(ssh-agent)
  6. # ssh-add
  7. # Token file must contain:
  8. # Authorization: token <token>
  9. # where <token> is generated from: Settings -> Applications, or:
  10. # <basegiteaurl>/user/settings/applications
  11. tokenfile="$PWD/.gitea.token"
  12. # domain used to detect if it's a repo that we can update
  13. gitdomain=funkthat.com
  14. # the gitea API url
  15. giteabaseurl="https://www.funkthat.com/gitea/api/v1"
  16. echo "start"
  17. # Command to list all the repos that have master as it's default branch.
  18. #curl -s -X GET "https://www.funkthat.com/gitea/api/v1/users/jmg/repos" -H "accept: application/json" | jq -r '(.[]) | select(.default_branch == "master") | .name'
  19. if ! [ -x $(which jq) ]; then
  20. echo 'Error: jq needs to be installed'
  21. exit 1
  22. fi
  23. # -H @"$tokenfile"
  24. # Set the default branch:
  25. # curl -v -i -d "$(jq -n '{ default_branch: "main" }')" -X PATCH "https://www.funkthat.com/gitea/api/v1/repos/jmg/projects" -H "Content-Type: application/json" -H "accept: application/json" -H @"$tokenfile"
  26. #curl -s -X GET "https://www.funkthat.com/gitea/api/v1/repos/jmg/ggate" -H "accept: application/json" | jq '.default_branch'
  27. #echo 'list'
  28. # make sure we are in a correct repo
  29. cd /Users/jmg/git/fbsdembdev
  30. r=$(git remote -v | grep git.funkthat.com 2>&1)
  31. if [ x"$r" = x"" ]; then
  32. echo 'not a gitea repo'
  33. exit 1
  34. fi
  35. # get the remote that we need to update
  36. gitremote=$(echo "$r" | awk '{ print $1; exit 0 }')
  37. # get the gitea user/project, this currently assumes that whatever
  38. # the url is, it ends with <username>/<reponame>.git
  39. giteauserproj=$(echo "$r" | awk '{ url=$2; cnt = split(url, surl, "/"); proj = split(surl[cnt], sproj, "."); printf("%s/%s", surl[cnt - 1], sproj[1]); exit 0; }')
  40. # see if there's a master branch
  41. r=$(git branch | grep master || true)
  42. if [ x"$r" = x"" ]; then
  43. echo 'no master branch'
  44. exit 1
  45. fi
  46. # Check if we are on that branch
  47. onotherbranch=1
  48. if [ x"${r#\* }" != x"$r" ]; then
  49. onotherbranch=0
  50. git checkout $(git log | head -n 1 | awk '{print $2}') >/dev/null 2>&1
  51. fi
  52. # rename the branch
  53. git branch -m master main
  54. # change upstream
  55. upmerge=$(git config branch.main.merge)
  56. if [ x"${upmerge%master}" != x"$upmerge" ]; then
  57. git config branch.main.merge refs/heads/main
  58. fi
  59. # push new main branch
  60. git push origin main
  61. # update gitea
  62. curl -v -i -d "$(jq -n '{ default_branch: "main" }')" -X PATCH "${giteabaseurl}/repos/${giteauserproj}" -H "Content-Type: application/json" -H "accept: application/json" -H @"$tokenfile"
  63. # delete old branch on server
  64. git push -d origin master
  65. # restore our checkout
  66. if [ x"$onotherbranch" = x"0" ]; then
  67. git checkout main
  68. fi