Better implementation of selecting all apps

This commit is contained in:
Bob Mottram 2016-10-17 13:13:02 +01:00
parent ad39b2c78d
commit 5edcf011f4
1 changed files with 11 additions and 29 deletions

View File

@ -56,12 +56,13 @@ do
done done
function show_apps { function show_apps {
select_all_apps=$1
applist="" applist=""
n=1 n=1
app_index=0 app_index=0
for a in "${APPS_AVAILABLE[@]}" for a in "${APPS_AVAILABLE[@]}"
do do
if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then
applist="$applist $n $a off" applist="$applist $n $a off"
else else
applist="$applist $n $a on" applist="$applist $n $a on"
@ -130,33 +131,14 @@ function remove_apps_selected {
} }
function install_apps_selected { function install_apps_selected {
select_all_apps=$1
# which apps need to be installed? # which apps need to be installed?
installs="" installs=""
app_index=0 app_index=0
n=0 n=0
for a in "${APPS_INSTALLED[@]}"
if [ ! $select_all_apps ]; then do
for a in "${APPS_INSTALLED[@]}" if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
do if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
if [ ${n} -gt 0 ]; then
installs="$installs ${APPS_AVAILABLE[$app_index]}"
else
installs="${APPS_AVAILABLE[$app_index]}"
fi
n=$[n+1]
fi
fi
app_index=$[app_index+1]
done
fi
if [[ $select_all_apps == "add-all" ]]; then
for a in "${APPS_INSTALLED[@]}"
do
if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
if [ ${n} -gt 0 ]; then if [ ${n} -gt 0 ]; then
installs="$installs ${APPS_AVAILABLE[$app_index]}" installs="$installs ${APPS_AVAILABLE[$app_index]}"
else else
@ -164,10 +146,9 @@ function install_apps_selected {
fi fi
n=$[n+1] n=$[n+1]
fi fi
APPS_CHOSEN[$app_index]="1" fi
app_index=$[app_index+1] app_index=$[app_index+1]
done done
fi
# if no apps to be installed then don't do anything # if no apps to be installed then don't do anything
if [ ${n} -eq 0 ]; then if [ ${n} -eq 0 ]; then
@ -206,11 +187,12 @@ if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
exit 1 exit 1
fi fi
show_apps show_apps $1
clear clear
remove_apps_selected remove_apps_selected
if [[ $1 == "add-all" ]]; then if [[ $1 == "add-all" ]]; then
install_apps_selected add-all install_apps_selected add-all
else else