freedombone-upgrade 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Command to upgrade the system
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. PROJECT_DIR="/root/${PROJECT_NAME}"
  31. # An optional configuration file which overrides some of these variables
  32. CONFIGURATION_FILE="/root/${PROJECT_NAME}.cfg"
  33. PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
  34. FRIENDS_MIRRORS_SERVER=
  35. FRIENDS_MIRRORS_SSH_PORT=2222
  36. FRIENDS_MIRRORS_PASSWORD=
  37. MY_MIRRORS_PASSWORD=
  38. source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-git
  39. function read_repo_servers {
  40. if [ -f $CONFIGURATION_FILE ]; then
  41. if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
  42. FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  43. fi
  44. if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
  45. FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  46. fi
  47. if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  48. MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  49. fi
  50. if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  51. FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  52. fi
  53. fi
  54. if [ ! $FRIENDS_MIRRORS_SERVER ]; then
  55. return
  56. fi
  57. if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
  58. return
  59. fi
  60. MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
  61. if [ ! -f $MAIN_COMMAND ]; then
  62. MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
  63. fi
  64. REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
  65. for line in "${REPOS[@]}"
  66. do
  67. repo_name=$(echo "$line" | awk -F '=' '{print $1}')
  68. mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
  69. friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
  70. ${repo_name}="${friends_repo_url}"
  71. done
  72. }
  73. if [ -f $CONFIGURATION_FILE ]; then
  74. # read the location of the main project repo
  75. if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then
  76. PROJECT_REPO=$(grep "PROJECT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  77. fi
  78. fi
  79. update-ca-certificates
  80. read_repo_servers
  81. ${PROJECT_NAME}-mirrors
  82. if [ ! -d $PROJECT_DIR ]; then
  83. git_clone $PROJECT_REPO $PROJECT_DIR
  84. fi
  85. if [ -d $PROJECT_DIR ]; then
  86. if [ -f $CONFIGURATION_FILE ]; then
  87. cd $PROJECT_DIR
  88. rm -rf $PROJECT_DIR/locale/*
  89. git_pull $PROJECT_REPO
  90. make install
  91. ${PROJECT_NAME} -c $CONFIGURATION_FILE
  92. fi
  93. fi
  94. # remove the original sipwitch daemon if it exists
  95. if [ -f /etc/init.d/sipwitch ]; then
  96. rm -f /etc/init.d/sipwitch
  97. fi
  98. # update blog avatar
  99. ${PROJECT_NAME}-blog
  100. if [ -f /usr/bin/reset-tripwire ]; then
  101. echo '
  102. ' | reset-tripwire
  103. fi
  104. # deliberately there is no 'exit 0' here