freedombone-utils-go 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Go 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. GO_VERSION=1.5
  31. GO_PACKAGE_MANAGER_REPO="https://github.com/gpmgo/gopm"
  32. GVM_HOME=/home/git/gvm
  33. GVM_REPO="https://github.com/moovweb/gvm"
  34. GVM_COMMIT='25ea8ae158e2861c92e2b22c458e60840157832f'
  35. function select_go_version {
  36. if [ ! -d $GVM_HOME/bin ]; then
  37. echo $'GVM was not installed'
  38. exit 629532
  39. fi
  40. export GVM_ROOT=$GVM_HOME
  41. if ! grep -q "GVM_ROOT=" ~/.bashrc; then
  42. echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc
  43. else
  44. sed -i "s|export GVM_ROOT=.*|export GVM_ROOT=$GVM_ROOT|g" ~/.bashrc
  45. fi
  46. cd $GVM_ROOT/bin
  47. [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
  48. gvm use go${GO_VERSION} --default
  49. systemctl set-environment GOPATH=$GOPATH
  50. if [ ${#GOPATH} -lt 2 ]; then
  51. echo $'GOPATH was not set'
  52. exit 629825
  53. fi
  54. }
  55. function upgrade_golang {
  56. if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
  57. return
  58. fi
  59. # NOTE: this is annoyingly hacky and going in the opposite
  60. # direction of a pure blend, but it's necessary if you want
  61. # to run the latest version of gogs
  62. # update to the next commit
  63. function_check set_repo_commit
  64. set_repo_commit $INSTALL_DIR/gvm "gvm commit" "$GVM_COMMIT" $GVM_REPO
  65. if grep -Fxq "upgrade_golang" $COMPLETION_FILE; then
  66. return
  67. fi
  68. export GVM_ROOT=$GVM_HOME
  69. apt-get -y install curl git mercurial make binutils bison gcc build-essential
  70. if [ ! -d $INSTALL_DIR ]; then
  71. mkdir $INSTALL_DIR
  72. fi
  73. cd $INSTALL_DIR
  74. function_check git_clone
  75. git_clone $GVM_REPO gvm
  76. cd $INSTALL_DIR/gvm
  77. git checkout $GVM_COMMIT -b $GVM_COMMIT
  78. if [ ! -f binscripts/gvm-installer ]; then
  79. echo $'gvm installer not found'
  80. fi
  81. chmod +x binscripts/gvm-installer
  82. if [ -d /root/.gvm ]; then
  83. rm -rf /root/.gvm
  84. fi
  85. if [ -d $GVM_ROOT ]; then
  86. rm -rf $GVM_ROOT
  87. fi
  88. sed -i "s|export GVM_ROOT=.*|export GVM_ROOT=$GVM_ROOT|g" ~/.bashrc
  89. if [ ! -d /home/git ]; then
  90. # add a gogs user account within which the gvm home directory will exist
  91. adduser --disabled-login --gecos 'Gogs' git
  92. fi
  93. if [ -d /home/git/Maildir ]; then
  94. rm -rf /home/git/Maildir
  95. fi
  96. # TODO: this script is all over the place
  97. # and contains hardcoded github. See if you can do better
  98. ./binscripts/gvm-installer master /home/git
  99. if [ ! -d $GVM_ROOT ]; then
  100. echo $'Unable to install gvm'
  101. exit 83537
  102. fi
  103. [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
  104. if [ ! -f $GVM_ROOT/bin/gvm ]; then
  105. echo $'gvm was not installed'
  106. fi
  107. if ! grep -q "export GVM_ROOT=" ~/.bashrc; then
  108. echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc
  109. fi
  110. cd $GVM_ROOT/bin
  111. gvm install go1.4
  112. gvm use go1.4
  113. export GOROOT_BOOTSTRAP=$GOROOT
  114. gvm install go${GO_VERSION}
  115. if [ ! "$?" = "0" ]; then
  116. echo $'Unable to upgrade golang'
  117. exit 529252
  118. fi
  119. gvm use go${GO_VERSION} --default
  120. chown -R git:git $GVM_HOME
  121. if ! grep -q "gvm commit" $COMPLETION_FILE; then
  122. echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE
  123. else
  124. sed -i "s/gvm commit.*/gvm commit:$GVM_COMMIT/g" $COMPLETION_FILE
  125. fi
  126. echo 'upgrade_golang' >> $COMPLETION_FILE
  127. }
  128. # NOTE: deliberately there is no "exit 0"