Skip to content

Commit

Permalink
Improved implementation. When there is enough RAM... On 'enter': inst…
Browse files Browse the repository at this point in the history
…antly start login manager. On 'ctrl + c': instantly abort and do not start login manager. On 'timeout': start login manager. Thanks to 'dh_systemd_start --no-start' we can now use 'StandardInput=tty' and 'read' instead of 'systemd-ask-password'. Now we could even implement an interactive menu at boot (that allows to configure wait time and/or disabling rads). - https://phabricator.whonix.org/T57
  • Loading branch information
Patrick Schleizer committed May 23, 2015
1 parent 6204549 commit c8c94c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
1 change: 1 addition & 0 deletions lib/systemd/system/rads.service
Expand Up @@ -13,6 +13,7 @@ Type=oneshot
ExecStart=/usr/lib/ram_adjusted_desktop_starter/ram_adjusted_desktop_starter
RemainAfterExit=yes
StandardOutput=tty
StandardInput=tty

[Install]
WantedBy=multi-user.target
44 changes: 8 additions & 36 deletions usr/lib/ram_adjusted_desktop_starter/ram_adjusted_desktop_starter
Expand Up @@ -23,14 +23,6 @@ ret: $? | BASH_COMMAND: $BASH_COMMAND | Please report this bug!"

trap "error_handler_rads" ERR

sigterm_rads() {
#echo "[${green}INFO${reset}] [RAM Adjusted Desktop Starter] SIGTERM received!"
true "INFO: [RAM Adjusted Desktop Starter] SIGTERM received!"
}

trap "sigterm_rads" SIGTERM
trap "sigterm_rads" SIGINT

colors() {
## Thanks to:
## http://mywiki.wooledge.org/BashFAQ/037
Expand Down Expand Up @@ -159,17 +151,6 @@ ram-adjusted-desktop-starter() {
export PATH
## }}

if command -v tty >/dev/null 2>&1 ; then
## When started by systemd, there is no stdin connected and `tty` exit code is 1.
if tty --silent ; then
## Likely run during an interactive apt-get upgrade.
if [ "$rads_debug" = "1" ]; then
true "INFO: [RAM Adjusted Desktop Starter] tty detected, not started by systemd, doing nothing."
fi
exit 0
fi
fi

command_v_exit_code="0"
command -v "$rads_display_manager" >/dev/null || { command_v_exit_code="$?" ; true; };

Expand Down Expand Up @@ -247,28 +228,24 @@ here: https://www.whonix.org/wiki/Desktop"
fi

## Fallback.
systemd_ask_password_exit_code="0"
read_exit_code="0"
if [ "$rads_wait" = "0" ]; then
if [ "$rads_debug" = "1" ]; then
true "INFO: Waiting feature disabled."
fi
else
if command -v systemd-ask-password >/dev/null 2>&1 ; then
systemd_ask_password_text="[${green}INFO${reset}] [RAM Adjusted Desktop Starter] Starting login manager \
echo "[${green}INFO${reset}] [RAM Adjusted Desktop Starter] Starting login manager \
(graphical desktop environment) $rads_display_manager in \
$rads_wait_seconds seconds, unless you abort using ctrl + c. \
This can be disabled or configured in /etc/rads.d/ configuration folder."
## systemd-ask-password exit codes:
## 0: no timeout
## 1: timeout
systemd_ask_password_output="$(systemd-ask-password --timeout "$rads_wait_seconds" "$systemd_ask_password_text")" || { systemd_ask_password_exit_code="$?" ; true; };
else
echo "[${green}INFO${reset}] [RAM Adjusted Desktop Starter] running non-interactive, because systemd-ask-password is not available."
echo "[${green}INFO${reset}] [RAM Adjusted Desktop Starter] can be disabled or configured in /etc/rads.d/ configuration folder."
fi
read -t "$rads_wait_seconds" read_input || { read_exit_code="$?" ; true; };
## read exits,
## 0: when enter has been pressed with or without input
## 142: on timeout
## 130: on ctrl + c
fi

if [ "$systemd_ask_password_exit_code" = "0" ] || [ "$systemd_ask_password_exit_code" = "1" ]; then
if [ "$read_exit_code" = "0" ] || [ "$read_exit_code" = "142" ]; then
service_2_exit_code="0"
## There is a /etc/sudoers.d/rads exception for this.
sudo service "$rads_display_manager" status >/dev/null || { service_2_exit_code="$?" ; true; };
Expand All @@ -279,11 +256,6 @@ This can be disabled or configured in /etc/rads.d/ configuration folder."
echo "[${green}INFO${reset}] [RAM Adjusted Desktop Starter] Trying to start login manager \
(graphical desktop environment) $rads_display_manager..."

## Sleep for the look and feel. Users should be able to see "Trying to start login manager..."
sleep_3_exit_code="0"
sleep 5 &
wait "$!" || { sleep_3_exit_code="$?" ; true; };

service_3_exit_code="0"
## There is a /etc/sudoers.d/rads exception for this.
sudo service "$rads_display_manager" start || { service_3_exit_code="$?" ; true; };
Expand Down

0 comments on commit c8c94c3

Please sign in to comment.