freedombone-selector 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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}-selector
  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. source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-selector
  40. function show_apps {
  41. applist=""
  42. n=1
  43. app_index=0
  44. for a in "${APPS_AVAILABLE[@]}"
  45. do
  46. if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
  47. applist="$applist $n $a off"
  48. else
  49. applist="$applist $n $a on"
  50. fi
  51. n=$[n+1]
  52. app_index=$[app_index+1]
  53. done
  54. choices=$(dialog --stdout --backtitle $"Freedombone" \
  55. --title $"Installed applications" \
  56. --checklist $'Choose:' \
  57. 80 40 20 $applist)
  58. if [ $? -eq 0 ]; then
  59. for choice in $choices
  60. do
  61. app_index = $[choice-1]
  62. APPS_CHOSEN[$app_index]="1"
  63. done
  64. else
  65. exit 0
  66. fi
  67. }
  68. function remove_apps_interactive {
  69. # which apps need to be removed?
  70. removals=""
  71. app_index=0
  72. n=0
  73. for a in "${APPS_INSTALLED[@]}"
  74. do
  75. if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
  76. if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
  77. if [ ${n} -gt 0 ]; then
  78. removals="$removals $APPS_AVAILABLE[$app_index]"
  79. else
  80. removals="$APPS_AVAILABLE[$app_index]"
  81. fi
  82. n=$[n+1]
  83. fi
  84. fi
  85. app_index=$[app_index+1]
  86. done
  87. # if no apps to be removed then don't do anything
  88. if [ ${n} -eq 0 ]; then
  89. return
  90. fi
  91. # ask for confirmation
  92. dialog --title $"Remove applications" \
  93. --backtitle $"Freedombone" \
  94. --defaultno \
  95. --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
  96. sel=$?
  97. case $sel in
  98. 1) return;;
  99. 255) return;;
  100. esac
  101. # remove the apps
  102. read_configuration
  103. remove_apps
  104. }
  105. function install_apps_interactive {
  106. # which apps need to be installed?
  107. installs=""
  108. app_index=0
  109. n=0
  110. for a in "${APPS_INSTALLED[@]}"
  111. do
  112. if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
  113. if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
  114. if [ ${n} -gt 0 ]; then
  115. installs="$installs $APPS_AVAILABLE[$app_index]"
  116. else
  117. installs="$APPS_AVAILABLE[$app_index]"
  118. fi
  119. n=$[n+1]
  120. fi
  121. fi
  122. app_index=$[app_index+1]
  123. done
  124. # if no apps to be installed then don't do anything
  125. if [ ${n} -eq 0 ]; then
  126. return
  127. fi
  128. # ask for confirmation
  129. dialog --title $"Remove applications" \
  130. --backtitle $"Freedombone" \
  131. --defaultno \
  132. --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
  133. sel=$?
  134. case $sel in
  135. 1) return;;
  136. 255) return;;
  137. esac
  138. # install the apps
  139. read_configuration
  140. install_apps
  141. }
  142. ${PROJECT_NAME}-tests
  143. if [ ! "$?" = "0" ]; then
  144. exit 2
  145. fi
  146. detect_apps
  147. # if no applications were found
  148. if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
  149. exit 1
  150. fi
  151. show_apps
  152. clear
  153. remove_apps_interactive
  154. install_apps_interactive
  155. exit 0