1
+ # Copyright (c) 2016 The crouton Authors. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+ ## Filename: /etc/init/crouton.conf
6
+ ## NOTE: 'rootfs' verification needs to be removed.
7
+
8
+ ## crouton chroot - Start session
9
+ ##
10
+ ## This will start a (crouton) chroot Desktop Environment session
11
+
12
+ description "Crouton Chroot Session daemon"
13
+ author "github/DennisLfromGA"
14
+
15
+ ## Choose when the crouton chroot will be started - 4 choices below -
16
+ ## NOTE: use only 1, prepend the others with the remark character: #
17
+
18
+ #start on starting ui # 1st - starts when the user interface begins
19
+ # + only 1 chroot will run in this mode
20
+ # + must use XMETHOD: 'xorg'
21
+
22
+ #start on started ui # 2nd - starts when the user interface appears
23
+ # + only 1 chroot will run in this mode
24
+ # + must use XMETHOD: 'xorg'
25
+
26
+ #start on login-prompt-visible # 3rd - starts when the login screen appears
27
+ # + only 1 chroot will run in this mode
28
+ # + must use XMETHOD: 'xorg'
29
+
30
+ start on start-user-session # 4th - starts when the user logs in - DEFAULT
31
+ # + multiple chroots could run in this mode
32
+ # + can use either XMETHOD: 'xiwi' or 'xorg'
33
+ # + ensures user ~/Downloads is available
34
+
35
+ stop on stopping ui or starting halt or starting reboot
36
+
37
+ ############################################################################
38
+ ## NOTE: This job can be controlled externally by placing the file ##
39
+ #+ 'crouton.init' in the User's Downloads folder on a per User ##
40
+ #+ basis or in the chroots parent folder per system with the ##
41
+ #+ following six optional variables set: ##
42
+ #+ 1) DELAY 2) CHROOT 3) START_DE 4) CHROOT_APP 5) XMETHOD 6) RUN_STATE ##
43
+ ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
44
+ #+ [ the 'env ' prefix must be omitted in the control file ] ##
45
+ ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
46
+ ## Start of control file variables ##
47
+ ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
48
+ env DELAY=10 # delay desired number of seconds before starting ##
49
+ env CHROOT=xenial # enter desired chroot to start ##
50
+ env START_DE=startxfce4 # enter desired Desktop Envirnoment to use ##
51
+ env CHROOT_APP=none # enter desired chroot application to run ##
52
+ env XMETHOD=default # enter temporary X-Window Envirnoment to use ##
53
+ env RUN_STATE=y # change to 'n' to disable running $CHROOT ##
54
+ ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
55
+ ## End of control file variables ##
56
+ ############################################################################
57
+
58
+ ##########################################################################
59
+ ## System control parameters ##
60
+ ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
61
+ env DEBUG=on # change to 'on' for DEBUGGING output ##
62
+ env MASTER_SW=on # change to 'off' to override running any $CHROOT ##
63
+ env MULTIPLES=on # change to 'off' to allow running only 1 $CHROOT ##
64
+ ##########################################################################
65
+
66
+ script
67
+
68
+ PID="$$"
69
+ touch /tmp/$UPSTART_JOB-$PID.log
70
+
71
+ ## For output, use 'grep $PID /var/log/messages'
72
+ LOGGER="logger -p local3.info -t $UPSTART_JOB($PID)"
73
+
74
+ trap "$LOGGER '### Exiting...'" EXIT
75
+
76
+ $LOGGER "###############"
77
+ $LOGGER "### Starting..."
78
+ if [ "$DEBUG" = 'on' ]; then
79
+ exec >> /tmp/$UPSTART_JOB-$PID.log 2>&1
80
+ set -x
81
+ $LOGGER "*** DEBUGGING turned ON."
82
+ $LOGGER "*** See '/tmp/$UPSTART_JOB-$PID.log' for output."
83
+ else
84
+ $LOGGER "*** DEBUGGING is OFF."
85
+ fi
86
+
87
+ if [ "$MASTER_SW" = "off" ]; then
88
+ ## No chroots will run even if allowed by external control file(s).
89
+ $LOGGER "!!! The MASTER_SW has been turned OFF"
90
+ $LOGGER "No CHROOTS will run - period. Exiting."
91
+ $LOGGER "###############"
92
+ $LOGGER "### Ending....."
93
+ $LOGGER "###############"
94
+ exit 255
95
+ fi
96
+
97
+ MULTS="`pgrep -l crouton|head -n 1`"
98
+ if [ "$MULTIPLES" = "off" ]; then
99
+ ## Multiple chroots cannot be run when more than one user is logged in.
100
+ if [ -n "$MULTS" ]; then
101
+ $LOGGER "!!! MULTIPLE CHROOTS has been turned OFF"
102
+ $LOGGER "No more CHROOTS will be run now. Exiting."
103
+ $LOGGER "###############"
104
+ $LOGGER "### Ending....."
105
+ $LOGGER "###############"
106
+ exit 255
107
+ fi
108
+ elif [ -n "$MULTS" ]; then
109
+ $LOGGER "*** MULTIPLE CHROOTS is turned ON"
110
+ $LOGGER "Now running an additional CHROOT."
111
+ $LOGGER "###############"
112
+ fi
113
+
114
+ $LOGGER "##- Main checks started."
115
+ if [ -d /var/crouton/chroots ]; then
116
+ ## Uses the @drinkcat 'separate_partition' branch - as DEFAULT
117
+ CROUTON_BIN=/var/crouton/bin
118
+ CROUTON_CHROOTS=/var/crouton/chroots
119
+ elif [ -d /usr/local/chroots ]; then
120
+ ## Uses the @dnschneid 'master' branch
121
+ CROUTON_BIN=/usr/local/bin
122
+ CROUTON_CHROOTS=/usr/local/chroots
123
+ else
124
+ ## Nothing found...
125
+ $LOGGER "*** Crouton 'chroots' directory is missing. Aborting!"
126
+ $LOGGER "###############"
127
+ exit 1
128
+ fi
129
+
130
+ if [ ! -d $CROUTON_BIN ]; then
131
+ $LOGGER "*** Crouton 'bin' directory is missing. Aborting!"
132
+ $LOGGER "###############"
133
+ exit 1
134
+ fi
135
+
136
+ $LOGGER "*** Crouton 'bin' directory is $CROUTON_BIN"
137
+ $LOGGER "*** Crouton 'chroots' directory is $CROUTON_CHROOTS"
138
+
139
+ $LOGGER "##- Check for external control."
140
+ USER_DOWNLOADS="/home/chronos/user/Downloads"
141
+ DOWNLOADS_INIT="$USER_DOWNLOADS/${UPSTART_JOB}.init"
142
+ CHROOTS_PARENT=`dirname $CROUTON_CHROOTS`
143
+ CROUTON_INIT="$CHROOTS_PARENT/${UPSTART_JOB}.init"
144
+ if [ -r $DOWNLOADS_INIT ]; then INIT_FILE="$DOWNLOADS_INIT"
145
+ elif [ -r $CROUTON_INIT ]; then INIT_FILE="$CROUTON_INIT"; fi
146
+ if [ -r $INIT_FILE ] && [ -s $INIT_FILE ]; then
147
+ $LOGGER "*** External control enabled via '$INIT_FILE' file."
148
+ ## Pull in variables from external control file
149
+ Delay="` awk -F= '/^DELAY=/ {print $2; exit}' "$INIT_FILE"`"
150
+ Chroot="` awk -F= '/^CHROOT=/ {print $2; exit}' "$INIT_FILE"`"
151
+ Start_DE="` awk -F= '/^START_DE=/ {print $2; exit}' "$INIT_FILE"`"
152
+ Chroot_App="` awk -F= '/^CHROOT_APP=/ {print $2; exit}' "$INIT_FILE"`"
153
+ XMethod="` awk -F= '/^XMETHOD=/ {print $2; exit}' "$INIT_FILE"`"
154
+ Run_state="` awk -F= '/^RUN_STATE=/ {print $2; exit}' "$INIT_FILE"`"
155
+
156
+ if [ -n "$Delay" -a "$Delay" != "$DELAY" ]; then
157
+ $LOGGER "##* DELAY changed from: '$DELAY' to '$Delay'."
158
+ DELAY="$Delay"
159
+ fi
160
+
161
+ if [ -n "$Chroot" -a "$Chroot" != "$CHROOT" ]; then
162
+ $LOGGER "##* CHROOT changed from: '$CHROOT' to '$Chroot'."
163
+ CHROOT="$Chroot"
164
+ fi
165
+
166
+ if [ -n "$Start_DE" -a "$Start_DE" != "$START_DE" ]; then
167
+ $LOGGER "##* START_DE changed from: '$START_DE' to '$Start_DE'."
168
+ START_DE="$Start_DE"
169
+ fi
170
+
171
+ if [ -n "$Chroot_App" -a "$Chroot_App" != "$CHROOT_APP" ]; then
172
+ $LOGGER "##* CHROOT_APP: '$Chroot_App' will be executed."
173
+ CHROOT_APP="$Chroot_App"
174
+ else
175
+ CHROOT_APP=
176
+ fi
177
+
178
+ if [ -n "$XMethod" -a "$XMethod" != "$XMETHOD" ]; then
179
+ $LOGGER "##* XMETHOD changed from: '$XMETHOD' to '$XMethod'."
180
+ XMETHOD=$XMethod
181
+ elif [ "$XMETHOD" != "default" ]; then
182
+ $LOGGER "##* XMETHOD changed from: 'default' to '$XMETHOD'."
183
+ else
184
+ $LOGGER "##* XMETHOD unchanged - set to '$XMETHOD'."
185
+ fi
186
+
187
+ if [ -n "$Run_state" -a "$Run_state" != "$RUN_STATE" ]; then
188
+ $LOGGER "##* RUN_STATE changed from: '$RUN_STATE' to '$Run_state'."
189
+ RUN_STATE="$Run_state"
190
+ fi
191
+ else
192
+ $LOGGER "### NO external control file found, using internal defaults."
193
+ fi
194
+
195
+ $LOGGER "##- Secondary checks started."
196
+ if [ ! -d $CROUTON_CHROOTS/$CHROOT ]; then
197
+ $LOGGER "*** Crouton '$CHROOT' directory is missing. Aborting!"
198
+ $LOGGER "###############"
199
+ exit 1
200
+ elif [ ! -s $CROUTON_BIN/$START_DE -o ! -x $CROUTON_BIN/$START_DE ]; then
201
+ $LOGGER "*** Crouton '$START_DE' script is missing. Aborting!"
202
+ $LOGGER "###############"
203
+ exit 1
204
+ fi
205
+
206
+ case $XMETHOD in
207
+ xorg|xiwi*)
208
+ XMARG="-X $XMETHOD"
209
+ ;;
210
+ default)
211
+ XMARG=
212
+ ;;
213
+ *)
214
+ XMARG=
215
+ $LOGGER "##* XMETHOD: '$XMETHOD' is invalid so not set."
216
+ ;;
217
+ esac
218
+
219
+ if [ "$RUN_STATE" = "n" -o "$MASTER_SW" = off ]; then
220
+ $LOGGER "*** The RUN_STATE for chroot '$CHROOT' is DISABLED. Exiting."
221
+ $LOGGER "###############"
222
+ exit 0
223
+ fi
224
+
225
+ $LOGGER "##- Starting main process in $DELAY seconds."
226
+ sleep $DELAY
227
+
228
+ $LOGGER "##$ sudo $CROUTON_BIN/$START_DE -c $CROUTON_CHROOTS -n $CHROOT $XMARG $CHROOT_APP"
229
+ eval sudo $CROUTON_BIN/$START_DE -c $CROUTON_CHROOTS -n "$CHROOT" $XMARG "$CHROOT_APP" \
230
+ || $LOGGER "##- Completed: status $?"
231
+
232
+ $LOGGER "### Ending....."
233
+ $LOGGER "###############"
234
+
235
+ if [ "$DEBUG" = "y" ]; then
236
+ set +x
237
+ fi
238
+
239
+ end script
0 commit comments