2016-07-06 14:21:43 +02:00
|
|
|
#!/bin/bash
|
2018-04-08 14:30:21 +02:00
|
|
|
# _____ _ _
|
|
|
|
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
|
|
|
|
# | __| _| -_| -_| . | . | | . | . | | -_|
|
|
|
|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
|
2016-07-06 14:21:43 +02:00
|
|
|
#
|
2018-04-08 14:30:21 +02:00
|
|
|
# Freedom in the Cloud
|
2016-07-06 14:21:43 +02:00
|
|
|
#
|
|
|
|
# Functions for selecting which apps to install or remove
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2018-02-21 20:32:13 +01:00
|
|
|
# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
|
2016-07-06 14:21:43 +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/>.
|
|
|
|
|
|
|
|
# Array containing names of available apps
|
|
|
|
APPS_AVAILABLE=()
|
|
|
|
|
|
|
|
# Array containing 1 or 0 indicating installed apps
|
|
|
|
APPS_INSTALLED=()
|
|
|
|
|
|
|
|
# Apps selected with checklist
|
|
|
|
APPS_CHOSEN=()
|
|
|
|
|
2016-07-09 19:02:33 +02:00
|
|
|
# A list of the names of installed apps
|
|
|
|
APPS_INSTALLED_NAMES=()
|
|
|
|
|
2016-09-30 23:50:16 +02:00
|
|
|
# file containing a list of removed apps
|
|
|
|
REMOVED_APPS_FILE=/root/removed
|
|
|
|
|
2016-10-11 14:47:35 +02:00
|
|
|
INSTALLED_APPS_LIST=/usr/share/${PROJECT_NAME}/installed.txt
|
|
|
|
|
2016-10-26 00:04:56 +02:00
|
|
|
# keep a list of which users have been added to which apps
|
|
|
|
# so that when a new app is added existing users can be added
|
|
|
|
APP_USERS_FILE=$HOME/app_users.txt
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ ! "$COMPLETION_FILE" ]; then
|
|
|
|
COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
|
2016-10-11 14:47:35 +02:00
|
|
|
fi
|
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
# Loads variables defined at the beginning of an app script
|
|
|
|
function app_load_variables {
|
|
|
|
app_name=$1
|
|
|
|
|
2016-10-11 16:07:02 +02:00
|
|
|
config_var_name=${app_name}_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
# shellcheck disable=SC2086
|
2016-10-11 16:07:02 +02:00
|
|
|
if [ ! ${!config_var_name} ]; then
|
2016-10-11 15:56:34 +02:00
|
|
|
echo $"${app_name}_variables was not found"
|
2016-10-05 23:33:41 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
#shellcheck disable=SC1087,SC2125,SC2178
|
2016-10-11 16:32:22 +02:00
|
|
|
configvarname=$config_var_name[@]
|
2018-03-02 23:20:49 +01:00
|
|
|
|
|
|
|
#shellcheck disable=SC2206
|
2016-10-11 16:32:22 +02:00
|
|
|
configvarname=( ${!configvarname} )
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for v in ${configvarname[@]}
|
2016-10-05 23:33:41 +02:00
|
|
|
do
|
2018-03-02 23:20:49 +01:00
|
|
|
read_config_param "$v"
|
2016-10-05 23:33:41 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Saves variables for a given app script
|
|
|
|
function app_save_variables {
|
|
|
|
app_name=$1
|
|
|
|
|
2016-10-11 16:07:02 +02:00
|
|
|
config_var_name=${app_name}_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
#shellcheck disable=SC2086
|
2016-10-11 16:07:02 +02:00
|
|
|
if [ ! ${!config_var_name} ]; then
|
2016-10-05 23:33:41 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
#shellcheck disable=SC1087,SC2125,SC2178
|
2016-10-11 16:32:22 +02:00
|
|
|
configvarname=$config_var_name[@]
|
2018-03-02 23:20:49 +01:00
|
|
|
|
|
|
|
#shellcheck disable=SC2206
|
2016-10-11 16:32:22 +02:00
|
|
|
configvarname=( ${!configvarname} )
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for v in ${configvarname[@]}
|
2016-10-05 23:33:41 +02:00
|
|
|
do
|
2018-03-02 23:20:49 +01:00
|
|
|
write_config_param "$v" "${!v}"
|
2016-10-05 23:33:41 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# gets the variants list from an app script
|
2016-09-30 11:02:51 +02:00
|
|
|
function app_variants {
|
|
|
|
filename=$1
|
2018-03-02 23:20:49 +01:00
|
|
|
variants_line=$(grep 'VARIANTS=' "${filename}")
|
2016-09-30 11:02:51 +02:00
|
|
|
if [[ "$variants_line" == *"'"* ]]; then
|
|
|
|
variants_list=$(echo "$variants_line" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
|
|
|
|
else
|
|
|
|
variants_list=$(echo "$variants_line" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
|
|
|
|
fi
|
|
|
|
echo "$variants_list"
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# whether a given item is in an array
|
2016-07-06 14:21:43 +02:00
|
|
|
function item_in_array {
|
2016-09-28 22:26:36 +02:00
|
|
|
local e
|
|
|
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
|
|
|
return 1
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 19:21:43 +02:00
|
|
|
# returns a list of available system variants
|
|
|
|
# based upon the variants string in each app script
|
|
|
|
function available_system_variants {
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check item_in_array
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
|
2016-10-08 19:21:43 +02:00
|
|
|
|
2016-10-09 23:17:33 +02:00
|
|
|
new_available_variants_list=()
|
2016-10-08 19:21:43 +02:00
|
|
|
for filename in $FILES
|
|
|
|
do
|
2018-03-02 23:20:49 +01:00
|
|
|
system_variants_list=$(app_variants "$filename")
|
|
|
|
# shellcheck disable=SC2206
|
2016-10-08 23:00:53 +02:00
|
|
|
variants_array=($system_variants_list)
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for variant_str in ${variants_array[@]}
|
2016-10-08 19:21:43 +02:00
|
|
|
do
|
2018-03-08 15:38:15 +01:00
|
|
|
if ! item_in_array "${variant_str}" ${new_available_variants_list[@]}; then
|
2016-10-09 23:17:33 +02:00
|
|
|
new_available_variants_list+=("$variant_str")
|
2016-10-08 19:21:43 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
2018-03-02 23:20:49 +01:00
|
|
|
# shellcheck disable=SC2207
|
2016-10-09 23:17:33 +02:00
|
|
|
available_variants_list=($(sort <<<"${new_available_variants_list[*]}"))
|
2016-10-08 19:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 20:32:04 +02:00
|
|
|
function is_valid_variant {
|
|
|
|
sys_type="$1"
|
|
|
|
available_variants_list=()
|
2016-10-15 14:59:56 +02:00
|
|
|
|
|
|
|
function_check available_system_variants
|
2016-10-08 20:32:04 +02:00
|
|
|
available_system_variants
|
|
|
|
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for variant_str in ${available_variants_list[@]}
|
2016-10-08 20:32:04 +02:00
|
|
|
do
|
|
|
|
if [[ "$sys_type" == "$variant_str" ]]; then
|
|
|
|
return "1"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return "0"
|
|
|
|
}
|
|
|
|
|
2016-10-08 20:55:21 +02:00
|
|
|
function show_available_variants {
|
|
|
|
available_variants_list=()
|
2016-10-15 14:59:56 +02:00
|
|
|
|
|
|
|
function_check available_system_variants
|
2016-10-08 20:55:21 +02:00
|
|
|
available_system_variants
|
|
|
|
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for variant_str in ${available_variants_list[@]}
|
2016-10-08 20:55:21 +02:00
|
|
|
do
|
|
|
|
echo " $variant_str"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# mark a given app as having been removed so that it doesn't get reinstalled on updates
|
2016-09-30 23:50:16 +02:00
|
|
|
function remove_app {
|
|
|
|
app_name=$1
|
|
|
|
if [ ! -f $REMOVED_APPS_FILE ]; then
|
|
|
|
touch $REMOVED_APPS_FILE
|
|
|
|
fi
|
2016-10-01 11:08:36 +02:00
|
|
|
if ! grep -Fxq "_${app_name}_" $REMOVED_APPS_FILE; then
|
|
|
|
echo "_${app_name}_" >> $REMOVED_APPS_FILE
|
2016-09-30 23:50:16 +02:00
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
if grep -Fxq "install_${app_name}" "$COMPLETION_FILE"; then
|
|
|
|
sed -i "/install_${app_name}/d" "$COMPLETION_FILE"
|
2016-10-11 14:47:35 +02:00
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
if grep -Fxq "install_${app_name}" "$INSTALLED_APPS_LIST"; then
|
|
|
|
sed -i "/install_${app_name}/d" "$INSTALLED_APPS_LIST"
|
2016-10-11 14:47:35 +02:00
|
|
|
fi
|
2016-09-30 23:50:16 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# returns 1 if an app has been marked as removed
|
2016-09-30 23:50:16 +02:00
|
|
|
function app_is_removed {
|
|
|
|
app_name="$1"
|
|
|
|
if [ ! -f $REMOVED_APPS_FILE ]; then
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-01 11:08:36 +02:00
|
|
|
if ! grep -Fxq "_${app_name}_" $REMOVED_APPS_FILE; then
|
2016-09-30 23:50:16 +02:00
|
|
|
echo "0"
|
|
|
|
else
|
|
|
|
echo "1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# Allows an app to be reinstalled even if it was previously marked as being removed
|
2016-09-30 23:50:16 +02:00
|
|
|
function reinstall_app {
|
|
|
|
app_name=$1
|
|
|
|
if [ ! -f $REMOVED_APPS_FILE ]; then
|
|
|
|
return
|
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(app_is_removed "$app_name") == "1" ]]; then
|
2016-10-01 11:08:36 +02:00
|
|
|
sed -i "/_${app_name}_/d" $REMOVED_APPS_FILE
|
2016-09-30 23:50:16 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# returns 1 if an app is installed
|
2016-07-06 14:21:43 +02:00
|
|
|
function app_is_installed {
|
2016-09-28 22:26:36 +02:00
|
|
|
app_name="$1"
|
2016-09-30 18:49:24 +02:00
|
|
|
|
|
|
|
# Why does this secondary file exist, apart from COMPLETION_FILE ?
|
|
|
|
# It's so that it is visible to unprivileged users from the user control panel
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ -f "$INSTALLED_APPS_LIST" ]; then
|
|
|
|
if ! grep -Fxq "install_${app_name}" "$INSTALLED_APPS_LIST"; then
|
2016-09-30 18:30:32 +02:00
|
|
|
echo "0"
|
|
|
|
else
|
|
|
|
echo "1"
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# check the completion file to see if it was installed
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ ! -f "$COMPLETION_FILE" ]; then
|
2016-09-30 18:39:02 +02:00
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
if ! grep -Fxq "install_${app_name}" "$COMPLETION_FILE"; then
|
2016-09-28 22:26:36 +02:00
|
|
|
echo "0"
|
|
|
|
else
|
|
|
|
echo "1"
|
|
|
|
fi
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# called at the end of the install section of an app script
|
2016-09-30 17:00:45 +02:00
|
|
|
function install_completed {
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ ! "${1}" ]; then
|
2016-09-30 17:00:45 +02:00
|
|
|
exit 673935
|
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
if ! grep -Fxq "install_${1}" "$COMPLETION_FILE"; then
|
|
|
|
echo "install_${1}" >> "$COMPLETION_FILE"
|
2016-10-16 20:50:56 +02:00
|
|
|
fi
|
2016-09-30 17:00:45 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# populates an array of "0" or "1" for whether apps are installed
|
2016-07-06 14:21:43 +02:00
|
|
|
function get_apps_installed {
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-09-28 22:26:36 +02:00
|
|
|
do
|
2018-03-02 23:20:49 +01:00
|
|
|
APPS_INSTALLED+=("$(app_is_installed "$a")")
|
2016-09-28 22:26:36 +02:00
|
|
|
done
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# populates an array of installed app names
|
2016-07-09 19:02:33 +02:00
|
|
|
function get_apps_installed_names {
|
2016-09-28 22:26:36 +02:00
|
|
|
APPS_INSTALLED_NAMES=()
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-09-28 22:26:36 +02:00
|
|
|
do
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(app_is_installed "$a") == "1" ]]; then
|
2016-09-28 22:26:36 +02:00
|
|
|
APPS_INSTALLED_NAMES+=("$a")
|
|
|
|
fi
|
|
|
|
done
|
2016-07-09 19:02:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 17:14:31 +02:00
|
|
|
function app_not_on_onion_only {
|
|
|
|
app_name="$1"
|
|
|
|
|
|
|
|
read_config_param ONION_ONLY
|
|
|
|
|
|
|
|
if [[ "$ONION_ONLY" != 'no' ]]; then
|
|
|
|
if grep -q "NOT_ON_ONION=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "1"
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:43:54 +02:00
|
|
|
function app_not_on_arm {
|
|
|
|
app_name="$1"
|
|
|
|
|
|
|
|
if grep -q "NOT_ON_ARM=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
|
|
|
|
archtype=$(uname -m)
|
|
|
|
if [[ "$archtype" == 'arm'* ]]; then
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "1"
|
|
|
|
}
|
|
|
|
|
2018-05-09 18:38:17 +02:00
|
|
|
function enough_ram_for_app {
|
|
|
|
app_name="$1"
|
|
|
|
|
|
|
|
if ! grep -q "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
minimum_ram_MB=$(grep "MINIMUM_RAM_MB=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}" | head -n 1 | awk -F '=' '{print $2}')
|
|
|
|
minimum_ram_bytes=$((minimum_ram_MB * 1024))
|
|
|
|
|
|
|
|
ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
|
|
|
if [ "$ram_available" -lt "$minimum_ram_bytes" ]; then
|
|
|
|
echo "1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "0"
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# detects what apps are available
|
2016-07-06 14:21:43 +02:00
|
|
|
function detect_apps {
|
2018-03-02 23:20:49 +01:00
|
|
|
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
|
2016-09-28 22:26:36 +02:00
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check item_in_array
|
|
|
|
|
2016-09-28 22:26:36 +02:00
|
|
|
APPS_AVAILABLE=()
|
|
|
|
APPS_CHOSEN=()
|
|
|
|
|
|
|
|
# for all the app scripts
|
|
|
|
for filename in $FILES
|
|
|
|
do
|
|
|
|
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
|
2018-05-09 18:41:37 +02:00
|
|
|
if [[ $(enough_ram_for_app "$app_name") == "0" ]]; then
|
2018-05-09 18:38:17 +02:00
|
|
|
if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
|
2018-05-11 14:43:54 +02:00
|
|
|
if [[ $(app_not_on_arm "$app_name") != "0" ]]; then
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
|
|
|
|
APPS_AVAILABLE+=("${app_name}")
|
|
|
|
APPS_CHOSEN+=("0")
|
|
|
|
fi
|
2018-05-09 18:38:17 +02:00
|
|
|
fi
|
2018-05-09 16:43:45 +02:00
|
|
|
fi
|
2016-09-28 22:26:36 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
function_check get_apps_installed
|
|
|
|
get_apps_installed
|
|
|
|
get_apps_installed_names
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# detects what apps are available and can be installed
|
|
|
|
# If the variants list within an app script is an empty string then
|
|
|
|
# it is considered to be too experimental to be installable
|
2016-09-30 11:02:51 +02:00
|
|
|
function detect_installable_apps {
|
2018-03-02 23:20:49 +01:00
|
|
|
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
|
2016-09-30 11:02:51 +02:00
|
|
|
|
|
|
|
APPS_AVAILABLE=()
|
|
|
|
APPS_CHOSEN=()
|
|
|
|
APPS_INSTALLED=()
|
|
|
|
APPS_INSTALLED_NAMES=()
|
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check app_variants
|
2016-09-30 11:02:51 +02:00
|
|
|
function_check app_is_installed
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check item_in_array
|
2016-09-30 11:02:51 +02:00
|
|
|
|
|
|
|
# for all the app scripts
|
|
|
|
for filename in $FILES
|
|
|
|
do
|
|
|
|
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
|
2016-10-08 23:00:53 +02:00
|
|
|
|
2018-05-09 18:41:37 +02:00
|
|
|
if [[ $(enough_ram_for_app "$app_name") == "0" ]]; then
|
2018-05-09 18:38:17 +02:00
|
|
|
if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
|
2018-05-11 14:43:54 +02:00
|
|
|
if [[ $(app_not_on_arm "$app_name") != "0" ]]; then
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
|
|
|
|
variants_list=$(app_variants "$filename")
|
|
|
|
# check for empty string
|
|
|
|
if [ ${#variants_list} -gt 0 ]; then
|
|
|
|
APPS_AVAILABLE+=("${app_name}")
|
|
|
|
APPS_CHOSEN+=("0")
|
|
|
|
APPS_INSTALLED+=("$(app_is_installed "$app_name")")
|
|
|
|
if [[ $(app_is_installed "$app_name") == "1" ]]; then
|
|
|
|
APPS_INSTALLED_NAMES+=("$app_name")
|
|
|
|
fi
|
2018-05-09 18:38:17 +02:00
|
|
|
fi
|
2018-05-09 16:43:45 +02:00
|
|
|
fi
|
2016-09-30 11:02:51 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-11-19 16:45:15 +01:00
|
|
|
function detect_installed_apps {
|
2018-03-02 23:20:49 +01:00
|
|
|
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
|
2016-11-19 16:45:15 +01:00
|
|
|
|
|
|
|
APPS_AVAILABLE=()
|
|
|
|
APPS_INSTALLED=()
|
|
|
|
APPS_INSTALLED_NAMES=()
|
|
|
|
|
|
|
|
function_check app_variants
|
|
|
|
function_check app_is_installed
|
|
|
|
function_check item_in_array
|
|
|
|
|
|
|
|
# for all the app scripts
|
|
|
|
for filename in $FILES
|
|
|
|
do
|
|
|
|
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
|
|
|
|
|
2018-05-09 18:41:37 +02:00
|
|
|
if [[ $(enough_ram_for_app "$app_name") == "0" ]]; then
|
2018-05-09 18:38:17 +02:00
|
|
|
if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
|
2018-05-11 14:43:54 +02:00
|
|
|
if [[ $(app_not_on_arm "$app_name") != "0" ]]; then
|
|
|
|
if [[ $(app_is_installed "$app_name") == "1" ]]; then
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
|
|
|
|
variants_list=$(app_variants "$filename")
|
|
|
|
if [ ${#variants_list} -gt 0 ]; then
|
|
|
|
APPS_AVAILABLE+=("${app_name}")
|
|
|
|
APPS_INSTALLED_NAMES+=("$app_name")
|
|
|
|
fi
|
2018-05-09 18:38:17 +02:00
|
|
|
fi
|
2018-05-09 16:43:45 +02:00
|
|
|
fi
|
2016-11-19 16:45:15 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-06 17:47:55 +02:00
|
|
|
# creates the APPS_AVAILABLE and APPS_CHOSEN arrays based on
|
|
|
|
# the given variant name
|
|
|
|
function choose_apps_for_variant {
|
2016-09-28 22:26:36 +02:00
|
|
|
variant_name="$1"
|
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check item_in_array
|
|
|
|
function_check app_variants
|
|
|
|
function_check app_is_removed
|
|
|
|
|
2016-10-15 12:03:52 +02:00
|
|
|
if [ ${#variant_name} -eq 0 ]; then
|
|
|
|
echo $"No variant name for choosing apps"
|
|
|
|
exit 237567
|
|
|
|
fi
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
|
2016-09-28 22:26:36 +02:00
|
|
|
|
|
|
|
APPS_CHOSEN=()
|
|
|
|
|
|
|
|
# for all the app scripts
|
|
|
|
for filename in $FILES
|
|
|
|
do
|
|
|
|
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
|
2018-05-09 18:41:37 +02:00
|
|
|
if [[ $(enough_ram_for_app "$app_name") == "0" ]]; then
|
2018-05-09 18:38:17 +02:00
|
|
|
if [[ $(app_not_on_onion_only "$app_name") != "0" ]]; then
|
2018-05-11 14:43:54 +02:00
|
|
|
if [[ $(app_not_on_arm "$app_name") != "0" ]]; then
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then
|
|
|
|
if grep -q "VARIANTS=" "${filename}"; then
|
|
|
|
variants_list=$(app_variants "$filename")
|
|
|
|
if [[ "${variants_list}" == 'all'* || \
|
|
|
|
"${variants_list}" == "$variant_name" || \
|
|
|
|
"${variants_list}" == "$variant_name "* || \
|
|
|
|
"${variants_list}" == *" $variant_name "* || \
|
|
|
|
"${variants_list}" == *" $variant_name" ]]; then
|
|
|
|
if [[ $(app_is_removed "${a}") == "0" ]]; then
|
|
|
|
#echo $"${app_name} chosen"
|
|
|
|
APPS_CHOSEN+=("1")
|
|
|
|
else
|
|
|
|
APPS_CHOSEN+=("0")
|
|
|
|
fi
|
2018-05-09 18:38:17 +02:00
|
|
|
else
|
|
|
|
APPS_CHOSEN+=("0")
|
|
|
|
fi
|
2018-05-09 16:43:45 +02:00
|
|
|
else
|
|
|
|
APPS_CHOSEN+=("0")
|
|
|
|
fi
|
2016-10-01 00:47:08 +02:00
|
|
|
fi
|
2016-09-28 22:26:36 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
function_check get_apps_installed
|
|
|
|
get_apps_installed
|
2016-07-06 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:42:20 +02:00
|
|
|
# show a list of apps which have been chosen
|
2016-07-06 17:47:55 +02:00
|
|
|
function list_chosen_apps {
|
2016-09-28 22:26:36 +02:00
|
|
|
app_index=0
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-09-28 22:26:36 +02:00
|
|
|
do
|
|
|
|
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
|
|
|
|
echo $"${a}"
|
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
app_index=$((app_index+1))
|
2016-09-28 22:26:36 +02:00
|
|
|
done
|
2016-07-06 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 14:21:43 +02:00
|
|
|
function remove_apps {
|
2016-09-28 22:26:36 +02:00
|
|
|
app_index=0
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-09-28 22:26:36 +02:00
|
|
|
do
|
|
|
|
if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
|
|
|
|
if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
|
2016-10-26 00:04:56 +02:00
|
|
|
echo $"Removing users for application: ${a}"
|
|
|
|
|
|
|
|
function_check remove_users_for_app
|
2018-03-02 23:20:49 +01:00
|
|
|
remove_users_for_app "${a}"
|
2016-10-26 00:04:56 +02:00
|
|
|
|
2016-09-28 22:26:36 +02:00
|
|
|
echo $"Removing application: ${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
|
|
|
function_check app_load_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
app_load_variables "${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
|
|
|
function_check remove_app
|
2018-03-02 23:20:49 +01:00
|
|
|
remove_app "${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
function_check "remove_${a}"
|
|
|
|
"remove_${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
2016-09-28 22:26:36 +02:00
|
|
|
echo $"${a} was removed"
|
|
|
|
fi
|
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
app_index=$((app_index+1))
|
2016-09-28 22:26:36 +02:00
|
|
|
done
|
2016-09-30 18:30:32 +02:00
|
|
|
update_installed_apps_list
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 18:20:04 +02:00
|
|
|
function install_apps_interactive {
|
|
|
|
echo $"Interactive installer"
|
|
|
|
app_index=0
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-10-15 18:20:04 +02:00
|
|
|
do
|
|
|
|
if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
|
|
|
|
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
|
|
|
|
# interactively obtain settings for this app
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(function_exists "install_interactive_${a}") == "1" ]]; then
|
|
|
|
"install_interactive_${a}"
|
2016-10-15 18:20:04 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
app_index=$((app_index+1))
|
2016-10-15 18:20:04 +02:00
|
|
|
done
|
|
|
|
echo $"Interactive settings complete"
|
|
|
|
}
|
|
|
|
|
2016-10-26 00:04:56 +02:00
|
|
|
function user_added_to_app {
|
|
|
|
user_name="$1"
|
|
|
|
app_name="$2"
|
|
|
|
|
|
|
|
if [[ $(is_valid_user "$user_name") == "1" ]]; then
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(function_exists "add_user_${app_name}") == "1" ]]; then
|
|
|
|
if grep -Fxq "${app_name}_${user_name}" "$APP_USERS_FILE"; then
|
2016-10-26 00:04:56 +02:00
|
|
|
echo "1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_users_after_install {
|
|
|
|
app_name="$1"
|
|
|
|
|
|
|
|
read_config_param MY_USERNAME
|
|
|
|
|
|
|
|
# ensure a minimum password length
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ ! "$MINIMUM_PASSWORD_LENGTH" ]; then
|
2016-10-26 00:04:56 +02:00
|
|
|
MINIMUM_PASSWORD_LENGTH=20
|
|
|
|
fi
|
|
|
|
if [ ${#MINIMUM_PASSWORD_LENGTH} -lt 20 ]; then
|
|
|
|
MINIMUM_PASSWORD_LENGTH=20
|
|
|
|
fi
|
|
|
|
|
|
|
|
ADMIN_USERNAME=$(get_completion_param "Admin user")
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ ! "$ADMIN_USERNAME" ]; then
|
2016-10-26 00:04:56 +02:00
|
|
|
ADMIN_USERNAME=$MY_USERNAME
|
|
|
|
fi
|
|
|
|
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
2016-11-12 14:59:33 +01:00
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
|
|
if [[ "$USERNAME" != "$ADMIN_USERNAME" ]]; then
|
|
|
|
if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then
|
|
|
|
valstr=$"Login for user ${USERNAME}="
|
2016-11-20 16:21:54 +01:00
|
|
|
app_password="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
2018-03-02 23:20:49 +01:00
|
|
|
"add_user_${app_name}" "${USERNAME}" "${app_password}"
|
|
|
|
echo "${app_name}_${USERNAME}" >> "$APP_USERS_FILE"
|
2016-10-26 00:04:56 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_users_for_app {
|
|
|
|
app_name="$1"
|
|
|
|
|
|
|
|
read_config_param MY_USERNAME
|
|
|
|
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
2016-11-12 14:59:33 +01:00
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
|
|
if [[ "$USERNAME" != "$MY_USERNAME" ]]; then
|
|
|
|
if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "1" ]]; then
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(function_exists "remove_user_${app_name}") == "1" ]]; then
|
|
|
|
"remove_user_${app_name}" "${USERNAME}"
|
2016-11-12 14:59:33 +01:00
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
sed -i "/${app_name}_${USERNAME}/d" "$APP_USERS_FILE"
|
2016-10-26 00:04:56 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-07-06 14:21:43 +02:00
|
|
|
function install_apps {
|
2016-09-30 12:25:05 +02:00
|
|
|
is_interactive=$1
|
2016-09-30 20:22:10 +02:00
|
|
|
|
2016-10-19 11:50:22 +02:00
|
|
|
APP_INSTALLED_SUCCESS=1
|
|
|
|
|
2016-10-01 10:48:57 +02:00
|
|
|
# interactive install configuration for each app
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ "${is_interactive}" ]; then
|
2016-10-15 18:20:04 +02:00
|
|
|
install_apps_interactive
|
2016-10-01 10:48:57 +02:00
|
|
|
fi
|
2016-09-30 20:22:10 +02:00
|
|
|
|
2016-10-01 10:48:57 +02:00
|
|
|
# now install the apps
|
2016-09-30 20:22:10 +02:00
|
|
|
app_index=0
|
2018-03-08 15:38:15 +01:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for a in ${APPS_AVAILABLE[@]}
|
2016-09-30 20:22:10 +02:00
|
|
|
do
|
2016-12-21 20:28:35 +01:00
|
|
|
if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
|
2016-09-30 20:22:10 +02:00
|
|
|
if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
|
2017-01-03 15:07:54 +01:00
|
|
|
|
|
|
|
# remove any temp files
|
|
|
|
rm -rf /tmp/*
|
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
if [ "${is_interactive}" ]; then
|
2016-10-01 10:48:57 +02:00
|
|
|
# clears any removal indicator
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check reinstall_app
|
2018-03-02 23:20:49 +01:00
|
|
|
reinstall_app "${a}"
|
2016-10-01 10:48:57 +02:00
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check app_load_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
app_load_variables "${a}"
|
2016-10-05 23:33:41 +02:00
|
|
|
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(app_is_installed "${a}") == "1" ]]; then
|
2016-10-01 18:38:07 +02:00
|
|
|
echo $"Upgrading application from interactive: ${a}"
|
2018-03-02 23:20:49 +01:00
|
|
|
"upgrade_${a}"
|
2016-10-01 18:38:07 +02:00
|
|
|
echo $"${a} was upgraded from interactive"
|
|
|
|
else
|
|
|
|
echo $"Installing application from interactive: ${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=
|
2018-03-02 23:20:49 +01:00
|
|
|
"install_${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
if [ $APP_INSTALLED ]; then
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check app_save_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
app_save_variables "${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
2016-10-26 00:04:56 +02:00
|
|
|
function_check add_users_after_install
|
2018-03-02 23:20:49 +01:00
|
|
|
add_users_after_install "${a}"
|
2016-10-26 00:04:56 +02:00
|
|
|
|
2016-11-30 10:41:56 +01:00
|
|
|
function_check lockdown_permissions
|
|
|
|
lockdown_permissions
|
2016-11-29 21:49:11 +01:00
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check install_completed
|
2018-03-02 23:20:49 +01:00
|
|
|
install_completed "${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
echo $"${a} was installed from interactive"
|
|
|
|
else
|
2018-03-02 23:20:49 +01:00
|
|
|
echo "Failed to install: ${a}" >> "/var/log/${PROJECT_NAME}.log"
|
2016-10-19 11:50:22 +02:00
|
|
|
APP_INSTALLED_SUCCESS=
|
2016-10-10 20:11:33 +02:00
|
|
|
echo $"${a} was not installed from interactive"
|
|
|
|
fi
|
2016-10-01 18:38:07 +02:00
|
|
|
fi
|
2016-09-30 23:50:16 +02:00
|
|
|
else
|
2016-10-01 10:48:57 +02:00
|
|
|
# check if the app was removed
|
2018-03-02 23:20:49 +01:00
|
|
|
if [[ $(app_is_removed "${a}") == "0" ]]; then
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check app_load_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
app_load_variables "${a}"
|
|
|
|
if [[ $(app_is_installed "${a}") == "1" ]]; then
|
2016-10-01 18:38:07 +02:00
|
|
|
echo $"Upgrading application: ${a}"
|
2018-03-02 23:20:49 +01:00
|
|
|
"upgrade_${a}"
|
2016-10-01 18:38:07 +02:00
|
|
|
echo $"${a} was upgraded"
|
|
|
|
else
|
|
|
|
echo $"Installing application: ${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=
|
2018-03-02 23:20:49 +01:00
|
|
|
"install_${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
if [ $APP_INSTALLED ]; then
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check app_save_variables
|
2018-03-02 23:20:49 +01:00
|
|
|
app_save_variables "${a}"
|
2016-10-15 14:59:56 +02:00
|
|
|
|
2016-10-26 00:04:56 +02:00
|
|
|
function_check add_users_after_install
|
2018-03-02 23:20:49 +01:00
|
|
|
add_users_after_install "${a}"
|
2016-10-26 00:04:56 +02:00
|
|
|
|
2016-11-30 10:41:56 +01:00
|
|
|
function_check lockdown_permissions
|
|
|
|
lockdown_permissions
|
2016-11-29 21:49:11 +01:00
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check install_completed
|
2018-03-02 23:20:49 +01:00
|
|
|
install_completed "${a}"
|
2016-10-10 20:11:33 +02:00
|
|
|
echo $"${a} was installed"
|
|
|
|
else
|
2018-03-02 23:20:49 +01:00
|
|
|
echo "Failed to install: ${a}" >> "/var/log/${PROJECT_NAME}.log"
|
2016-10-19 11:50:22 +02:00
|
|
|
APP_INSTALLED_SUCCESS=
|
2016-10-10 20:11:33 +02:00
|
|
|
echo $"${a} was not installed"
|
|
|
|
fi
|
2016-10-01 18:38:07 +02:00
|
|
|
fi
|
2016-09-30 23:50:16 +02:00
|
|
|
else
|
|
|
|
echo $"${a} has been removed and so will not be reinstalled"
|
|
|
|
fi
|
|
|
|
fi
|
2016-09-28 22:26:36 +02:00
|
|
|
fi
|
2016-12-21 20:28:35 +01:00
|
|
|
fi
|
2018-03-02 23:20:49 +01:00
|
|
|
app_index=$((app_index+1))
|
2016-09-28 22:26:36 +02:00
|
|
|
done
|
2016-09-30 20:22:10 +02:00
|
|
|
|
2016-10-15 14:59:56 +02:00
|
|
|
function_check update_installed_apps_list
|
2016-09-30 18:30:32 +02:00
|
|
|
update_installed_apps_list
|
2016-07-06 14:21:43 +02:00
|
|
|
}
|
2016-07-06 15:43:20 +02:00
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|