stali-init

Stali init files. To be shared.
git clone git://r-36.net/stali-init
Log | Files | Refs

rc.init (5566B)


      1 #!/bin/busybox ash
      2 
      3 . /etc/rc.conf
      4 
      5 mkdir -p /dev
      6 mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
      7 touch /dev/mdev.log
      8 mkdir -p /dev/pts
      9 mountpoint -q /dev/pts || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec,noatime
     10 bootlogd -c -l /run/boot.log -p /run/bootlogd.pid
     11 
     12 printf "\n\n"
     13 printf "         sta.li\n"
     14 printf "\n\n"
     15 
     16 printf "Mounting base filesystems.\n"
     17 mkdir -p /proc
     18 mkdir -p /sys
     19 mkdir -p /run
     20 mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
     21 mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
     22 mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
     23 
     24 mkdir -p -m 1777 /run/lock
     25 mkdir -p /dev/shm
     26 mountpoint -q /dev/shm || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev,noatime
     27 
     28 ln -s /proc/self/fd /dev/fd
     29 
     30 mountpoint -q /sys/fs/cgroup || mount -n -t cgroup nodev /sys/fs/cgroup
     31 
     32 if [ ! -e /run/initramfs/fsck-root ];
     33 then
     34 	printf "Remounting root ro.\n"
     35 	mount -o remount,ro /
     36 fi
     37 
     38 if [ -s /etc/locale.conf ];
     39 then
     40 	printf "Reading /etc/locale.conf.\n"
     41 	eval $(cat /etc/locale.conf)
     42 fi
     43 
     44 if [ -n $(printf "%s" "$LANG" | grep -i utf) ];
     45 then
     46 	printf "Setting ttys to be UTF-8.\n"
     47 	for i in /dev/tty[0-9]*; do
     48 		kbd_mode -u < ${i} &>/dev/null
     49 		printf "\e%%G" > ${i} &>/dev/null
     50 	done
     51 	echo 1 >| /sys/module/vt/parameters/default_utf8
     52 else
     53 	printf "Setting ttys to legacy.\n"
     54 	for i in /dev/tty[0-9]*; do
     55 		kbd_mode -a < ${i} &>/dev/null
     56 		printf "\e%%@" > ${i} &>/dev/null
     57 	done
     58 	echo 0 >| /sys/module/vt/parameters/default_utf8
     59 fi
     60 
     61 if [ -s /etc/vconsole.conf ];
     62 then
     63 	printf "Reading vconsole.conf.\n"
     64 	eval $(cat /etc/vconsole.conf)
     65 	[ -n "$FONT" ] && CONSOLEFONT="$FONT"
     66 	[ -n "$FONT_MAP" ] && CONSOLEMAP="$FONT_MAP"
     67 fi
     68 
     69 [ -n "$KEYMAP" ] && loadkeys -q "$KEYMAP"
     70 
     71 HWCLOCK_PARAMS="-s"
     72 case $HARDWARECLOCK in
     73 	"")
     74 		;;
     75 	UTC)
     76 		HWCLOCK_PARAMS="${HWCLOCK_PARAMS} -u"
     77 		;;
     78 	localtime)
     79 		HWCLOCK_PARAMS="${HWCLOCK_PARAMS} -l"
     80 		;;
     81 	*)
     82 		HWCLOCK_PARAMS=""
     83 		;;
     84 esac
     85 
     86 if [ -n "$HWCLOCK_PARAMS" ];
     87 then
     88 	printf "Setting hwclock.\n"
     89 	[ -n "$TIMEZONE" ] && export TZ="$TIMEZONE"
     90 	hwclock $HWCLOCK_PARAMS
     91 	unset TZ
     92 fi
     93 
     94 printf "Running nldev.\n"
     95 nldev -kbd &
     96 
     97 printf "Loading MODULES from rc.conf.\n"
     98 for i in $MODULES;
     99 do
    100 	busybox modprobe "${i}"
    101 done
    102 
    103 printf "Triggering all device events.\n"
    104 nltrigger add all
    105 
    106 printf "Setting up lo device.\n"
    107 [ -d /sys/class/net/lo ] && ifconfig lo up
    108 #ip link set up dev lo
    109 
    110 [ "$USEDMRAID" = "yes" ] && printf "Setting up dmraid.\n" && env dmraid -i -ay 
    111 [ "$USEBTRFS" = "yes" ] && printf "Setting up btrfs.\n" && env btrfs device scan
    112 [ "$USELVM" = "yes" ] && printf "Setting up lvm.\n" && env vgchange --sysinit -a y >/dev/null
    113 
    114 # TODO: crypttab support
    115 
    116 if [ ! -e /fastboot ];
    117 then
    118 	printf "Running fsck -ATa.\n"
    119 	fsck -ATa
    120 	if [ $? -gt 1 ];
    121 	then
    122 		printf "Filesystem errors exist. Please fix manually.\n"
    123 		/bin/busybox ash
    124 		reboot
    125 	fi
    126 fi
    127 
    128 printf "Remounting /.\n"
    129 mount -o remount,rw /
    130 printf "Mounting all filesystems in /etc/fstab.\n"
    131 mount -a
    132 
    133 [ "$USELVM" = "yes" ] && printf "Activating lvm monitor.\n" && env vgchange --monitor y >/dev/null
    134 
    135 printf "Activating swap.\n"
    136 swapon -a &
    137 
    138 if [ -n "$TIMEZONE" ];
    139 then
    140 	printf "Setting local timezone to '%s',\n" "${TIMEZONE}"
    141 	local zonefile="/usr/share/zoneinfo/${TIMEZONE}"
    142 	if [ ! -e "${zonefile}" ];
    143 	then
    144 		printf "'%s' is not a valid timezone.\n" "${TIMEZONE}"
    145 	else
    146 		if [ ! -L /etc/localtime ] || [ ! /etc/localtime -ef "${zonefile}" ];
    147 		then
    148 			ln -sf "${zoneinfo}" /etc/localtime
    149 		fi
    150 	fi
    151 fi
    152 
    153 printf "Applying random seed to /dev/urandom.\n"
    154 RANDOM_SEED=/var/lib/misc/random-seed
    155 if [ -s $RANDOM_SEED ];
    156 then
    157 	cat $RANDOM_SEED > /dev/urandom
    158 else
    159 	dd if=/dev/random of=/dev/urandom count=1 &>/dev/null
    160 	touch $RANDOM_SEED
    161 fi
    162 chmod 600 $RANDOM_SEED
    163 POOL_FILE=/proc/sys/kernel/random/poolsize
    164 [ -r $POOL_FILE ] && POOL_SIZE=$(cat $POOL_FILE) || POOL_SIZE=512
    165 
    166 printf "Cleaning up /var.\n"
    167 if [ ! -L /var/lock ] && [ ! /var/lock -ef /run/lock ];
    168 then
    169 	rm -rf /var/lock 2>/dev/null
    170 	ln -sf /run/lock /var/lock
    171 fi
    172 
    173 if [ ! -L /var/run ] && [ ! /var/run -ef /run ];
    174 then
    175 	rm -rf /var/run 2>/dev/null
    176 	ln -sf /run /var/run
    177 fi
    178 
    179 [ -s /etc/hostname ] && HOSTNAME=$(cat /etc/hostname)
    180 if [ -n "$HOSTNAME" ];
    181 then
    182 	printf "Setting hostname to '%s'.\n" "${HOSTNAME}"
    183 	printf "%s\n" "$HOSTNAME" > /proc/sys/kernel/hostname
    184 	hostname -F /etc/hostname
    185 fi
    186 
    187 printf "Storing dmesg output into /var/log/dmesg.log.\n"
    188 env dmesg > /var/log/dmesg.log
    189 if [ -e /proc/sys/kernel/dmesg_restrict ] && [ $(cat /proc/sys/kernel/dmesg_restrict) = "1" ];
    190 then
    191 	chmod 0600 /var/log/dmesg.log
    192 else
    193 	chmod 0644 /var/log/dmesg.log
    194 fi
    195 
    196 printf "Running sysctl.\n"
    197 sysctl -p /etc/sysctl.conf &>/dev/null
    198 for path in /usr/lib/sysctl.d /etc/sysctl.d /run/sysctl.d;
    199 do
    200 	if [ -d $path ];
    201 	then
    202 		for file in $(ls -1 $path);
    203 		do
    204 			sysctl -p $file &>/dev/null
    205 		done
    206 	fi
    207 done
    208 
    209 printf "Running binfmt.\n"
    210 mountpoint -q /proc/sys/fs/binfmt_misc || \
    211 	mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
    212 for path in /usr/lib/binfmt.d /etc/binfmt.d /run/binfmt.d;
    213 do
    214 	[ ! -d $path ] && continue;
    215 	for file in $(ls -1 $path);
    216 	do
    217 		grep "^:" $file | \
    218 			while read -r line;
    219 			do
    220 				printf "%s" "$line" \
    221 					> /proc/sys/fs/binfmt_misc/register
    222 			done
    223 	done
    224 done
    225 
    226 printf "Killing bootlogd.\n"
    227 if [ -f /run/bootlogd.pid ];
    228 then
    229 	kill $(cat /run/bootlogd.pid)
    230 	rm -f /run/bootlogd.pid
    231 fi
    232 [ -e /run/boot.log ] && mv /run/boot.log /var/log/boot
    233 
    234 printf "Loading DELAYMODULES from rc.conf.\n"
    235 for i in $DELAYMODULES;
    236 do
    237 	busybox modprobe "${i}"
    238 done
    239 
    240 # next is rc.svc
    241 # then is tty1 from stali.inittab
    242