Selecting full installs

This commit is contained in:
Bob Mottram 2016-09-28 21:26:36 +01:00
parent e7539c36c9
commit ed0e6be64e
1 changed files with 100 additions and 95 deletions

View File

@ -41,137 +41,142 @@ APPS_CHOSEN=()
APPS_INSTALLED_NAMES=() APPS_INSTALLED_NAMES=()
function item_in_array { function item_in_array {
local e local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1 return 1
} }
function app_is_installed { function app_is_installed {
app_name="$1" app_name="$1"
if [ ! -f $COMPLETION_FILE ]; then if [ ! -f $COMPLETION_FILE ]; then
echo "0" echo "0"
return return
fi fi
if ! grep -Fxq "install_${app_name}" $COMPLETION_FILE; then if ! grep -Fxq "install_${app_name}" $COMPLETION_FILE; then
echo "0" echo "0"
else else
echo "1" echo "1"
fi fi
} }
function get_apps_installed { function get_apps_installed {
for a in "${APPS_AVAILABLE[@]}" for a in "${APPS_AVAILABLE[@]}"
do do
APPS_INSTALLED+=("$(app_is_installed $a)") APPS_INSTALLED+=("$(app_is_installed $a)")
done done
} }
function get_apps_installed_names { function get_apps_installed_names {
APPS_INSTALLED_NAMES=() APPS_INSTALLED_NAMES=()
for a in "${APPS_AVAILABLE[@]}" for a in "${APPS_AVAILABLE[@]}"
do do
if [[ $(app_is_installed $a) == "1" ]]; then if [[ $(app_is_installed $a) == "1" ]]; then
APPS_INSTALLED_NAMES+=("$a") APPS_INSTALLED_NAMES+=("$a")
fi fi
done done
} }
function detect_apps { function detect_apps {
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
APPS_AVAILABLE=() APPS_AVAILABLE=()
APPS_CHOSEN=() APPS_CHOSEN=()
# for all the app scripts # for all the app scripts
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 if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
APPS_AVAILABLE+=("${app_name}") APPS_AVAILABLE+=("${app_name}")
APPS_CHOSEN+=("0") APPS_CHOSEN+=("0")
fi fi
done done
function_check get_apps_installed function_check get_apps_installed
get_apps_installed get_apps_installed
get_apps_installed_names get_apps_installed_names
} }
# creates the APPS_AVAILABLE and APPS_CHOSEN arrays based on # creates the APPS_AVAILABLE and APPS_CHOSEN arrays based on
# the given variant name # the given variant name
function choose_apps_for_variant { function choose_apps_for_variant {
variant_name="$1" variant_name="$1"
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
APPS_AVAILABLE=() APPS_AVAILABLE=()
APPS_CHOSEN=() APPS_CHOSEN=()
# for all the app scripts # for all the app scripts
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 if [[ $(item_in_array ${app_name} ${APPS_AVAILABLE[@]}) != 0 ]]; then
APPS_AVAILABLE+=("${app_name}") APPS_AVAILABLE+=("${app_name}")
if grep -q "VARIANTS=" ${filename}; then if grep -q "VARIANTS=" ${filename}; then
variants_list="$(cat ${filename} | grep "VARIANTS=" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')" variants_list="$(cat ${filename} | grep "VARIANTS=" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')"
if [[ "${variants_list}" == 'all' || "${variants_list}" == "$variant_name "* || "${variants_list}" == *" $variant_name "* || "${variants_list}" == *" $variant_name" ]]; then if [[ "${variants_list}" == 'all' || \
APPS_CHOSEN+=("1") "${variants_list}" == 'any' || \
else "${variants_list}" == 'full' || \
APPS_CHOSEN+=("0") "${variants_list}" == "$variant_name "* || \
fi "${variants_list}" == *" $variant_name "* || \
else "${variants_list}" == *" $variant_name" ]]; then
APPS_CHOSEN+=("0") APPS_CHOSEN+=("1")
fi else
APPS_CHOSEN+=("0")
fi
else
APPS_CHOSEN+=("0")
fi
fi fi
done done
function_check get_apps_installed function_check get_apps_installed
get_apps_installed get_apps_installed
} }
function list_chosen_apps { function list_chosen_apps {
app_index=0 app_index=0
for a in "${APPS_AVAILABLE[@]}" for a in "${APPS_AVAILABLE[@]}"
do do
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
echo $"${a}" echo $"${a}"
fi fi
app_index=$[app_index+1] app_index=$[app_index+1]
done done
} }
function remove_apps { function remove_apps {
app_index=0 app_index=0
for a in "${APPS_AVAILABLE[@]}" for a in "${APPS_AVAILABLE[@]}"
do do
if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
echo $"Removing application: ${a}" echo $"Removing application: ${a}"
remove_${a} remove_${a}
echo $"${a} was removed" echo $"${a} was removed"
fi fi
fi fi
app_index=$[app_index+1] app_index=$[app_index+1]
done done
} }
function install_apps { function install_apps {
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" ]]; then
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
echo $"Installing application: ${a}" echo $"Installing application: ${a}"
install_${a} install_${a}
echo $"${a} was installed" echo $"${a} was installed"
fi fi
fi fi
app_index=$[app_index+1] app_index=$[app_index+1]
done done
} }
# NOTE: deliberately no exit 0 # NOTE: deliberately no exit 0