freedombone/src/freedombone-addremove

285 lines
7.6 KiB
Plaintext
Raw Permalink Normal View History

2016-09-30 10:46:42 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-09-30 10:46:42 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-09-30 10:46:42 +02:00
#
# Add or remove apps
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
2016-09-30 10:46:42 +02:00
#
# 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
2018-02-26 14:50:40 +01:00
if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
2016-09-30 10:46:42 +02:00
PROJECT_INSTALL_DIR=/usr/bin
fi
2018-02-26 14:50:40 +01:00
COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
2016-09-30 10:46:42 +02:00
2017-06-23 11:53:25 +02:00
# Start including files
2018-02-26 14:50:40 +01:00
source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
2017-06-23 11:53:25 +02:00
2018-02-26 14:50:40 +01:00
UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
2016-09-30 10:46:42 +02:00
for f in $UTILS_FILES
do
2018-02-26 14:50:40 +01:00
source "$f"
2016-09-30 10:46:42 +02:00
done
2018-02-26 14:50:40 +01:00
APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
2016-09-30 10:46:42 +02:00
for f in $APP_FILES
do
2018-02-26 14:50:40 +01:00
source "$f"
2016-09-30 10:46:42 +02:00
done
2017-06-23 11:53:25 +02:00
# End including files
2016-10-19 20:26:12 +02:00
function mark_unselected_apps_as_removed {
2016-10-19 20:31:40 +02:00
# Initially mark the apps not chosen on first install as being removed
2016-10-19 20:26:12 +02:00
# otherwise they may be automatically installed on the next update
select_all_apps=$1
if [[ "$select_all_apps" != "add-all" ]]; then
return
fi
2018-02-26 14:50:40 +01:00
if [ -f "$REMOVED_APPS_FILE" ]; then
rm "$REMOVED_APPS_FILE"
2016-10-19 20:26:12 +02:00
fi
app_index=0
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for app_name in ${APPS_AVAILABLE[@]}
2016-10-19 20:26:12 +02:00
do
2016-10-19 20:30:38 +02:00
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
2018-02-26 14:50:40 +01:00
echo "_${app_name}_" >> "$REMOVED_APPS_FILE"
2016-10-19 20:26:12 +02:00
fi
2018-02-26 14:50:40 +01:00
app_index=$((app_index+1))
2016-10-19 20:26:12 +02:00
done
}
2016-10-19 21:35:47 +02:00
function app_expected_to_be_installed {
# 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
if [[ $ONION_ONLY != 'no' && "$app_name" == "hubzilla" ]]; then
2016-10-19 21:35:47 +02:00
echo "0"
return
fi
2018-02-26 14:50:40 +01:00
if ! grep -q "IN_DEFAULT_INSTALL=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
2016-10-19 21:35:47 +02:00
echo "0"
return
fi
fi
2016-10-19 21:35:47 +02:00
echo "1"
}
2016-09-30 10:46:42 +02:00
function show_apps {
2018-02-26 14:50:40 +01:00
select_all_apps="$1"
2016-09-30 10:46:42 +02:00
applist=""
n=1
app_index=0
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
2016-09-30 10:46:42 +02:00
do
2018-05-09 17:17:10 +02:00
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
2016-10-19 19:48:02 +02:00
applist="$applist $n $a off"
else
2018-05-09 17:17:10 +02:00
applist="$applist $n $a on"
2016-10-19 19:48:02 +02:00
fi
2016-09-30 10:46:42 +02:00
fi
2018-05-09 17:17:10 +02:00
n=$((n+1))
app_index=$((app_index+1))
2016-09-30 10:46:42 +02:00
done
2018-03-04 20:08:28 +01:00
# shellcheck disable=SC2086
2016-09-30 10:46:42 +02:00
choices=$(dialog --stdout --backtitle $"Freedombone" \
--title $"Add/Remove Applications" \
--checklist $'Choose:' \
2018-03-04 20:08:28 +01:00
27 40 20 $applist)
2016-09-30 10:46:42 +02:00
2018-02-26 14:50:40 +01:00
# shellcheck disable=SC2181
2016-09-30 10:46:42 +02:00
if [ $? -eq 0 ]; then
for choice in $choices
do
2018-02-26 14:50:40 +01:00
app_index=$((choice-1))
2016-09-30 10:46:42 +02:00
APPS_CHOSEN[$app_index]="1"
done
else
exit 0
fi
}
2016-10-17 12:35:13 +02:00
function remove_apps_selected {
2016-09-30 10:46:42 +02:00
# which apps need to be removed?
removals=""
app_index=0
n=0
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for a in ${APPS_INSTALLED[@]}
2016-09-30 10:46:42 +02:00
do
2018-05-09 17:17:10 +02:00
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]}"
2016-09-30 10:46:42 +02:00
fi
2018-05-09 17:17:10 +02:00
n=$((n+1))
2016-09-30 10:46:42 +02:00
fi
fi
2018-05-09 17:17:10 +02:00
app_index=$((app_index+1))
2016-09-30 10:46:42 +02:00
done
# if no apps to be removed then don't do anything
if [ ${n} -eq 0 ]; then
return
fi
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
2016-09-30 10:46:42 +02:00
# ask for confirmation
dialog --title $"Remove applications" \
--backtitle $"Freedombone" \
--defaultno \
2018-02-26 14:50:40 +01:00
--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
2016-09-30 10:46:42 +02:00
sel=$?
case $sel in
1) return;;
255) return;;
esac
2016-09-30 22:55:05 +02:00
clear
2016-09-30 10:46:42 +02:00
# remove the apps
read_configuration
remove_apps
}
2016-10-17 12:35:13 +02:00
function install_apps_selected {
2016-09-30 10:46:42 +02:00
# which apps need to be installed?
select_all_apps=$1
2016-09-30 10:46:42 +02:00
installs=""
app_index=0
n=0
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for a in ${APPS_INSTALLED[@]}
do
2018-05-09 17:17:10 +02:00
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]}"
2016-09-30 10:46:42 +02:00
fi
2018-05-09 17:17:10 +02:00
n=$((n+1))
2016-09-30 10:46:42 +02:00
fi
fi
2018-05-09 17:17:10 +02:00
app_index=$((app_index+1))
done
2016-09-30 10:46:42 +02:00
# if no apps to be installed then don't do anything
if [ ${n} -eq 0 ]; then
return
fi
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 \
2018-02-26 14:50:40 +01:00
--yesno $"\\nThis will install the $installs app\\n\\nProceed?" 9 40
else
2018-02-26 14:50:40 +01:00
dialog_height=$((15 + "$n"))
dialog --title $"Add applications" \
--backtitle $"Freedombone" \
--defaultno \
2018-02-26 14:50:40 +01:00
--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
fi
2016-09-30 10:46:42 +02:00
2016-09-30 22:55:05 +02:00
clear
2016-09-30 10:46:42 +02:00
# install the apps
read_configuration
install_apps interactive
2018-02-26 14:50:40 +01:00
if [ ! "$APP_INSTALLED_SUCCESS" ]; then
echo $'One or more apps failed to install'
fi
2016-09-30 10:46:42 +02:00
}
2016-10-01 10:59:20 +02:00
if [[ $1 == "test"* ]]; then
2018-02-26 14:50:40 +01:00
if ! ${PROJECT_NAME}-tests; then
2016-10-01 10:59:20 +02:00
exit 2
fi
2016-09-30 10:46:42 +02:00
fi
detect_installable_apps
2016-09-30 10:46:42 +02:00
# if no applications were found
if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
exit 1
fi
2018-02-26 14:50:40 +01:00
show_apps "$1"
mark_unselected_apps_as_removed "$1"
2016-09-30 10:46:42 +02:00
clear
2016-10-17 12:35:13 +02:00
remove_apps_selected
2018-03-04 20:08:28 +01:00
if [[ "$1" == "add-all" ]]; then
install_apps_selected add-all
else
install_apps_selected
fi
2018-05-25 16:17:34 +02:00
android_update_apps
2016-09-30 10:46:42 +02:00
exit 0