-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathsession-run-awesome.sh
executable file
·106 lines (87 loc) · 2.37 KB
/
session-run-awesome.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Gets run via ~/.xinitrc.
#
# Use SIGHUP to reload awesome.
# Use SIGUSR to restart awesome.
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
LOG=/tmp/awesome$DISPLAY.log
# POSIX compatible redirection of stdout/stderr to logfile.
stdout_pipe=$(mktemp --dry-run)
stderr_pipe=$(mktemp --dry-run)
mkfifo "$stdout_pipe"
mkfifo "$stderr_pipe"
tee -a "$LOG" < "$stdout_pipe" & exec 1> "$stdout_pipe"
tee -a "$LOG" >&2 < "$stderr_pipe" & exec 2> "$stderr_pipe"
log() {
echo "$(date '+%F %T') $*"
}
log "== $0 =="
log "PPID:$PPID ($(ps -o args= $PPID))"
unset TERM
unset TMUX
# Make gnome-control-center display everything.
# export XDG_CURRENT_DESKTOP=GNOME
export XDG_CURRENT_DESKTOP=Unity
trap 'log "TRAPPED: USR1, restarting."; loop_restart=1; sleep_restart=0' USR1
trap 'log "TRAPPED: TERM, not restarting."; loop_restart=0' TERM
# Used for logout in awesome WM.
export MY_SESSION_RUN_PID=$$
log "MY_SESSION_RUN_PID=$MY_SESSION_RUN_PID"
cd ~ || exit
sleep_restart=1
while :; do
log "=========== START AWESOME ==========="
date
loop_restart=1
last_start="$(date +%s)"
# Reset sleep when config file changed.
STAT_CMD="stat -L -t $HOME/.config/awesome/rc.lua"
last_stat="$($STAT_CMD)"
# Read any args supplied by "awesome-restart", e.g. another config file.
args_file="/var/run/user/$(id -u)/awesome-restart-args"
if [ -f "$args_file" ]; then
args="$(cat "$args_file")"
echo "Using args: $args"
rm "$args_file"
else
args=
fi
for f in /usr/local/bin/awesome /usr/bin/awesome; do
if [ -x "$f" ]; then
echo "Running: $f $args"
eval "$f $args"
RET=$?
echo "RET: $RET"
if [ "$RET" = 99 ]; then
# custom awesome.quit(99) call to indicate quitting.
loop_restart=0
fi
break
fi
done
if ! ps $PPID 2>/dev/null 1>&2; then
log "Parent PID ($PPID) is gone, not restarting.."
loop_restart=0
elif [ "$loop_restart" = 1 ]; then
# source ~/.xsessionrc
if [ "$(expr $(date +%s) - $last_start)" -lt 2 ]; then
if [ "$($STAT_CMD)" != "$last_stat" ]; then
sleep_restart=0
elif [ "$(expr $sleep_restart \< 100)" = 1 ]; then
sleep_restart=$(expr $sleep_restart + 5)
fi
else
sleep_restart=0
fi
sleep_secs=$(expr 1 + $sleep_restart / 10).$(expr $sleep_restart % 10)
log "===== Restarting in $sleep_secs seconds. ====="
sleep "$sleep_secs"
if [ "$loop_restart" = 1 ]; then
continue
fi
fi
log "Breaking..."
break
done