2 # Filename: grml-screen
3 # Purpose: wrapper for screen to start with appropriate configuration
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 # export variable USER for use withing GNU screen:
15 sudo chown $USER.tty $TTY
17 # FIXME: fix for screen race-conditions
18 PID_FILE_="/var/lock/grml-screen"
19 PID_FILE_CREATED_="false"
21 if [ ! -d "/var/run/screen/S-$USER" ]; then
22 # no /var/run/screen/S-$USER and possible no /var/run/screen either -> locking
23 for i in `seq 40`; do # 40*0.25 = 10 seconds
24 if lockfile-create --retry 0 $PID_FILE_; then
25 echo $MY_PID_ >$PID_FILE_
26 PID_FILE_CREATED_="true"
29 PID_FILE_CREATED_="error"
34 if [ $PID_FILE_CREATED_ = "true" ]; then
37 for i in `seq 40`; do # 40*0.25 = 10 seconds
38 if [ ! -d "/var/run/screen/S-$USER" ]; then
39 sleep 0.25 # educated guess
44 if [ `cat $PID_FILE_` = $MY_PID_ ]; then
46 lockfile-remove $PID_FILE_
50 elif [ $PID_FILE_CREATED_ = "error" ]; then
51 SLEEP_TIME_="$(( $$ % 5 * 5 + 5 ))"
52 echo "grml-screen: Error could not create lockfile! (sleeping for $SLEEP_TIME_)" >&2
54 elif [ $PID_FILE_CREATED_ = "false" ]; then
55 echo "nothing to do" &>/dev/null
57 echo "grml-screen: internal error - PID_FILE_CREATED_ == \"$PID_FILE_CREATED_\"" >&2
60 # now run screen with config
61 cd $HOME # important for e.g. hardcopy-feature
62 # do we have a utf8 enabled terminal?
63 [ -x /usr/bin/vt-is-UTF8 ] && /usr/bin/vt-is-UTF8 -q && UTF='-U'
64 if [ `id -u` = 0 ] ; then
65 exec screen $UTF -c /etc/grml/screenrc
66 elif [ -r "$HOME/.screenrc" ] ; then
67 exec screen $UTF -c "$HOME/.screenrc"
69 exec screen $UTF -c /etc/grml/screenrc_grml
72 ## END OF FILE #################################################################