galeb

Једноставна статичка дистрибуција заснована на musl-у
git clone https://git.sr.ht/~strahinja/galeb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

rc.init (4510B)


      1 #!/bin/sh
      2 
      3 umask 022
      4 
      5 . /etc/rc.conf
      6 RCINIT=1 . /lib/g_fun.sh
      7 
      8 PATH=/local/bin:/bin:/plan9/bin:/sucks/bin
      9 export PATH
     10 
     11 clear
     12 printf "${green}===( ${bold}${white}%s${norm}${green} )=== booting${norm}\n" \
     13 	"$(cat /etc/galeb-release)"
     14 
     15 ctrlaltdel -s
     16 
     17 msg info "Mounting essential filesystems"
     18 mount -n -t proc     -o nosuid,noexec,nodev		      proc   /proc
     19 mount -n -t sysfs    -o nosuid,noexec,nodev		      sysfs  /sys
     20 mount -n -t tmpfs    -o nosuid,nodev,noatime,mode=1777	      tmp    /tmp
     21 mkdir -p /dev/shm
     22 mount -n -t tmpfs    -o nosuid,nodev,noatime,mode=1777	      shm    /dev/shm
     23 mkdir -p /dev/pts
     24 mount -n -t devpts   -o nosuid,noexec,noatime,gid=5,mode=0620 devpts /dev/pts
     25 mount -n -t tmpfs    -o nosuid,nodev,noatime,mode=0755	      run    /var/run
     26 mount -n -t efivarfs -o nosuid,nodev,noexec efivarfs /sys/firmware/efi/efivars
     27 
     28 create_logfile
     29 
     30 printf "%s: %s created on %s\n" $0 "${G_LOGFILE}" "$(date)" >${G_LOGFILE}
     31 
     32 if grep -q verbose /proc/cmdline >/dev/null 2>>${G_LOGFILE}; then
     33 	dmesg -n 8 2>>${G_LOGFILE}
     34 else
     35 	dmesg -n 3 2>>${G_LOGFILE}
     36 fi
     37 
     38 msg info "Running smdev..."
     39 smdev -s >/dev/null 2>>${G_LOGFILE}
     40 if [ -e /proc/sys/kernel/hotplug ]; then
     41 	echo /bin/smdev >/proc/sys/kernel/hotplug
     42 fi
     43 
     44 cd /dev
     45 ln -sf /proc/self/fd/0 stdin 2>>${G_LOGFILE}
     46 ln -sf /proc/self/fd/1 stdout 2>>${G_LOGFILE}
     47 ln -sf /proc/self/fd/2 stderr 2>>${G_LOGFILE}
     48 ln -sf /proc/self/fd   fd 2>>${G_LOGFILE}
     49 cd - >/dev/null
     50 
     51 if echo ${LANG} | grep -i utf >/dev/null 2>>${G_LOGFILE}; then
     52 	kbd_mode=-u
     53 	loadkeys=''
     54 	act_string=%%G
     55 	def_utf=1
     56 else
     57 	kbd_mode=-a
     58 	loadkeys=-a
     59 	act_string=%%@
     60 	def_utf=0
     61 fi
     62 msg info "Setting kbd_mode %s and font" "${kbd_mode}"
     63 kbd_mode ${kbd_mode} >/dev/null 2>>${G_LOGFILE}
     64 if [ -n "${KEYMAP}" ]; then
     65 	loadkeys -q ${loadkeys} ${KEYMAP} 2>>${G_LOGFILE}
     66 fi
     67 for tty in /dev/tty[0-9]*; do
     68 	kbd_mode ${kbd_mode} -C ${tty} >/dev/null 2>>${G_LOGFILE}
     69 	printf "\e${act_string}" >${tty} >/dev/null 2>>${G_LOGFILE}
     70 	if [ -n "${FONT}" ]; then
     71 		SETFONT_ARGS=
     72 		if [ -n "${FONT_MAP}" ]; then
     73 			SETFONT_ARGS+=" -m${FONT_MAP}"
     74 		fi
     75 		if [ -n "${FONT_UNIMAP}" ]; then
     76 			SETFONT_ARGS+=" -u${FONT_UNIMAP}"
     77 		fi
     78 		setfont ${FONT} ${SETFONT_ARGS} -C ${tty} 2>>${G_LOGFILE}
     79 	fi
     80 done
     81 echo ${def_utf} >| /sys/module/vt/parameters/default_utf8 2>>${G_LOGFILE}
     82 
     83 msg info "Setting hostname"
     84 if [ -n "${HOSTNAME}" ]; then
     85 	hostname ${HOSTNAME} 2>>${G_LOGFILE}
     86 elif [ -e /etc/hostname ]; then
     87 	hostname $(sed 1q /etc/hostname) 2>>${G_LOGFILE}
     88 else
     89 	hostname galeb 2>>${G_LOGFILE}
     90 fi
     91 
     92 msg info "Checking filesystems"
     93 fsckout=$(fsck -ATa 2>&1)
     94 if [ $? -eq 1 ]; then
     95 	echo "${fsckout}"
     96 	msg err "Filesystem errors, fix manually"
     97 	sh
     98 	msg warn "Rebooting"
     99 	halt -r
    100 fi
    101 
    102 msg info "Remounting / read-write"
    103 mount -o rw,remount / 2>>${G_LOGFILE}
    104 ln -sf /proc/mounts /etc/mtab 2>>${G_LOGFILE}
    105 
    106 msg info "Mounting filesystems"
    107 mount -a 2>>${G_LOGFILE}
    108 
    109 msg info "Activating swap"
    110 swapon -a 2>>${G_LOGFILE}
    111 
    112 msg info "Setting timezone"
    113 if [ -n "${TIMEZONE}" ]; then
    114 	TZ=:${TIMEZONE}
    115 	export TZ
    116 	ln -sf /share/zoneinfo/${TIMEZONE} /etc/localtime 2>>${G_LOGFILE}
    117 else
    118 	if [ ! -L /etc/localtime ]; then
    119 		TIMEZONE=GMT
    120 		TZ=:${TIMEZONE}
    121 		export TZ
    122 		ln -sf /share/zoneinfo/${TIMEZONE} /etc/localtime \
    123 			2>>${G_LOGFILE}
    124 	fi
    125 fi
    126 
    127 msg info "Configure svc"
    128 svc -c 2>>${G_LOGFILE}
    129 
    130 service start metalog 2>>${G_LOGFILE}
    131 
    132 msg info "Setting random seed"
    133 if [ -f /etc/random-seed ]; then
    134 	cat /etc/random-seed >/dev/urandom 2>>${G_LOGFILE}
    135 fi
    136 dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null 2>>${G_LOGFILE}
    137 
    138 msg info "Storing dmesg output to /var/log/dmesg.log"
    139 dmesg >/var/log/dmesg.log 2>>${G_LOGFILE}
    140 
    141 if [ -e /proc/sys/kernel/dmesg_restrict ] && \
    142 	[ "$(cat /proc/sys/kernel/dmesg_restrict)" = "1" ]
    143 then
    144 	chmod 0600 /var/log/dmesg.log 2>>${G_LOGFILE}
    145 else
    146 	chmod 0644 /var/log/dmesg.log 2>>${G_LOGFILE}
    147 fi
    148 
    149 if [ -x /bin/rc.modules ]; then
    150 	msg info "Starting /bin/rc.modules"
    151 	/bin/rc.modules
    152 fi
    153 
    154 if [ -x /bin/rc.inet ]; then
    155 	msg info "Starting /bin/rc.inet"
    156 	/bin/rc.inet
    157 fi
    158 
    159 env STATUSDELAY=${STATUSDELAY} \
    160 service start all
    161 
    162 if [ -x /bin/rc.local ]; then
    163 	msg info "Starting /bin/rc.local"
    164 	/bin/rc.local
    165 fi
    166 
    167 :>/var/run/utmp
    168 chmod 0664 /var/run/utmp 2>>${G_LOGFILE}
    169 chown root:utmp /var/run/utmp 2>>${G_LOGFILE}
    170 
    171 unset PATH G_LOGFILE
    172 export LANG
    173 
    174 printf "%s: Boot finished at %s, spawning gettys.\n" $0 "$(date)" \
    175 	>>/tmp/boot.log
    176 mv /tmp/boot.log /var/log/ 2>/dev/null
    177 chmod 0600 /var/log/boot.log 2>/dev/null
    178 
    179 echo
    180 for n in 1 2 3 4; do
    181 	/bin/respawn /bin/gettyc /dev/tty$n linux >/dev/null 2>&1 &
    182 done