freedombone-utils-git 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 == *"tlsdate" ]]; then
  106. cd $INSTALL_DIR/tlsdate
  107. make clean
  108. ./configure
  109. if [ ! "$?" = "0" ]; then
  110. echo $'Failed to configure tlsdate'
  111. exit 727824
  112. fi
  113. make
  114. if [ ! "$?" = "0" ]; then
  115. echo $'Failed to build tlsdate'
  116. exit 728752
  117. fi
  118. make install
  119. fi
  120. if [[ $repo_dir == *"gpgit" ]]; then
  121. cp gpgit.pl /usr/bin/gpgit.pl
  122. fi
  123. if [[ $repo_dir == *"cleanup-maildir" ]]; then
  124. cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
  125. fi
  126. if [[ $repo_dir == *"nginx_ensite" ]]; then
  127. make install
  128. fi
  129. if [[ $repo_dir == *"gogs" ]]; then
  130. git checkout master
  131. go get -u ./...
  132. if [ ! "$?" = "0" ]; then
  133. echo $'Failed to get gogs'
  134. exit 52792
  135. fi
  136. git checkout $repo_commit
  137. go build
  138. if [ ! "$?" = "0" ]; then
  139. echo $'Failed to build gogs'
  140. exit 36226
  141. fi
  142. systemctl restart gogs
  143. fi
  144. if [[ $repo_dir == *"toxcore" ]]; then
  145. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  146. autoreconf -i
  147. ./configure --enable-daemon
  148. make
  149. make install
  150. systemctl daemon-reload
  151. systemctl restart tox-bootstrapd.service
  152. fi
  153. if [[ $repo_dir == *"toxic" ]]; then
  154. make
  155. make install
  156. fi
  157. if [[ $repo_dir == $RSS_READER_PATH ]]; then
  158. function_check rss_reader_modifications
  159. rss_reader_modifications
  160. fi
  161. if [[ $repo_dir == *"inadyn" ]]; then
  162. ./configure
  163. USE_OPENSSL=1 make
  164. make install
  165. systemctl restart inadyn
  166. fi
  167. if [[ $repo_dir == *"ipfs" ]]; then
  168. chown -R git:git /home/git
  169. systemctl restart ipfs
  170. systemctl daemon-reload
  171. fi
  172. sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE
  173. fi
  174. else
  175. echo "${repo_commit_name}:${repo_commit}" >> $COMPLETION_FILE
  176. fi
  177. fi
  178. }
  179. # NOTE: deliberately no exit 0