Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Add or remove apps
#
# License
# =======
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-addremove
export TEXTDOMAINDIR="/usr/share/locale"
PROJECT_INSTALL_DIR=/usr/local/bin
COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
# Initially mark the apps not chosen on first install as being removed
# otherwise they may be automatically installed on the next update
select_all_apps=$1
if [[ "$select_all_apps" != "add-all" ]]; then
return
fi
# shellcheck disable=SC2068
for app_name in ${APPS_AVAILABLE[@]}
# is the given application expected to be installed by default?
select_all_apps="$1"
app_name="$2"
read_config_param ONION_ONLY
if [[ "$select_all_apps" == "add-all" ]]; then
Bob Mottram
committed
if [[ $ONION_ONLY != 'no' && "$app_name" == "hubzilla" ]]; then
if ! grep -q "IN_DEFAULT_INSTALL=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
# Select a particular app to be added or removed
function select_specific_app {
app_name="$1"
# make sure that already installed apps are chosen
app_index=0
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
do
APPS_CHOSEN[$app_index]=${APPS_INSTALLED[$app_index]}
app_index=$((app_index+1))
done
app_index=0
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
do
if [[ "$a" == "$app_name" ]]; then
APPS_CHOSEN[$app_index]="$app_is_chosen"
break
fi
app_index=$((app_index+1))
done
}
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then
applist="$applist $n $a off"
else
if [[ $(app_expected_to_be_installed "$select_all_apps" "$a") == "0" ]]; then
choices=$(dialog --stdout --backtitle $"Freedombone" \
--title $"Add/Remove Applications" \
--checklist $'Choose:' \
if [ $? -eq 0 ]; then
for choice in $choices
do
APPS_CHOSEN[$app_index]="1"
done
else
exit 0
fi
}
# which apps need to be removed?
removals=""
app_index=0
n=0
# shellcheck disable=SC2068
for a in ${APPS_INSTALLED[@]}
if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
if [ ${n} -gt 0 ]; then
removals="$removals ${APPS_AVAILABLE[$app_index]}"
else
removals="${APPS_AVAILABLE[$app_index]}"
done
# if no apps to be removed then don't do anything
if [ ${n} -eq 0 ]; then
return
fi
if [ $install_is_interactive ]; then
if [ -f /tmp/.upgrading ]; then
dialog --title $"Cannot remove apps" \
--msgbox $"A system upgrade is happening, so apps cannot be removed at this time" 6 60
return
fi
# ask for confirmation
dialog --title $"Remove applications" \
--backtitle $"Freedombone" \
--defaultno \
--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
sel=$?
case $sel in
1) return;;
255) return;;
esac
# remove the apps
read_configuration
remove_apps
}
select_all_apps=$1
# shellcheck disable=SC2068
for a in ${APPS_INSTALLED[@]}
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]}"
# if no apps to be installed then don't do anything
if [ ${n} -eq 0 ]; then
return
fi
if [ $install_is_interactive ]; then
if [[ "$select_all_apps" != "add-all" ]]; then
if [ -f /tmp/.upgrading ]; then
dialog --title $"Cannot install apps" \
--msgbox $"A system upgrade is happening, so apps cannot be installed at this time" 6 60
return
fi
# ask for confirmation
if [ $n -eq 1 ]; then
dialog --title $"$installs" \
--backtitle $"Freedombone" \
--defaultno \
--yesno $"\\nThis will install the $installs app\\n\\nProceed?" 9 40
else
dialog_height=$((15 + "$n"))
dialog --title $"Add applications" \
--backtitle $"Freedombone" \
--defaultno \
--yesno $"\\nYou have chosen to install $n apps\\n\\n $installs\\n\\nProceed?" $dialog_height 60
fi
sel=$?
case $sel in
1) return;;
255) return;;
esac
clear
# install the apps
read_configuration
install_apps interactive
else
# install the apps
read_configuration
install_apps
fi
echo $'One or more apps failed to install'
fi
# if no applications were found
if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
exit 1
fi
if [ "$2" ]; then
if [[ "$args" == "add" || "$args" == "remove" ]]; then
app_name_upper=$(echo "$2" | awk '{print toupper($0)}')
read_config_param "${app_name_upper}_DOMAIN_NAME"
read_config_param "${app_name_upper}_CODE"
if [[ "$args" == "add" ]]; then
select_specific_app "$2" "1"
else
select_specific_app "$2" "0"
fi
install_is_interactive=
else
show_apps "$args"
fi
else
show_apps "$args"
fi
mark_unselected_apps_as_removed "$args"
if [ $install_is_interactive ]; then
clear
fi
if [[ "$args" == "add-all" ]]; then
install_apps_selected "$args"
else
install_apps_selected
fi