Skip to content

Commit 4fa6aae

Browse files
committed
reorder
1 parent 1a5f165 commit 4fa6aae

File tree

6 files changed

+512
-1
lines changed

6 files changed

+512
-1
lines changed

autostart/init/crouton.conf

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
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

autostart/init/mnt-crouton.conf

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (c) 2012 The Chromium OS 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+
description "mount CROUTON on /var/crouton"
6+
author "drinkcat & DennisLfromGA"
7+
8+
start on starting boot-services
9+
task
10+
script
11+
# Exits the script with return code $1, spitting out message $@ to stderr
12+
error() {
13+
local ecode="$1"
14+
shift
15+
echo "$*" 1>&2
16+
exit "$ecode"
17+
}
18+
19+
# Find the root device
20+
# Sets:
21+
# - $ROOTDEVICE as the root device (e.g. /dev/sda or /dev/mmcblk0)
22+
# - $ROOTDEVICEPREFIX as a prefix for partitions (/dev/sda, /dev/mmcblk0p)
23+
findrootdevice() {
24+
ROOTDEVICE="`rootdev -d -s`"
25+
26+
if [ -z "$ROOTDEVICE" ]; then
27+
error 1 "Cannot find root device."
28+
fi
29+
30+
if [ ! -b "$ROOTDEVICE" ]; then
31+
error 1 "$ROOTDEVICE is not a block device."
32+
fi
33+
34+
# If $ROOTDEVICE ends with a number (e.g. mmcblk0), partitions are named
35+
# ${ROOTDEVICE}pX (e.g. mmcblk0p1). If not (e.g. sda), they are named
36+
# ${ROOTDEVICE}X (e.g. sda1).
37+
ROOTDEVICEPREFIX="$ROOTDEVICE"
38+
if [ "${ROOTDEVICE%[0-9]}" != "$ROOTDEVICE" ]; then
39+
ROOTDEVICEPREFIX="${ROOTDEVICE}p"
40+
fi
41+
}
42+
43+
# Define CROUTON mountpoint
44+
MOUNTCROUTON='/var/crouton'
45+
# Try to mount the CROUTON partition, if it exists, on $MOUNTCROUTON.
46+
mountcrouton() {
47+
if [ -z "$ROOTDEVICE" ]; then
48+
findrootdevice
49+
fi
50+
51+
local croutonpart="`sudo cgpt find -n -l CROUTON "$ROOTDEVICE"`"
52+
if [ -z "$croutonpart" ]; then
53+
return 1
54+
fi
55+
56+
# Check if crouton is mounted already
57+
if grep -q "^${ROOTDEVICEPREFIX}$croutonpart " /proc/mounts; then
58+
# If mounted, it must be mounted to $mountpoint
59+
60+
if ! grep -q "^${ROOTDEVICEPREFIX}$croutonpart $MOUNTCROUTON " \
61+
/proc/mounts; then
62+
error 1 "Error: CROUTON partition is not mounted on $MOUNTCROUTON."
63+
else
64+
PRIOR=' already'
65+
fi
66+
else
67+
sudo mkdir -p "$MOUNTCROUTON" || error 1 "Cannot create $MOUNTCROUTON."
68+
sudo mount "${ROOTDEVICEPREFIX}$croutonpart" "$MOUNTCROUTON" || \
69+
error 1 "Cannot mount $MOUNTCROUTON"
70+
fi
71+
return 0
72+
}
73+
74+
# Now mount the CROUTON partition
75+
mountcrouton
76+
end script

autostart/local/crouton.init

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
##########################################################################
2+
##* crouton.conf defaults are: ##
3+
# DELAY=10 # delay desired number of seconds before starting ##
4+
# CHROOT=xenial # enter desired chroot to start ##
5+
# START_DE=startxfce4 # enter desired Desktop Envirnoment to use ##
6+
# CHROOT_APP=none # enter desired chroot application to run ##
7+
# XMETHOD=default # enter the desired XMETHOD (xorg,xephyr,xiwi) ##
8+
# RUN_STATE=y # change to 'n' to disable running $CHROOT ##
9+
##########################################################################
10+
11+
###
12+
##############################################################
13+
## Place a '#' in the 1st column before the variable if you ##
14+
#+ don't want to change it from the crouton.conf defaults. ##
15+
## ##
16+
## SEVERAL EXAMPLES ARE GIVEN BELOW FOR YOUR REFERENCE ##
17+
#+ YOU CAN REMOVE THEM IF YOU LIKE TO KEEP THINGS NEAT ##
18+
##############################################################
19+
20+
###
21+
### DELAY: change to desired number of seconds before starting
22+
##* It helps sometimes to give other applicaitons time to initialize.
23+
#--
24+
DELAY=3
25+
26+
###
27+
### CHROOT: change to desired chroot to use
28+
#--
29+
##* chroot(s) in '/var/crouton/chroots': trusty, xenial, wheezy-cb, mdwatson
30+
##! trusty - DE:kde,xbmc
31+
#CHROOT=trusty
32+
##! xenial - DE:gnome,kde,xfce,xbmc
33+
CHROOT=bionic
34+
##! wheezy-cb - DE:xinit,startob
35+
#CHROOT=wheezy-cb
36+
##! mdwatson - DE:elementary
37+
#CHROOT=mdwatson
38+
39+
###
40+
### START_DE: change to desired Desktop Envirnoment to use
41+
#--
42+
#START_DE=startelementary
43+
#START_DE=startkde
44+
#START_DE=startlxde
45+
#START_DE=startgnome
46+
#START_DE=startunity
47+
#START_DE=startxbmc
48+
#START_DE=startxfce4
49+
##! below 'enter-chroot' commonly used with
50+
##! CHROOT_APP=sleep infinity (below) for headless operations.
51+
START_DE=enter-chroot
52+
53+
###
54+
### CHROOT_APP: enter a chroot application to run, used for startxiwi
55+
##* or enter-chroot, etc.
56+
#--
57+
#CHROOT_APP=pidgin
58+
#CHROOT_APP=skype
59+
#CHROOT_APP=xterm
60+
## below 'sleep infinity' commonly used with
61+
## START_DE=enter-chroot (above) for headless operations, etc.
62+
#CHROOT_APP=sleep infinity
63+
CHROOT_APP=/usr/bin/python3 /opt/croutonlauncher/main.py
64+
65+
###
66+
### XMETHOD: Override the default XMETHOD for this session - if installed, some examples shown
67+
#--
68+
#XMETHOD=default
69+
#XMETHOD=xephyr
70+
#XMETHOD=xorg
71+
XMETHOD=xiwi
72+
73+
###
74+
### RUN_STATE: change to 'n' to disable running crouton.conf
75+
#--
76+
RUN_STATE=y

0 commit comments

Comments
 (0)