summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/local/bin/tails-upgrade-frontend-wrapper
blob: c6176a283549a63b8987b45db682ccb303840d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

CMD=$(basename ${0})

. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

TORDATE_DIR=/var/run/tordate
TORDATE_DONE_FILE="${TORDATE_DIR}/done"
INOTIFY_TIMEOUT=60
MIN_MEMFREE=$((125 * 1024))
MIN_TOTAL_MEMFREE=$((500 * 1024))
RUN_AS_USER=tails-upgrade-frontend

### Functions

error () {
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>

${@}"
    echo "${cli_text}" >&2
    zenity --error --title "" --text "${dialog_text}"
    exit 1
}

check_free_memory () {
   local min_memfree min_total_memfree memfree buffers cached total_memfree
   local errormsg

   min_memfree="$1"
   min_total_memfree="$2"

   memfree=$(awk '/^MemFree:/{print $2}' /proc/meminfo)
   buffers=$(awk '/^Buffers:/{print $2}' /proc/meminfo)
   cached=$(awk '/^Cached:/{print $2}' /proc/meminfo)
   total_memfree=$(($memfree + $buffers + $cached))

   errormsg="`gettext \"<b>Not enough memory available to check for upgrades.</b>

Make sure this system satisfies the requirements for running Tails.
See file:///usr/share/doc/tails/website/doc/about/requirements.en.html

Try to restart Tails to check for upgrades again.

Or do a manual upgrade.
See https://tails.boum.org/doc/first_steps/upgrade#manual\"`"

   if [ "$memfree" -lt "$MIN_MEMFREE" ] ; then
      echo "Only $memfree MemFree, while $MIN_MEMFREE is needed." >&2
      error "$errormsg"
   fi

   if [ "$total_memfree" -lt "$MIN_TOTAL_MEMFREE" ] ; then
      echo "Only $total_memfree MemFree + Buffers + Cached, while $MIN_TOTAL_MEMFREE is needed." >&2
      error "$errormsg"
   fi
}

### Main

while ! sudo -n -u debian-tor /usr/local/sbin/tor-has-bootstrapped ; do
   sleep 10
done

sleep 30

check_free_memory "$MIN_MEMFREE" "$MIN_TOTAL_MEMFREE"

# Go to a place where everyone, especially Archive::Tar::Wrapper called by
# tails-install-iuk, can chdir back after it has chdir'd elsewhere to do
# its job.
cd /

xhost +SI:localuser:"$RUN_AS_USER"
if [ $# -gt 0 ] ; then
   gksudo -u "$RUN_AS_USER" "/usr/bin/tails-upgrade-frontend $@"
else
   gksudo -u "$RUN_AS_USER" /usr/bin/tails-upgrade-frontend
fi
xhost -SI:localuser:"$RUN_AS_USER"