freedombone-utils-git 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Useful git functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. function git_clone {
  31. repo_url="$1"
  32. destination_dir="$2"
  33. if [[ "$repo_url" == "ssh:"* ]]; then
  34. retval=$(get_friends_servers)
  35. if [[ $retval == "0" ]]; then
  36. if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
  37. if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
  38. if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
  39. if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
  40. echo "sshpass -p \"$FRIENDS_MIRRORS_PASSWORD\" git clone $repo_url $destination_dir"
  41. sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git clone "$repo_url" "$destination_dir"
  42. return
  43. fi
  44. fi
  45. fi
  46. fi
  47. fi
  48. fi
  49. echo "git clone $repo_url $destination_dir"
  50. git clone "$repo_url" "$destination_dir"
  51. }
  52. function git_pull {
  53. if [ ! $1 ]; then
  54. echo $'git_pull no repo specified'
  55. fi
  56. git stash
  57. git remote set-url origin $1
  58. git checkout master
  59. retval=$(get_friends_servers)
  60. if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
  61. if [ ${#FRIENDS_MIRRORS_SERVER} -gt 2 ]; then
  62. if [ "$FRIENDS_MIRRORS_PASSWORD" ]; then
  63. if [ ${#FRIENDS_MIRRORS_PASSWORD} -gt 2 ]; then
  64. sshpass -p "$FRIENDS_MIRRORS_PASSWORD" git pull
  65. if [ $2 ]; then
  66. git checkout $2 -b $2
  67. fi
  68. return
  69. fi
  70. fi
  71. fi
  72. fi
  73. git pull
  74. if [ $2 ]; then
  75. # delete any existing branch
  76. git branch -D $2
  77. # check out the new branch
  78. git checkout $2 -b $2
  79. if [ ! "$?" = "0" ]; then
  80. echo $"Unable to checkout $1 $2"
  81. exit 72357
  82. fi
  83. fi
  84. }
  85. # This ensures that a given repo is on a given commit
  86. # If it isn't then it attempts to upgrade
  87. function set_repo_commit {
  88. repo_dir=$1
  89. repo_commit_name=$2
  90. repo_commit=$3
  91. repo_url=$4
  92. if [ -d $repo_dir ]; then
  93. if grep -q "$repo_commit_name" $COMPLETION_FILE; then
  94. CURRENT_REPO_COMMIT=$(grep "$repo_commit_name" $COMPLETION_FILE | awk -F ':' '{print $2}')
  95. if [[ "$CURRENT_REPO_COMMIT" != "$repo_commit" ]]; then
  96. cd $repo_dir
  97. git_pull $repo_url $repo_commit
  98. # application specific stuff after updating the repo
  99. if [[ $repo_dir == *"www"* ]]; then
  100. chown -R www-data:www-data $repo_dir
  101. fi
  102. if [[ $repo_dir == *"cjdns" ]]; then
  103. ./do
  104. fi
  105. if [[ $repo_dir == *"gpgit" ]]; then
  106. cp gpgit.pl /usr/bin/gpgit.pl
  107. fi
  108. if [[ $repo_dir == *"cleanup-maildir" ]]; then
  109. cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
  110. fi
  111. if [[ $repo_dir == *"nginx_ensite" ]]; then
  112. make install
  113. fi
  114. if [[ $repo_dir == *"gogs" ]]; then
  115. git checkout master
  116. go get -u ./...
  117. if [ ! "$?" = "0" ]; then
  118. echo $'Failed to get gogs'
  119. exit 52792
  120. fi
  121. git checkout $repo_commit
  122. go build
  123. if [ ! "$?" = "0" ]; then
  124. echo $'Failed to build gogs'
  125. exit 36226
  126. fi
  127. systemctl restart gogs
  128. fi
  129. if [[ $repo_dir == *"toxcore" ]]; then
  130. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  131. autoreconf -i
  132. ./configure --enable-daemon
  133. make
  134. make install
  135. systemctl daemon-reload
  136. systemctl restart tox-bootstrapd.service
  137. fi
  138. if [[ $repo_dir == *"toxic" ]]; then
  139. make
  140. make install
  141. fi
  142. if [[ $repo_dir == $RSS_READER_PATH ]]; then
  143. function_check rss_reader_modifications
  144. rss_reader_modifications
  145. fi
  146. if [[ $repo_dir == *"inadyn" ]]; then
  147. ./configure
  148. USE_OPENSSL=1 make
  149. make install
  150. systemctl restart inadyn
  151. fi
  152. if [[ $repo_dir == *"ipfs" ]]; then
  153. chown -R git:git /home/git
  154. systemctl restart ipfs
  155. systemctl daemon-reload
  156. fi
  157. sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE
  158. fi
  159. else
  160. echo "${repo_commit_name}:${repo_commit}" >> $COMPLETION_FILE
  161. fi
  162. fi
  163. }
  164. # NOTE: deliberately no exit 0