# HG changeset patch # User David Demelier # Date 1552769676 -3600 # Node ID 36f3ab3945d7f785b189514a2d90985f0964a00e # Parent 2a742bf097aa3b3ce8900c10fc683b745ea2630b core/sysvinit: add basic init scripts diff -r 2a742bf097aa -r 36f3ab3945d7 core/filesystem/filesystem.sh --- a/core/filesystem/filesystem.sh Sat Mar 16 21:33:50 2019 +0100 +++ b/core/filesystem/filesystem.sh Sat Mar 16 21:54:36 2019 +0100 @@ -25,6 +25,7 @@ build() { install -d $DESTDIR/etc + install -d $DESTDOR/etc/rc.d install -d $DESTDIR/home install -d $DESTDIR/mnt install -d $DESTDIR/proc diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/inittab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sysvinit/inittab Sat Mar 16 21:54:36 2019 +0100 @@ -0,0 +1,45 @@ +# +# /etc/inittab: init system configuration +# + +# +# vanilla recommends the following runlevels: +# +# S: single user mode (no services at all) +# 1: single user mode +# 2: multi user mode (console) +# 3: multi user mode (graphical) +# 4, 5: unused but kept to administrator discretion. +# +# The following run levels are special and must not be used as default: +# +# 0: power off +# 6: reboot +# + +# Default run level. +id:2:initdefault: + +# System initialization. +si::sysinit:/etc/rc.init + +# Runlevels. +lS:S:wait:/usr/sbin/sulogin +l0:0:wait:/etc/rc.shutdown 0 +l1:1:wait:/etc/rc.start 1 +l2:2:wait:/etc/rc.start 2 +l3:3:wait:/etc/rc.start 3 +l4:4:wait:/etc/rc.start 4 +l5:5:wait:/etc/rc.start 5 +l6:6:wait:/etc/rc.shutdown 6 + +# Shutdown on ctrl+alt+delete. +ca::ctrlaltdel:/usr/sbin/shutdown -t1 -h now + +# Console terminals. +c1:2345:respawn:/usr/sbin/agetty --noclear 38400 tty1 linux +c2:2345:respawn:/usr/sbin/agetty 38400 tty2 linux +c3:2345:respawn:/usr/sbin/agetty 38400 tty3 linux +c4:2345:respawn:/usr/sbin/agetty 38400 tty4 linux +c5:2345:respawn:/usr/sbin/agetty 38400 tty5 linux +c6:2345:respawn:/usr/sbin/agetty 38400 tty6 linux diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/rc.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sysvinit/rc.conf Sat Mar 16 21:54:36 2019 +0100 @@ -0,0 +1,12 @@ +# +# /etc/rc.conf: system configuration +# + +# System hostname. +HOSTNAME="localhost" + +# System timezone. +TIMEZONE="UTC" + +# Services to start at boot. +SERVICES="" diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/rc.init --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sysvinit/rc.init Sat Mar 16 21:54:36 2019 +0100 @@ -0,0 +1,68 @@ +# +# /etc/rc.init: system initialization script +# + +if [ -f /etc/rc.conf ]; then + source /etc/rc.conf +fi + +if [ -n "$HOSTNAME" ] && [ -x /usr/bin/hostname ]; then + echo "Setting hostname: $HOSTNAME" + /usr/bin/hostname "$HOSTNAME" +fi + +if [ -x /usr/sbin/sysctl ]; then + echo "Setting kernel parameters." + /usr/sbin/sysctl -p >/dev/null 2>&1 +fi + +if [ -x /usr/bin/mountpoint ]; then + echo -n "Mounting filesystems: " + + if ! /usr/bin/mountpoint /proc >/dev/null 2>&1; then + /usr/bin/mount -t proc none /proc >/dev/null 2>&1 + echo -n "/proc " + fi + + if ! /usr/bin/mountpoint /sys >/dev/null 2>&1; then + /usr/bin/mount -t sysfs none /sys >/dev/null 2>&1 + echo -n "/sys " + fi + + echo "done." +fi + +if [ -x /usr/sbin/fsck ]; then + # Make sure / is ro in case of initrd. + /usr/bin/mount -o remount,ro / + + # If /etc/forcefsck is there, force check. + if [ -f /etc/forcefsck ]; then + force="-f" + fi + + /usr/sbin/fsck $force -A -T -C -a >/dev/null 2>&1 + + if [ "$?" -gt 1 ]; then + echo "* Filesystem check failed" + /usr/sbin/sulogin -p + fi +fi + +# Remount / and enable swap as the system is ready. +/usr/bin/mount -o remount,rw / +/usr/sbin/swapon -a + +if [ -n "$TIMEZONE" ]; then + echo -n "Setting timezone: " + + if [ -f /usr/share/zoneinfo/$TIMEZONE ]; then + /usr/bin/ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime + echo "$TIMEZONE." + else + echo "$TIMEZONE not found." + fi +fi + +# cleanup some files. +rm -f /etc/forcefsck diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/rc.shutdown --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sysvinit/rc.shutdown Sat Mar 16 21:54:36 2019 +0100 @@ -0,0 +1,26 @@ +# +# /etc/rc.shutdown: reboot and halt script +# + +if [ -f /etc/rc.conf ]; then + source /etc/rc.conf +fi + +echo "Terminating all processes." +/usr/sbin/killall5 -15 + +echo "Unmounting all filesystems." +/usr/sbin/halt -w +/usr/sbin/swapoff -a + +if [ -x /usr/bin/mount ]; then + /usr/bin/umount -a -d -r -t nosysfs,noproc,nodevtmpfs + /usr/bin/umount -a -r + /usr/bin/mount -o remount,ro / +fi + +if [ "$1" = "0" ]; then + /usr/sbin/poweroff -d -f -i +else + /usr/sbin/reboot -d -f -i +fi diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/rc.start --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/sysvinit/rc.start Sat Mar 16 21:54:36 2019 +0100 @@ -0,0 +1,32 @@ +# +# /etc/rc.start: runlevel control script +# + +if [ "$#" -ne 1 ]; then + echo "usage: $0 runlevel" 1>&2 + exit 1 +fi + +if [ -f /etc/rc.conf ]; then + source /etc/rc.conf +fi + +# Start user services requested in rc.conf(5). +for s in $SERVICES; do + # + # Services are requested in the form name[:runlevel], if runlevel is + # specified the service is started only if the system runlevel is + # greater or equal to the request. + # + name="${s%%:*}" + level="${s##*:}" + + # No minimum level, set to requested. + if [ -z "$level" ]; then + level="$1" + fi + + if [ -x /etc/rc.d/$name ] && [ "$level" -le "$1" ]; then + /etc/rc.d/$name start + fi +done diff -r 2a742bf097aa -r 36f3ab3945d7 core/sysvinit/sysvinit.sh --- a/core/sysvinit/sysvinit.sh Sat Mar 16 21:33:50 2019 +0100 +++ b/core/sysvinit/sysvinit.sh Sat Mar 16 21:54:36 2019 +0100 @@ -21,6 +21,11 @@ PKGLICENSE="GPLv2+" PKGSUMMARY="traditional System V init" PKGDOWNLOAD="http://download.savannah.nongnu.org/releases/$PKGNAME/$PKGNAME-$PKGVERSION.tar.xz" +PKGPROTECT="etc/inittab + etc/rc.conf + etc/rc.init + etc/rc.shutdown + etc/rc.start" : ${CC:=gcc} : ${CFLAGS:=-O2} @@ -37,6 +42,7 @@ -e 's|$(ROOT)/sbin|$(ROOT)/usr/sbin|g' src/Makefile make CC="$CC" CFLAGS="$CFLAGS" make install ROOT=$DESTDIR + install -Dm0644 ../inittab popd rm -rf $PKGNAME-$PKGVERSION