Fix testing of items in an array

This commit is contained in:
Bob Mottram 2016-10-08 22:00:53 +01:00
parent b6188eb42d
commit d50ee1761e
2 changed files with 19 additions and 9 deletions

View File

@ -76,7 +76,7 @@ function app_save_variables {
# gets the variants list from an app script # gets the variants list from an app script
function app_variants { function app_variants {
filename=$1 filename=$1
variants_line=$(cat ${filename} | grep "VARIANTS=") variants_line=$(cat ${filename} | grep 'VARIANTS=')
if [[ "$variants_line" == *"'"* ]]; then if [[ "$variants_line" == *"'"* ]]; then
variants_list=$(echo "$variants_line" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}') variants_list=$(echo "$variants_line" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
else else
@ -97,13 +97,15 @@ function item_in_array {
function available_system_variants { function available_system_variants {
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
available_variants_list=()
for filename in $FILES for filename in $FILES
do do
variants_list=$(app_variants $filename) system_variants_list=$(app_variants $filename)
variants_array=($variants_list) variants_array=($system_variants_list)
for variant_str in "${vars[@]}" for variant_str in "${variants_array[@]}"
do do
if [[ $(item_in_array "$variant_str" ${available_variants_list[@]}) == "0" ]]; then item_in_array "${variant_str}" "${available_variants_list[@]}"
if [[ $? != 0 ]]; then
available_variants_list+=("$variant_str") available_variants_list+=("$variant_str")
fi fi
done done
@ -238,7 +240,9 @@ function detect_apps {
for filename in $FILES for filename in $FILES
do do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
if [[ $? != 0 ]]; then
APPS_AVAILABLE+=("${app_name}") APPS_AVAILABLE+=("${app_name}")
APPS_CHOSEN+=("0") APPS_CHOSEN+=("0")
fi fi
@ -266,7 +270,9 @@ function detect_installable_apps {
for filename in $FILES for filename in $FILES
do do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
if [[ $? != 0 ]]; then
variants_list=$(app_variants $filename) variants_list=$(app_variants $filename)
# check for empty string # check for empty string
if [ ${#variants_list} -gt 0 ]; then if [ ${#variants_list} -gt 0 ]; then
@ -295,7 +301,9 @@ function choose_apps_for_variant {
for filename in $FILES for filename in $FILES
do do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
if [[ $? != 0 ]]; then
APPS_AVAILABLE+=("${app_name}") APPS_AVAILABLE+=("${app_name}")
if grep -q "VARIANTS=" ${filename}; then if grep -q "VARIANTS=" ${filename}; then

View File

@ -489,7 +489,9 @@ function upgrade_apps {
for filename in $FILES for filename in $FILES
do do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
if [[ $(item_in_array ${app_name} ${APPS_COMPLETED[@]}) != 0 ]]; then
item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
if [[ $? != 0 ]]; then
function_check app_is_installed function_check app_is_installed
if [[ "$(app_is_installed $a)" == "1" ]]; then if [[ "$(app_is_installed $a)" == "1" ]]; then
APPS_COMPLETED+=("${app_name}") APPS_COMPLETED+=("${app_name}")