freedombone-upgrade 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/local/bin/${PROJECT_NAME}-utils-git
  39. if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
  40. source /usr/bin/${PROJECT_NAME}-utils-git
  41. fi
  42. function read_repo_servers {
  43. if [ -f $CONFIGURATION_FILE ]; then
  44. if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
  45. FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  46. fi
  47. if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
  48. FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  49. fi
  50. if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  51. MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  52. fi
  53. if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  54. FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  55. fi
  56. fi
  57. if [ ! $FRIENDS_MIRRORS_SERVER ]; then
  58. return
  59. fi
  60. if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
  61. return
  62. fi
  63. MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
  64. if [ ! -f $MAIN_COMMAND ]; then
  65. MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
  66. fi
  67. REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
  68. for line in "${REPOS[@]}"
  69. do
  70. repo_name=$(echo "$line" | awk -F '=' '{print $1}')
  71. mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
  72. friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
  73. ${repo_name}="${friends_repo_url}"
  74. done
  75. }
  76. if [ -f $CONFIGURATION_FILE ]; then
  77. # read the location of the main project repo
  78. if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then
  79. PROJECT_REPO=$(grep "PROJECT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  80. fi
  81. fi
  82. update-ca-certificates
  83. read_repo_servers
  84. ${PROJECT_NAME}-mirrors
  85. if [ ! -d $PROJECT_DIR ]; then
  86. git_clone $PROJECT_REPO $PROJECT_DIR
  87. fi
  88. if [ -d $PROJECT_DIR ]; then
  89. if [ -f $CONFIGURATION_FILE ]; then
  90. cd $PROJECT_DIR
  91. rm -rf $PROJECT_DIR/locale/*
  92. git_pull $PROJECT_REPO
  93. make install
  94. ${PROJECT_NAME} -c $CONFIGURATION_FILE
  95. fi
  96. fi
  97. # remove the original sipwitch daemon if it exists
  98. if [ -f /etc/init.d/sipwitch ]; then
  99. rm -f /etc/init.d/sipwitch
  100. fi
  101. # update blog avatar
  102. ${PROJECT_NAME}-blog
  103. if [ -f /usr/bin/reset-tripwire ]; then
  104. echo '
  105. ' | reset-tripwire
  106. fi
  107. # deliberately there is no 'exit 0' here