|
@@ -0,0 +1,189 @@
|
|
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
|
+
|
|
31
|
+PROJECT_NAME='freedombone'
|
|
32
|
+
|
|
33
|
+export TEXTDOMAIN=${PROJECT_NAME}-addremove
|
|
34
|
+export TEXTDOMAINDIR="/usr/share/locale"
|
|
35
|
+
|
|
36
|
+PROJECT_INSTALL_DIR=/usr/local/bin
|
|
37
|
+if [ -f /usr/bin/${PROJECT_NAME} ]; then
|
|
38
|
+ PROJECT_INSTALL_DIR=/usr/bin
|
|
39
|
+fi
|
|
40
|
+
|
|
41
|
+source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
|
|
42
|
+
|
|
43
|
+COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
|
44
|
+
|
|
45
|
+UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
|
46
|
+for f in $UTILS_FILES
|
|
47
|
+do
|
|
48
|
+ source $f
|
|
49
|
+done
|
|
50
|
+
|
|
51
|
+APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
|
|
52
|
+for f in $APP_FILES
|
|
53
|
+do
|
|
54
|
+ source $f
|
|
55
|
+done
|
|
56
|
+
|
|
57
|
+function show_apps {
|
|
58
|
+ applist=""
|
|
59
|
+ n=1
|
|
60
|
+ app_index=0
|
|
61
|
+ for a in "${APPS_AVAILABLE[@]}"
|
|
62
|
+ do
|
|
63
|
+ if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
|
|
64
|
+ applist="$applist $n $a off"
|
|
65
|
+ else
|
|
66
|
+ applist="$applist $n $a on"
|
|
67
|
+ fi
|
|
68
|
+ n=$[n+1]
|
|
69
|
+ app_index=$[app_index+1]
|
|
70
|
+ done
|
|
71
|
+
|
|
72
|
+ choices=$(dialog --stdout --backtitle $"Freedombone" \
|
|
73
|
+ --title $"Add/Remove Applications" \
|
|
74
|
+ --checklist $'Choose:' \
|
|
75
|
+ 27 40 20 $applist)
|
|
76
|
+
|
|
77
|
+ if [ $? -eq 0 ]; then
|
|
78
|
+ for choice in $choices
|
|
79
|
+ do
|
|
80
|
+ app_index = $[choice-1]
|
|
81
|
+ APPS_CHOSEN[$app_index]="1"
|
|
82
|
+ done
|
|
83
|
+ else
|
|
84
|
+ exit 0
|
|
85
|
+ fi
|
|
86
|
+}
|
|
87
|
+
|
|
88
|
+function remove_apps_interactive {
|
|
89
|
+ # which apps need to be removed?
|
|
90
|
+ removals=""
|
|
91
|
+ app_index=0
|
|
92
|
+ n=0
|
|
93
|
+ for a in "${APPS_INSTALLED[@]}"
|
|
94
|
+ do
|
|
95
|
+ if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
|
|
96
|
+ if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
|
|
97
|
+ if [ ${n} -gt 0 ]; then
|
|
98
|
+ removals="$removals $APPS_AVAILABLE[$app_index]"
|
|
99
|
+ else
|
|
100
|
+ removals="$APPS_AVAILABLE[$app_index]"
|
|
101
|
+ fi
|
|
102
|
+ n=$[n+1]
|
|
103
|
+ fi
|
|
104
|
+ fi
|
|
105
|
+ app_index=$[app_index+1]
|
|
106
|
+ done
|
|
107
|
+
|
|
108
|
+ # if no apps to be removed then don't do anything
|
|
109
|
+ if [ ${n} -eq 0 ]; then
|
|
110
|
+ return
|
|
111
|
+ fi
|
|
112
|
+
|
|
113
|
+ # ask for confirmation
|
|
114
|
+ dialog --title $"Remove applications" \
|
|
115
|
+ --backtitle $"Freedombone" \
|
|
116
|
+ --defaultno \
|
|
117
|
+ --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
|
|
118
|
+ sel=$?
|
|
119
|
+ case $sel in
|
|
120
|
+ 1) return;;
|
|
121
|
+ 255) return;;
|
|
122
|
+ esac
|
|
123
|
+
|
|
124
|
+ # remove the apps
|
|
125
|
+ read_configuration
|
|
126
|
+ remove_apps
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+function install_apps_interactive {
|
|
130
|
+ # which apps need to be installed?
|
|
131
|
+ installs=""
|
|
132
|
+ app_index=0
|
|
133
|
+ n=0
|
|
134
|
+ for a in "${APPS_INSTALLED[@]}"
|
|
135
|
+ do
|
|
136
|
+ if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
|
|
137
|
+ if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
|
|
138
|
+ if [ ${n} -gt 0 ]; then
|
|
139
|
+ installs="$installs $APPS_AVAILABLE[$app_index]"
|
|
140
|
+ else
|
|
141
|
+ installs="$APPS_AVAILABLE[$app_index]"
|
|
142
|
+ fi
|
|
143
|
+ n=$[n+1]
|
|
144
|
+ fi
|
|
145
|
+ fi
|
|
146
|
+ app_index=$[app_index+1]
|
|
147
|
+ done
|
|
148
|
+
|
|
149
|
+ # if no apps to be installed then don't do anything
|
|
150
|
+ if [ ${n} -eq 0 ]; then
|
|
151
|
+ return
|
|
152
|
+ fi
|
|
153
|
+
|
|
154
|
+ # ask for confirmation
|
|
155
|
+ dialog --title $"Remove applications" \
|
|
156
|
+ --backtitle $"Freedombone" \
|
|
157
|
+ --defaultno \
|
|
158
|
+ --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
|
|
159
|
+ sel=$?
|
|
160
|
+ case $sel in
|
|
161
|
+ 1) return;;
|
|
162
|
+ 255) return;;
|
|
163
|
+ esac
|
|
164
|
+
|
|
165
|
+ # install the apps
|
|
166
|
+ read_configuration
|
|
167
|
+ install_apps
|
|
168
|
+}
|
|
169
|
+
|
|
170
|
+${PROJECT_NAME}-tests
|
|
171
|
+if [ ! "$?" = "0" ]; then
|
|
172
|
+ exit 2
|
|
173
|
+fi
|
|
174
|
+
|
|
175
|
+detect_apps
|
|
176
|
+
|
|
177
|
+# if no applications were found
|
|
178
|
+if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
|
|
179
|
+ exit 1
|
|
180
|
+fi
|
|
181
|
+
|
|
182
|
+show_apps
|
|
183
|
+
|
|
184
|
+clear
|
|
185
|
+
|
|
186
|
+remove_apps_interactive
|
|
187
|
+install_apps_interactive
|
|
188
|
+
|
|
189
|
+exit 0
|