freedombone-addremove 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Add or remove apps
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-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. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-addremove
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. PROJECT_INSTALL_DIR=/usr/local/bin
  34. if [ -f /usr/bin/${PROJECT_NAME} ]; then
  35. PROJECT_INSTALL_DIR=/usr/bin
  36. fi
  37. source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
  38. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  39. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  40. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  41. for f in $UTILS_FILES
  42. do
  43. source $f
  44. done
  45. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  46. for f in $APP_FILES
  47. do
  48. source $f
  49. done
  50. function show_apps {
  51. applist=""
  52. n=1
  53. app_index=0
  54. for a in "${APPS_AVAILABLE[@]}"
  55. do
  56. if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
  57. applist="$applist $n $a off"
  58. else
  59. applist="$applist $n $a on"
  60. fi
  61. n=$[n+1]
  62. app_index=$[app_index+1]
  63. done
  64. choices=$(dialog --stdout --backtitle $"Freedombone" \
  65. --title $"Add/Remove Applications" \
  66. --checklist $'Choose:' \
  67. 27 40 20 $applist)
  68. if [ $? -eq 0 ]; then
  69. for choice in $choices
  70. do
  71. app_index=$[choice-1]
  72. APPS_CHOSEN[$app_index]="1"
  73. done
  74. else
  75. exit 0
  76. fi
  77. }
  78. function remove_apps_interactive {
  79. # which apps need to be removed?
  80. removals=""
  81. app_index=0
  82. n=0
  83. for a in "${APPS_INSTALLED[@]}"
  84. do
  85. if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
  86. if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
  87. if [ ${n} -gt 0 ]; then
  88. removals="$removals ${APPS_AVAILABLE[$app_index]}"
  89. else
  90. removals="${APPS_AVAILABLE[$app_index]}"
  91. fi
  92. n=$[n+1]
  93. fi
  94. fi
  95. app_index=$[app_index+1]
  96. done
  97. # if no apps to be removed then don't do anything
  98. if [ ${n} -eq 0 ]; then
  99. return
  100. fi
  101. # ask for confirmation
  102. dialog --title $"Remove applications" \
  103. --backtitle $"Freedombone" \
  104. --defaultno \
  105. --yesno $"\nYou have chosen to remove $n apps.\n\n $removals\n\nIf you choose 'yes' then this will remove both the applications and their data/messages. If you don't have a backup then you will not be able to recover the data for these applications.\n\nAre you sure that you wish to continue?" 15 60
  106. sel=$?
  107. case $sel in
  108. 1) return;;
  109. 255) return;;
  110. esac
  111. clear
  112. # remove the apps
  113. read_configuration
  114. remove_apps
  115. }
  116. function install_apps_interactive {
  117. # which apps need to be installed?
  118. installs=""
  119. app_index=0
  120. n=0
  121. for a in "${APPS_INSTALLED[@]}"
  122. do
  123. if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
  124. if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
  125. if [ ${n} -gt 0 ]; then
  126. installs="$installs ${APPS_AVAILABLE[$app_index]}"
  127. else
  128. installs="${APPS_AVAILABLE[$app_index]}"
  129. fi
  130. n=$[n+1]
  131. fi
  132. fi
  133. app_index=$[app_index+1]
  134. done
  135. # if no apps to be installed then don't do anything
  136. if [ ${n} -eq 0 ]; then
  137. return
  138. fi
  139. # ask for confirmation
  140. dialog --title $"Remove applications" \
  141. --backtitle $"Freedombone" \
  142. --defaultno \
  143. --yesno $"\nYou have chosen to install $n apps.\n\n $installs\n\nIf you choose 'yes' then these will now be installed.\n\nAre you sure that you wish to continue?" 15 60
  144. sel=$?
  145. case $sel in
  146. 1) return;;
  147. 255) return;;
  148. esac
  149. clear
  150. # install the apps
  151. read_configuration
  152. install_apps interactive
  153. }
  154. if [[ $1 == "test"* ]]; then
  155. ${PROJECT_NAME}-tests
  156. if [ ! "$?" = "0" ]; then
  157. exit 2
  158. fi
  159. fi
  160. detect_installable_apps
  161. # if no applications were found
  162. if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
  163. exit 1
  164. fi
  165. show_apps
  166. clear
  167. remove_apps_interactive
  168. install_apps_interactive
  169. exit 0