Ticket #8945: Bootscript

File Bootscript, 4.2 KB (added by dsjonny, 12 years ago)
Line 
1## The system's main boot script.
2
3##
4## Some functions used by the main script
5##
6
7# launch <executable path> [ <thread to wait for> [ <program args> ] ]
8
9launch() {
10 toLaunch="$1"
11 shift
12 toWaitFor="$1"
13 (( $# )) && shift
14 if [ -f "/boot/$toLaunch" ]
15 then
16 "/boot/$toLaunch" $* &
17 [ "$toWaitFor" != "" ] && waitfor "$toWaitFor"
18 return 1
19 else
20 echo There is no "$toLaunch"
21 fi
22 return 0
23}
24
25# launchscript <script path>
26
27launchscript() {
28 if [ -f "/boot/$1" ]
29 then
30 . "/boot/$1"
31 fi
32}
33
34# runprog <executable path>
35
36runprog() {
37 if [ -f "/boot/$1" ]
38 then
39 "/boot/$1"
40 return 1
41 else
42 echo There is no "$1"
43 fi
44 return 0
45}
46
47##
48## Main script starts here
49##
50
51# Set up stdin/out/err to nirvana
52
53exec </dev/null
54exec >/dev/null 2>&1
55
56# Standard locations of boot files
57SCRIPTS=system/boot
58SERVERS=system/servers
59
60# clean the shared memory dir
61shmDir=/var/shared_memory
62rm -rf $shmDir
63mkdir -p $shmDir
64chmod 777 $shmDir
65
66# Set up the environment
67
68export SAFEMODE=`/bin/safemode`
69
70launchscript $SCRIPTS/SetupEnvironment
71
72# If the boot volume is a CD we use another script
73isReadOnly=`/bin/isvolume -readonly-partition /boot`
74if [ "$isReadOnly" = "yes" ]; then
75 # block the CD tray (avoid accidental ejection)
76 # This option stays 'on' even if we continue booting to the desktop.
77 /bin/eject -b /boot
78else
79 # Sets timezone etc.
80 runprog system/bin/clockconfig
81fi
82
83# Create /tmp dir, and make sure it's empty
84
85TMPDIR=/boot/common/cache/tmp
86if [ ! -d $TMPDIR ]; then
87 mkdir -f $TMPDIR
88 chmod a+rwx $TMPDIR
89else
90 rm -rf $TMPDIR/*
91fi
92
93
94# Launch servers
95
96# We must wait for the app_server and registrar to be ready
97launch $SERVERS/registrar _roster_thread_ # launch registrar
98
99launch $SERVERS/debug_server # launch debug_server
100
101# Init Network
102if [ "$SAFEMODE" != "yes" ]; then
103 launch $SERVERS/net_server # launch net_server
104fi
105
106launch $SERVERS/app_server picasso # launch app_server
107
108if [ "$SAFEMODE" != "yes" ]; then
109 launch $SERVERS/syslog_daemon
110 waitfor _input_server_event_loop_ # wait for input devices
111fi
112
113# Now ask the user if he wants to run the Installer or continue to the Desktop.
114if [ "$isReadOnly" = "yes" ]; then
115 # Create Installer link (using the write overlay)
116 ln -sf /boot/system/apps/Installer /boot/home/Desktop/Installer
117
118 /bin/ReadOnlyBootPrompt
119 if [ $? -eq 0 ]; then
120 launchscript $SCRIPTS/Bootscript.cd
121 exit 0 # and return
122 fi
123else
124 if [ ! -f '/boot/home/config/settings/Local settings' ]; then
125 ln -sf /boot/system/apps/Installer /boot/home/Desktop/Installer
126
127 /bin/ReadOnlyBootPrompt
128 if [ $? -eq 0 ]; then
129 launchscript $SCRIPTS/Bootscript.cd
130 exit 0 # and return
131 fi
132 fi
133fi
134
135
136if [ -e /etc/users ]; then
137 # TODO: system/Login needs to be fixed to launch the mount_server!
138 launch system/Login
139 # nothing more
140else
141 cd /boot/home
142
143 launch $SERVERS/mount_server
144 waitfor -m application/x-vnd.Haiku-mount_server
145 # delay the boot script until all previous volumes have been mounted
146 hey -s mount_server DO InitialScan
147
148 launch system/Tracker
149 launch system/Deskbar
150fi
151
152if [ "$SAFEMODE" != "yes" ]; then
153 launch $SERVERS/media_server
154 launch $SERVERS/midi_server
155fi
156
157# Launch Print Server
158if [ "$SAFEMODE" != "yes" ]; then
159 launch $SERVERS/print_server
160fi
161
162# Launch Mail Daemon (if enabled on startup)
163if [ "$SAFEMODE" != "yes" ]; then
164 launch $SERVERS/mail_daemon "" -E
165fi
166
167# Launch CDDB Daemon
168if [ "$SAFEMODE" != "yes" ]; then
169 launch $SERVERS/cddb_daemon ""
170fi
171
172# Launch Notification Server
173if [ "$SAFEMODE" != "yes" ]; then
174 launch $SERVERS/notification_server ""
175fi
176
177# Launch Power Daemon
178if [ "$SAFEMODE" != "yes" ]; then
179 launch $SERVERS/power_daemon ""
180fi
181
182# Check for daylight saving time
183launch system/bin/dstcheck
184
185# Synchronize network time
186launch system/preferences/Time "" --update
187
188if [ "$SAFEMODE" != "yes" ]; then
189 # Start user boot script
190 if [ -f $HOME/config/boot/UserBootscript ]; then
191 . $HOME/config/boot/UserBootscript
192 fi
193fi
194
195# Check for fresh install and run post install scripts.
196postInstallDir=/boot/common/boot/post_install
197freshInstallIndicator=/boot/common/settings/fresh_install
198if [ -e $freshInstallIndicator ]; then
199 # wait a moment for things to calm down a bit
200 sleep 3
201
202 # execute scripts
203 for f in $postInstallDir/*.sh; do
204 if [ -f $f ]; then
205 echo "Running post install script $f ..." > /dev/dprintf
206 $f
207 fi
208 done
209
210 sync
211 rm $freshInstallIndicator
212fi