Browse Source

Rename selector to addremove

Bob Mottram 8 years ago
parent
commit
28d5909c71
2 changed files with 189 additions and 179 deletions
  1. 189
    0
      src/freedombone-addremove
  2. 0
    179
      src/freedombone-selector

+ 189
- 0
src/freedombone-addremove View File

@@ -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

+ 0
- 179
src/freedombone-selector View File

@@ -1,179 +0,0 @@
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}-selector
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
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-selector
46
-
47
-function show_apps {
48
-	applist=""
49
-	n=1
50
-	app_index=0
51
-	for a in "${APPS_AVAILABLE[@]}"
52
-	do
53
-		if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
54
-			applist="$applist $n $a off"
55
-		else
56
-			applist="$applist $n $a on"
57
-		fi
58
-		n=$[n+1]
59
-		app_index=$[app_index+1]
60
-	done
61
-
62
-	choices=$(dialog --stdout --backtitle $"Freedombone" \
63
-					 --title $"Installed applications" \
64
-					 --checklist $'Choose:' \
65
-					 80 40 20 $applist)
66
-
67
-	if [ $? -eq 0 ]; then
68
-		for choice in $choices
69
-		do
70
-			app_index = $[choice-1]
71
-			APPS_CHOSEN[$app_index]="1"
72
-		done
73
-	else
74
-		exit 0
75
-	fi
76
-}
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
-
98
-	# if no apps to be removed then don't do anything
99
-	if [ ${n} -eq 0 ]; then
100
-		return
101
-	fi
102
-
103
-	# ask for confirmation
104
-	dialog --title $"Remove applications" \
105
-		   --backtitle $"Freedombone" \
106
-		   --defaultno \
107
-		   --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
108
-	sel=$?
109
-	case $sel in
110
-		1) return;;
111
-		255) return;;
112
-	esac
113
-
114
-	# remove the apps
115
-	read_configuration
116
-	remove_apps
117
-}
118
-
119
-function install_apps_interactive {
120
-	# which apps need to be installed?
121
-	installs=""
122
-	app_index=0
123
-	n=0
124
-	for a in "${APPS_INSTALLED[@]}"
125
-	do
126
-		if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
127
-			if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
128
-				if [ ${n} -gt 0 ]; then
129
-					installs="$installs $APPS_AVAILABLE[$app_index]"
130
-				else
131
-					installs="$APPS_AVAILABLE[$app_index]"
132
-				fi
133
-				n=$[n+1]
134
-			fi
135
-		fi
136
-		app_index=$[app_index+1]
137
-	done
138
-
139
-	# if no apps to be installed then don't do anything
140
-	if [ ${n} -eq 0 ]; then
141
-		return
142
-	fi
143
-
144
-	# ask for confirmation
145
-	dialog --title $"Remove applications" \
146
-		   --backtitle $"Freedombone" \
147
-		   --defaultno \
148
-		   --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
149
-	sel=$?
150
-	case $sel in
151
-		1) return;;
152
-		255) return;;
153
-	esac
154
-
155
-	# install the apps
156
-	read_configuration
157
-	install_apps
158
-}
159
-
160
-${PROJECT_NAME}-tests
161
-if [ ! "$?" = "0" ]; then
162
-	exit 2
163
-fi
164
-
165
-detect_apps
166
-
167
-# if no applications were found
168
-if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
169
-	exit 1
170
-fi
171
-
172
-show_apps
173
-
174
-clear
175
-
176
-remove_apps_interactive
177
-install_apps_interactive
178
-
179
-exit 0