-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdm.sh
executable file
·116 lines (100 loc) · 2.67 KB
/
fdm.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
107
108
109
110
111
112
113
114
115
# FDM, feline display manager is a fork of
# tdm, tbk display manager, or tiny display manager.
# It is a session selector after login.
# It links the starting script to default and start
# the startx script.
fallback(){
if [[ -n $1 ]]
then echo -e "\033[31;1m(-) ERROR: $1\033[0m"
fi
exec $SHELL
}
warning(){
if [[ -n $1 ]]
then echo -e "\033[31;1m/!\\ WARNING: $1\033[0m"
fi
}
# started from startx, so start session
if [[ -n $1 && $1 = "--xstart" ]]
then
if [[ -f "${CONFDIR}/fdmexit" ]]
then . "${CONFDIR}/fdmexit"
fi
if [[ -x "/tmp/fdm_last" ]]
then exec /tmp/fdm_last
else
exec "${DEFAULT}"
fi
fi
# check for a 'good' and true tty
(basename $(tty)|grep -q tty) || fallback "Invalid tty"
# X started, informe and continue
# X can be started few times from different tty
if [ $(pgrep X) ]
then
warning 'X already started.'
ps aux | grep "Xorg" | grep -v "grep" | while read LINE
do
echo -e "\t- X started by user \"$(echo $LINE | tr -s ' ' | cut -d ' ' -f1)\" from tty \"$(echo $LINE | tr -s ' ' | cut -d ' ' -f7)\" on display \"$(echo $LINE | tr -s ' ' | cut -d ' ' -f14)\"."
done
read -p "Press enter to continue ..."
fi
# build confdir
if [ ! -d "${CONFDIR}" ]
then fdmctl init
fi
# otherwise, run as the session chosen script
if [[ -f "${CONFDIR}/fdminit" ]]
then source "${CONFDIR}/fdminit"
fi
let XID=0
let WID=0
let TOTAL=0
sessions=()
if [ $UI = "ncurses" ] && [ $(type dialog 2>/dev/null) ]
then CUR_UI="fdm_ncurses"
else CUR_UI="fdm_text"
fi
source fdm_core
${CUR_UI}
rm -f /tmp/fdm_last
if [[ (-n $sid) && ($sid -lt $TOTAL) && ($sid -ge $WID) ]]
then #extra session
exec ${sessions[$sid]}
elif [[ (-n $sid) && ($sid -lt $WID) && ($sid -ge $XID) ]]
then #Wayland session
if [[ ${SAVELAST} -ne 0 ]]
then
ln -sf ${sessions[${sid}]} "${DEFAULT}"
else
ln -sf ${sessions[${sid}]} "/tmp/fdm_last"
fi
exec ${sessions[$sid]}
elif [[ (-n $sid) && ($sid -lt $XID) && ($sid -ge 0) ]]
then #X session
if [[ ${SAVELAST} -ne 0 ]]; then
ln -sf ${sessions[${sid}]} "${DEFAULT}"
else
ln -sf ${sessions[${sid}]} "/tmp/fdm_last"
fi
if [[ $# -gt 0 ]] #if there are parameters to send to startx, send them
then startx ${sessions[$sid]} $*
else startx ${sessions[$sid]}
logout
else #Wrong session value
echo "Unknown value,load default."
if [ -x "${DEFAULT}" ]
then
#X session
if [[ (${DEF_ID} -lt $XID) && ($DEF_ID -ge 0) ]]
then if [[ $# -gt 0 ]] #if there are parameters to send to startx, send them
then startx ${DEFAULT} $*
else startx ${DEFAULT}
#Wayland session
else ${DEFAULT}
logout
fi
else
fallback "Session not defined,fallback."
fi
fi