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 |
|
---|
9 | launch() {
|
---|
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 |
|
---|
27 | launchscript() {
|
---|
28 | if [ -f "/boot/$1" ]
|
---|
29 | then
|
---|
30 | . "/boot/$1"
|
---|
31 | fi
|
---|
32 | }
|
---|
33 |
|
---|
34 | # runprog <executable path>
|
---|
35 |
|
---|
36 | runprog() {
|
---|
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 |
|
---|
53 | exec </dev/null
|
---|
54 | exec >/dev/null 2>&1
|
---|
55 |
|
---|
56 | # Standard locations of boot files
|
---|
57 | SCRIPTS=system/boot
|
---|
58 | SERVERS=system/servers
|
---|
59 |
|
---|
60 | # clean the shared memory dir
|
---|
61 | shmDir=/var/shared_memory
|
---|
62 | rm -rf $shmDir
|
---|
63 | mkdir -p $shmDir
|
---|
64 | chmod 777 $shmDir
|
---|
65 |
|
---|
66 | # Set up the environment
|
---|
67 |
|
---|
68 | export SAFEMODE=`/bin/safemode`
|
---|
69 |
|
---|
70 | launchscript $SCRIPTS/SetupEnvironment
|
---|
71 |
|
---|
72 | # If the boot volume is a CD we use another script
|
---|
73 | isReadOnly=`/bin/isvolume -readonly-partition /boot`
|
---|
74 | if [ "$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
|
---|
78 | else
|
---|
79 | # Sets timezone etc.
|
---|
80 | runprog system/bin/clockconfig
|
---|
81 | fi
|
---|
82 |
|
---|
83 | # Create /tmp dir, and make sure it's empty
|
---|
84 |
|
---|
85 | TMPDIR=/boot/common/cache/tmp
|
---|
86 | if [ ! -d $TMPDIR ]; then
|
---|
87 | mkdir -f $TMPDIR
|
---|
88 | chmod a+rwx $TMPDIR
|
---|
89 | else
|
---|
90 | rm -rf $TMPDIR/*
|
---|
91 | fi
|
---|
92 |
|
---|
93 |
|
---|
94 | # Launch servers
|
---|
95 |
|
---|
96 | # We must wait for the app_server and registrar to be ready
|
---|
97 | launch $SERVERS/registrar _roster_thread_ # launch registrar
|
---|
98 |
|
---|
99 | launch $SERVERS/debug_server # launch debug_server
|
---|
100 |
|
---|
101 | # Init Network
|
---|
102 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
103 | launch $SERVERS/net_server # launch net_server
|
---|
104 | fi
|
---|
105 |
|
---|
106 | launch $SERVERS/app_server picasso # launch app_server
|
---|
107 |
|
---|
108 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
109 | launch $SERVERS/syslog_daemon
|
---|
110 | waitfor _input_server_event_loop_ # wait for input devices
|
---|
111 | fi
|
---|
112 |
|
---|
113 | # Now ask the user if he wants to run the Installer or continue to the Desktop.
|
---|
114 | if [ "$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
|
---|
123 | else
|
---|
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
|
---|
133 | fi
|
---|
134 |
|
---|
135 |
|
---|
136 | if [ -e /etc/users ]; then
|
---|
137 | # TODO: system/Login needs to be fixed to launch the mount_server!
|
---|
138 | launch system/Login
|
---|
139 | # nothing more
|
---|
140 | else
|
---|
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
|
---|
150 | fi
|
---|
151 |
|
---|
152 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
153 | launch $SERVERS/media_server
|
---|
154 | launch $SERVERS/midi_server
|
---|
155 | fi
|
---|
156 |
|
---|
157 | # Launch Print Server
|
---|
158 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
159 | launch $SERVERS/print_server
|
---|
160 | fi
|
---|
161 |
|
---|
162 | # Launch Mail Daemon (if enabled on startup)
|
---|
163 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
164 | launch $SERVERS/mail_daemon "" -E
|
---|
165 | fi
|
---|
166 |
|
---|
167 | # Launch CDDB Daemon
|
---|
168 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
169 | launch $SERVERS/cddb_daemon ""
|
---|
170 | fi
|
---|
171 |
|
---|
172 | # Launch Notification Server
|
---|
173 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
174 | launch $SERVERS/notification_server ""
|
---|
175 | fi
|
---|
176 |
|
---|
177 | # Launch Power Daemon
|
---|
178 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
179 | launch $SERVERS/power_daemon ""
|
---|
180 | fi
|
---|
181 |
|
---|
182 | # Check for daylight saving time
|
---|
183 | launch system/bin/dstcheck
|
---|
184 |
|
---|
185 | # Synchronize network time
|
---|
186 | launch system/preferences/Time "" --update
|
---|
187 |
|
---|
188 | if [ "$SAFEMODE" != "yes" ]; then
|
---|
189 | # Start user boot script
|
---|
190 | if [ -f $HOME/config/boot/UserBootscript ]; then
|
---|
191 | . $HOME/config/boot/UserBootscript
|
---|
192 | fi
|
---|
193 | fi
|
---|
194 |
|
---|
195 | # Check for fresh install and run post install scripts.
|
---|
196 | postInstallDir=/boot/common/boot/post_install
|
---|
197 | freshInstallIndicator=/boot/common/settings/fresh_install
|
---|
198 | if [ -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
|
---|
212 | fi
|
---|