Bob Mottram 8 years ago
parent
commit
6c143c31f2
1 changed files with 22 additions and 6 deletions
  1. 22
    6
      src/freedombone-utils-selector

+ 22
- 6
src/freedombone-utils-selector View File

@@ -43,6 +43,7 @@ APPS_INSTALLED_NAMES=()
43 43
 # file containing a list of removed apps
44 44
 REMOVED_APPS_FILE=/root/removed
45 45
 
46
+# gets the variants list from an app script
46 47
 function app_variants {
47 48
     filename=$1
48 49
     variants_line=$(cat ${filename} | grep "VARIANTS=")
@@ -54,12 +55,14 @@ function app_variants {
54 55
     echo "$variants_list"
55 56
 }
56 57
 
58
+# whether a given item is in an array
57 59
 function item_in_array {
58 60
     local e
59 61
     for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
60 62
     return 1
61 63
 }
62 64
 
65
+# mark a given app as having been removed so that it doesn't get reinstalled on updates
63 66
 function remove_app {
64 67
     app_name=$1
65 68
     if [ ! -f $REMOVED_APPS_FILE ]; then
@@ -70,6 +73,7 @@ function remove_app {
70 73
     fi
71 74
 }
72 75
 
76
+# returns 1 if an app has been marked as removed
73 77
 function app_is_removed {
74 78
     app_name="$1"
75 79
     if [ ! -f $REMOVED_APPS_FILE ]; then
@@ -84,6 +88,7 @@ function app_is_removed {
84 88
     fi
85 89
 }
86 90
 
91
+# Allows an app to be reinstalled even if it was previously marked as being removed
87 92
 function reinstall_app {
88 93
     app_name=$1
89 94
     if [ ! -f $REMOVED_APPS_FILE ]; then
@@ -94,6 +99,7 @@ function reinstall_app {
94 99
     fi
95 100
 }
96 101
 
102
+# returns 1 if an app is installed
97 103
 function app_is_installed {
98 104
     app_name="$1"
99 105
 
@@ -109,6 +115,7 @@ function app_is_installed {
109 115
         return
110 116
     fi
111 117
 
118
+    # check the completion file to see if it was installed
112 119
     if [ ! -f $COMPLETION_FILE ]; then
113 120
         echo "0"
114 121
         return
@@ -121,6 +128,7 @@ function app_is_installed {
121 128
     fi
122 129
 }
123 130
 
131
+# called at the end of the install section of an app script
124 132
 function install_completed {
125 133
     if [ ! ${1} ]; then
126 134
         exit 673935
@@ -128,6 +136,7 @@ function install_completed {
128 136
     echo "install_${1}" >> $COMPLETION_FILE
129 137
 }
130 138
 
139
+# populates an array of "0" or "1" for whether apps are installed
131 140
 function get_apps_installed {
132 141
     for a in "${APPS_AVAILABLE[@]}"
133 142
     do
@@ -135,6 +144,7 @@ function get_apps_installed {
135 144
     done
136 145
 }
137 146
 
147
+# populates an array of installed app names
138 148
 function get_apps_installed_names {
139 149
     APPS_INSTALLED_NAMES=()
140 150
     for a in "${APPS_AVAILABLE[@]}"
@@ -145,6 +155,7 @@ function get_apps_installed_names {
145 155
     done
146 156
 }
147 157
 
158
+# detects what apps are available
148 159
 function detect_apps {
149 160
     FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
150 161
 
@@ -166,6 +177,9 @@ function detect_apps {
166 177
     get_apps_installed_names
167 178
 }
168 179
 
180
+# detects what apps are available and can be installed
181
+# If the variants list within an app script is an empty string then
182
+# it is considered to be too experimental to be installable
169 183
 function detect_installable_apps {
170 184
     FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
171 185
 
@@ -182,6 +196,7 @@ function detect_installable_apps {
182 196
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
183 197
         if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
184 198
             variants_list=$(app_variants $filename)
199
+            # check for empty string
185 200
             if [ ${#variants_list} -gt 0 ]; then
186 201
                 APPS_AVAILABLE+=("${app_name}")
187 202
                 APPS_CHOSEN+=("0")
@@ -236,6 +251,7 @@ function choose_apps_for_variant {
236 251
     get_apps_installed
237 252
 }
238 253
 
254
+# show a list of apps which have been chosen
239 255
 function list_chosen_apps {
240 256
     app_index=0
241 257
     for a in "${APPS_AVAILABLE[@]}"
@@ -270,12 +286,12 @@ function install_apps {
270 286
     app_index=0
271 287
     for a in "${APPS_AVAILABLE[@]}"
272 288
     do
273
-        if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
274
-            if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
275
-                if [ ${is_interactive} ]; then
276
-                    # interactively obtain settings for this app
277
-                    if [[ $(function_exists install_interactive_${a}) == "1" ]]; then
278
-                        if [[ $(app_is_removed ${a}) == "0" ]]; then
289
+        if [[ $(app_is_removed ${a}) == "0" ]]; then
290
+            if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
291
+                if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
292
+                    if [ ${is_interactive} ]; then
293
+                        # interactively obtain settings for this app
294
+                        if [[ $(function_exists install_interactive_${a}) == "1" ]]; then
279 295
                             install_interactive_${a}
280 296
                         fi
281 297
                     fi