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 fi 124 125 126 if [ -e /etc/users ]; then 127 # TODO: system/Login needs to be fixed to launch the mount_server! 128 launch system/Login 129 # nothing more 130 else 131 cd /boot/home 132 133 launch $SERVERS/mount_server 134 waitfor -m application/x-vnd.Haiku-mount_server 135 # delay the boot script until all previous volumes have been mounted 136 hey -s mount_server DO InitialScan 137 138 launch system/Tracker 139 launch system/Deskbar 140 fi 141 142 if [ "$SAFEMODE" != "yes" ]; then 143 launch $SERVERS/media_server 144 launch $SERVERS/midi_server 145 fi 146 147 # Launch Print Server 148 if [ "$SAFEMODE" != "yes" ]; then 149 launch $SERVERS/print_server 150 fi 151 152 # Launch Mail Daemon (if enabled on startup) 153 if [ "$SAFEMODE" != "yes" ]; then 154 launch $SERVERS/mail_daemon "" -E 155 fi 156 157 # Launch CDDB Daemon 158 if [ "$SAFEMODE" != "yes" ]; then 159 launch $SERVERS/cddb_daemon "" 160 fi 161 162 # Launch Notification Server 163 if [ "$SAFEMODE" != "yes" ]; then 164 launch $SERVERS/notification_server "" 165 fi 166 167 # Launch Power Daemon 168 if [ "$SAFEMODE" != "yes" ]; then 169 launch $SERVERS/power_daemon "" 170 fi 171 172 # Check for daylight saving time 173 launch system/bin/dstcheck 174 175 # Synchronize network time 176 launch system/preferences/Time "" --update 177 178 if [ "$SAFEMODE" != "yes" ]; then 179 # Start user boot script 180 if [ -f $HOME/config/boot/UserBootscript ]; then 181 . $HOME/config/boot/UserBootscript 182 fi 183 fi 184 185 # Check for fresh install and run post install scripts. 186 postInstallDir=/boot/common/boot/post_install 187 freshInstallIndicator=/boot/common/settings/fresh_install 188 if [ -e $freshInstallIndicator ]; then 189 # wait a moment for things to calm down a bit 190 sleep 3 191 192 # execute scripts 193 for f in $postInstallDir/*.sh; do 194 if [ -f $f ]; then 195 echo "Running post install script $f ..." > /dev/dprintf 196 $f 197 fi 198 done 199 200 sync 201 rm $freshInstallIndicator 202 fi 203