tails-upgrade-frontend-wrapper 2.03 KB
Newer Older
1 2
#!/bin/sh

3 4 5 6 7 8
CMD=$(basename ${0})

. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

9 10 11
TORDATE_DIR=/var/run/tordate
TORDATE_DONE_FILE="${TORDATE_DIR}/done"
INOTIFY_TIMEOUT=60
12 13
MIN_MEMFREE=$((200 * 1024))
MIN_TOTAL_MEMFREE=$((500 * 1024))
14
RUN_AS_USER=tails-upgrade-frontend
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

### 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
30
   local errormsg
31 32 33 34 35 36 37 38 39

   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))

Tails developers's avatar
Tails developers committed
40
   errormsg="`gettext \"<b>Not enough memory available to check for upgrades.</b>
41

Tails developers's avatar
Tails developers committed
42 43 44 45 46 47 48
Make sure this system satisfies the requirements for running Tails.
See file:///usr/share/doc/tails/website/doc/about/requirements/index.en.html.

Try to restart Tails and upgrade again.

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

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

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

### Main
62 63 64 65 66 67 68 69 70 71 72

# wait for the $TORDATE_DIR directory to appear
while [ ! -d "$TORDATE_DIR" ]; do
      sleep 10
done

# wait for a guarantee that time is in Tor valid range
while ! [ -e "$TORDATE_DONE_FILE" ]; do
   inotifywait -q -t "$INOTIFY_TIMEOUT" -e create --format %w%f "$TORDATE_DIR"
done

73 74
check_free_memory "$MIN_MEMFREE" "$MIN_TOTAL_MEMFREE"

75
xhost +SI:localuser:"$RUN_AS_USER"
76
gksudo -u "$RUN_AS_USER" "/usr/bin/tails-upgrade-frontend $@"
77
xhost -SI:localuser:"$RUN_AS_USER"