Newer
Older
#!/bin/bash
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Freedom in the Cloud
#
# Keep track of install progress
#
# 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/>.
function app_install_progress_max {
app_filename="$1"
if [ ! -f "$app_filename" ]; then
echo '0'
return
fi
app_install_lines_temp=$(grep -c 'increment_app_install_progress' "$app_filename")
app_install_lines=$((app_install_lines_temp + 1))
function clear_app_install_progress {
if [ -f /root/.app_install_counter ]; then
rm /root/.app_install_counter
fi
# copy the app icon
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin"
if [ ! -f "$webadmin_install_dir/images/installing_app.png" ]; then
cp "/root/${PROJECT_NAME}/img/android-app/${app_name}.png" "$webadmin_install_dir/images/installing_app.png"
chown www-data:www-data "$webadmin_install_dir/images/installing_app.png"
fi
if [ -f /root/.install_counter ]; then
install_counter=$(cat /root/.install_counter)
echo "$install_comment" > /root/.install_comment
install_counter=$((install_counter + 1))
echo -n "$install_counter" > /root/.install_counter
function update_app_install_progress_bar {
if [ ! "${app_name}" ]; then
return
fi
local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local
webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin"
app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"
if [ ! -f "$app_filename" ]; then
if [ ! -f /root/.app_install_counter ]; then
echo -n '1' > /root/.app_install_counter
fi
max_counter=$(app_install_progress_max "$app_filename")
installing_page="$webadmin_install_dir/app_installing_progress.html"
progress_percent=$((progress_counter * 100 / max_counter))
if [ $progress_percent -gt 100 ]; then
progress_percent=100
fi
sed -i "s|<div class=\"w3-container.*|<div class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:${progress_percent}%\">${progress_percent}%</div>|g" "$installing_page"
if ! grep -q 'w3-container w3-blue' "$webadmin_install_dir/index.html"; then
cp "$webadmin_install_dir/index.html" "$webadmin_install_dir/index_app_installing.html"
cp "$installing_page" "$webadmin_install_dir/index.html"
fi
sed -i "s|<div class=\"w3-container.*|<div class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:${progress_percent}%\">${progress_percent}%</div>|g" "$webadmin_install_dir/index.html"
}
function increment_app_install_progress {
if [ -f /root/.app_install_counter ]; then
app_install_counter=$(cat /root/.app_install_counter)
echo "$install_comment" > /root/.app_install_comment
app_install_counter=$((app_install_counter + 1))
echo -n "$app_install_counter" > /root/.app_install_counter
update_app_install_progress_bar
}
# NOTE: deliberately there is no "exit 0"