From 54d7bde90161b3e01a5e15260d08e79f39096fec Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Wed, 18 Dec 2019 21:04:42 +0300 Subject: add makefile --- Makefile | 14 ++++ etc/inittab | 11 ---- inittab | 11 ++++ lib/init/rc.boot | 177 --------------------------------------------------- lib/init/rc.shutdown | 48 -------------- rc.boot | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++ rc.shutdown | 48 ++++++++++++++ 7 files changed, 250 insertions(+), 236 deletions(-) create mode 100644 Makefile delete mode 100644 etc/inittab create mode 100644 inittab delete mode 100755 lib/init/rc.boot delete mode 100755 lib/init/rc.shutdown create mode 100755 rc.boot create mode 100755 rc.shutdown diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..41eacf1 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +# See license for licensing details + +PREFIX=/usr + +install: + @install -Dm644 inittab ${DESTDIR}/etc/inittab + @install -Dm755 rc.boot ${DESTDIR}${PREFIX}/lib/init/rc.boot + @install -Dm755 rc.shutdown ${DESTDIR}${PREFIX}/lib/init/rc.shutdown + +uninstall: + @rm -f ${DESTDIR}/etc/inittab + @rm -f ${DESTDIR}${PREFIX}/lib/init/rc.boot + @rm -f ${DESTDIR}${PREFIX}/lib/init/rc.shutdown + diff --git a/etc/inittab b/etc/inittab deleted file mode 100644 index 2cd998c..0000000 --- a/etc/inittab +++ /dev/null @@ -1,11 +0,0 @@ -::sysinit:/lib/init/rc.boot -::restart:/sbin/init -::shutdown:/lib/init/rc.shutdown -::respawn:runsvdir -P /var/service 'log: ................................................................................................................................................................................................................................................................' - -tty1::respawn:/sbin/getty 38400 tty1 -tty2::respawn:/sbin/getty 38400 tty2 -tty3::respawn:/sbin/getty 38400 tty3 -tty4::respawn:/sbin/getty 38400 tty4 -tty5::respawn:/sbin/getty 38400 tty5 -tty6::respawn:/sbin/getty 38400 tty6 diff --git a/inittab b/inittab new file mode 100644 index 0000000..2cd998c --- /dev/null +++ b/inittab @@ -0,0 +1,11 @@ +::sysinit:/lib/init/rc.boot +::restart:/sbin/init +::shutdown:/lib/init/rc.shutdown +::respawn:runsvdir -P /var/service 'log: ................................................................................................................................................................................................................................................................' + +tty1::respawn:/sbin/getty 38400 tty1 +tty2::respawn:/sbin/getty 38400 tty2 +tty3::respawn:/sbin/getty 38400 tty3 +tty4::respawn:/sbin/getty 38400 tty4 +tty5::respawn:/sbin/getty 38400 tty5 +tty6::respawn:/sbin/getty 38400 tty6 diff --git a/lib/init/rc.boot b/lib/init/rc.boot deleted file mode 100755 index b5b8782..0000000 --- a/lib/init/rc.boot +++ /dev/null @@ -1,177 +0,0 @@ -#!/bin/sh - -log() { printf '\033[1;36m=>\033[m\033[1m %s\n' "$@" ;} - -welcome() { printf '\033[1;36m=>\033[m\033[1m Welcome to\033[35m Carbs Linux\033[m\033[1m!\n' ;} - -error() { printf '\033[1m\033[31m=> ERROR: %s\033[m\n' "$@" ;} - -mnt() { - mountpoint -q "$1" || { - dir=$1 - shift - mount "$@" "$dir" - } -} - -emergency_shell() { - error \ - "Cannot continue init due to errors above, starting emergency shell" \ - "When ready, type 'exit' to continue the boot." - - /bin/sh -l -} - -main() { - PATH=/usr/bin:/usr/sbin - old_ifs=$IFS - set -f - - welcome - - log "Mounting pseudo filesystems..."; { - mnt /proc -o nosuid,noexec,nodev -t proc proc - mnt /sys -o nosuid,noexec,nodev -t sysfs sys - mnt /run -o mode=0755,nosuid,nodev -t tmpfs run - mnt /dev -o mode=0755,nosuid -t devtmpfs dev - - mkdir -pm 0755 /run/runit \ - /run/lvm \ - /run/user \ - /run/lock \ - /run/log \ - /dev/pts \ - /dev/shm - - mnt /dev/pts -o mode=0620,gid=5,nosuid,noexec -nt devpts devpts - mnt /dev/shm -o mode=1777,nosuid,nodev -nt tmpfs shm - } - - log "Starting eudev..."; { - command -v udevd >/dev/null && { - udevd --daemon - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices - udevadm settle - } - } - - log "Remounting rootfs as ro..."; { - mount -o remount,ro / || emergency_shell - } - - log "Activating encrypted devices (if any exist)..."; { - [ -e /etc/crypttab ] && [ -x /bin/cryptsetup ] && { - exec 3<&0 - - while read -r name dev pass opts err; do - [ "${name##\#*}" ] || continue - - # Break on invalid crypttab. - [ "$err" ] && { - printf 'error: A valid crypttab has only 4 columns.\n' - break - } - - # Turn 'UUID=*' lines into device names. - [ "${dev##UUID*}" ] || dev=$(blkid -l -o device -t "$dev") - - # Parse options by turning list into a pseudo array. - IFS=, - set -- $opts - IFS=$old_ifs - - copts="cryptsetup luksOpen" - - # Create an argument list (no other way to do this in sh). - for opt; do case $opt in - discard) copts="$copts --allow-discards" ;; - readonly|read-only) copts="$copts -r" ;; - tries=*) copts="$copts -T ${opt##*=}" ;; - esac; done - - # If password is 'none', '-' or empty ask for it. - case $pass in - none|-|"") $copts "$dev" "$name" <&3 ;; - *) $copts -d "$pass" "$dev" "$name" ;; - esac - done < /etc/crypttab - - exec 3>&- - - [ "$copts" ] && [ -x /bin/vgchance ] && { - log "Activating LVM devices for dm-crypt..." - vgchange --sysinit -a y || emergency_shell - } - } - } - - log "Checking filesystems..."; { - fsck -ATat noopts=_netdev - [ $? -gt 1 ] && emergency_shell - } - - log "Mounting rootfs rw..."; { - mount -o remount,rw / || emergency_shell - } - - log "Mounting all local filesystems..."; { - mount -at nosysfs,nonfs,nonfs4,nosmbfs,nocifs -O no_netdev || - emergency_shell - } - - log "Enabling swap..."; { - swapon -a || emergency_shell - } - - log "Seeding random..."; { - if [ -f /var/random.seed ]; then - cat /var/random.seed > /dev/urandom - else - log "This may hang." - log "Mash the keyboard to generate entropy..." - - dd count=1 bs=512 if=/dev/random of=/var/random.seed - fi - } - - log "Setting up loopback..."; { - ip link set up dev lo - } - - log "Setting hostname..."; { - read -r hostname < /etc/hostname - printf '%s\n' "${hostname:-carbs-linux}" > /proc/sys/kernel/hostname - } 2>/dev/null - - log "Getting keymap settings..."; { - [ -r "/etc/keymap" ] && . /etc/keymap - [ -n "$KEYMAP" ] && loadkmap < "$KEYMAP" - } - - log "Loading sysctl settings..."; { - find /run/sysctl.d \ - /etc/sysctl.d \ - /usr/local/lib/sysctl.d \ - /usr/lib/sysctl.d \ - /lib/sysctl.d \ - /etc/sysctl.conf \ - -name \*.conf -type f 2>/dev/null \ - | while read -r conf; do - seen="$seen ${conf##*/}" - - case $seen in - *" ${conf##*/} "*) ;; - *) printf '%s\n' "* Applying $conf ..." - sysctl -p "$conf" ;; - esac - done - } - - command -v udevd >/dev/null && - udevadm control --exit - - log "Boot stage complete..." -} - -main diff --git a/lib/init/rc.shutdown b/lib/init/rc.shutdown deleted file mode 100755 index 9dba627..0000000 --- a/lib/init/rc.shutdown +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -log() { printf '\033[36;1m=>\033[m\033[1m %s\n' "$@" ;} - -main() { - PATH=/sbin:/bin:/usr/sbin:/usr/bin - - log "Waiting for services to stop..."; { - sv -w196 force-stop /var/service/* - sv exit /var/service/* - } - - log "Saving random seed..."; { - dd count=1 bs=512 if=/dev/random of=/var/random.seed - } - - halt -w - - log "Sending TERM signal to all processes..."; { - killall5 -TERM - sleep 1 - } - - log "Sending KILL signal to all processes..."; { - killall5 -KILL - } - - log "Unmounting filesystems and disabling swap..." \ - "Remounting rootfs as readonly"; { - swapoff -a - umount -rat nosysfs,noproc,nodevtmpfs,notmpfs - mount -o remount,ro / - - sync - } - - log "Deactivating dmcrypt devices (if any exist)."; { - [ -x /bin/cryptsetup ] && [ -x /bin/dmsetup ] && { - dmsetup ls --target crypt \ - --exec "dmsetup info -c --noheadings -o open,name" | - while read -r drive; do - [ "${drive%%:*}" = "0" ] && cryptsetup close "${drive##*:}" - done - } - } -} - -main diff --git a/rc.boot b/rc.boot new file mode 100755 index 0000000..b5b8782 --- /dev/null +++ b/rc.boot @@ -0,0 +1,177 @@ +#!/bin/sh + +log() { printf '\033[1;36m=>\033[m\033[1m %s\n' "$@" ;} + +welcome() { printf '\033[1;36m=>\033[m\033[1m Welcome to\033[35m Carbs Linux\033[m\033[1m!\n' ;} + +error() { printf '\033[1m\033[31m=> ERROR: %s\033[m\n' "$@" ;} + +mnt() { + mountpoint -q "$1" || { + dir=$1 + shift + mount "$@" "$dir" + } +} + +emergency_shell() { + error \ + "Cannot continue init due to errors above, starting emergency shell" \ + "When ready, type 'exit' to continue the boot." + + /bin/sh -l +} + +main() { + PATH=/usr/bin:/usr/sbin + old_ifs=$IFS + set -f + + welcome + + log "Mounting pseudo filesystems..."; { + mnt /proc -o nosuid,noexec,nodev -t proc proc + mnt /sys -o nosuid,noexec,nodev -t sysfs sys + mnt /run -o mode=0755,nosuid,nodev -t tmpfs run + mnt /dev -o mode=0755,nosuid -t devtmpfs dev + + mkdir -pm 0755 /run/runit \ + /run/lvm \ + /run/user \ + /run/lock \ + /run/log \ + /dev/pts \ + /dev/shm + + mnt /dev/pts -o mode=0620,gid=5,nosuid,noexec -nt devpts devpts + mnt /dev/shm -o mode=1777,nosuid,nodev -nt tmpfs shm + } + + log "Starting eudev..."; { + command -v udevd >/dev/null && { + udevd --daemon + udevadm trigger --action=add --type=subsystems + udevadm trigger --action=add --type=devices + udevadm settle + } + } + + log "Remounting rootfs as ro..."; { + mount -o remount,ro / || emergency_shell + } + + log "Activating encrypted devices (if any exist)..."; { + [ -e /etc/crypttab ] && [ -x /bin/cryptsetup ] && { + exec 3<&0 + + while read -r name dev pass opts err; do + [ "${name##\#*}" ] || continue + + # Break on invalid crypttab. + [ "$err" ] && { + printf 'error: A valid crypttab has only 4 columns.\n' + break + } + + # Turn 'UUID=*' lines into device names. + [ "${dev##UUID*}" ] || dev=$(blkid -l -o device -t "$dev") + + # Parse options by turning list into a pseudo array. + IFS=, + set -- $opts + IFS=$old_ifs + + copts="cryptsetup luksOpen" + + # Create an argument list (no other way to do this in sh). + for opt; do case $opt in + discard) copts="$copts --allow-discards" ;; + readonly|read-only) copts="$copts -r" ;; + tries=*) copts="$copts -T ${opt##*=}" ;; + esac; done + + # If password is 'none', '-' or empty ask for it. + case $pass in + none|-|"") $copts "$dev" "$name" <&3 ;; + *) $copts -d "$pass" "$dev" "$name" ;; + esac + done < /etc/crypttab + + exec 3>&- + + [ "$copts" ] && [ -x /bin/vgchance ] && { + log "Activating LVM devices for dm-crypt..." + vgchange --sysinit -a y || emergency_shell + } + } + } + + log "Checking filesystems..."; { + fsck -ATat noopts=_netdev + [ $? -gt 1 ] && emergency_shell + } + + log "Mounting rootfs rw..."; { + mount -o remount,rw / || emergency_shell + } + + log "Mounting all local filesystems..."; { + mount -at nosysfs,nonfs,nonfs4,nosmbfs,nocifs -O no_netdev || + emergency_shell + } + + log "Enabling swap..."; { + swapon -a || emergency_shell + } + + log "Seeding random..."; { + if [ -f /var/random.seed ]; then + cat /var/random.seed > /dev/urandom + else + log "This may hang." + log "Mash the keyboard to generate entropy..." + + dd count=1 bs=512 if=/dev/random of=/var/random.seed + fi + } + + log "Setting up loopback..."; { + ip link set up dev lo + } + + log "Setting hostname..."; { + read -r hostname < /etc/hostname + printf '%s\n' "${hostname:-carbs-linux}" > /proc/sys/kernel/hostname + } 2>/dev/null + + log "Getting keymap settings..."; { + [ -r "/etc/keymap" ] && . /etc/keymap + [ -n "$KEYMAP" ] && loadkmap < "$KEYMAP" + } + + log "Loading sysctl settings..."; { + find /run/sysctl.d \ + /etc/sysctl.d \ + /usr/local/lib/sysctl.d \ + /usr/lib/sysctl.d \ + /lib/sysctl.d \ + /etc/sysctl.conf \ + -name \*.conf -type f 2>/dev/null \ + | while read -r conf; do + seen="$seen ${conf##*/}" + + case $seen in + *" ${conf##*/} "*) ;; + *) printf '%s\n' "* Applying $conf ..." + sysctl -p "$conf" ;; + esac + done + } + + command -v udevd >/dev/null && + udevadm control --exit + + log "Boot stage complete..." +} + +main diff --git a/rc.shutdown b/rc.shutdown new file mode 100755 index 0000000..9dba627 --- /dev/null +++ b/rc.shutdown @@ -0,0 +1,48 @@ +#!/bin/sh + +log() { printf '\033[36;1m=>\033[m\033[1m %s\n' "$@" ;} + +main() { + PATH=/sbin:/bin:/usr/sbin:/usr/bin + + log "Waiting for services to stop..."; { + sv -w196 force-stop /var/service/* + sv exit /var/service/* + } + + log "Saving random seed..."; { + dd count=1 bs=512 if=/dev/random of=/var/random.seed + } + + halt -w + + log "Sending TERM signal to all processes..."; { + killall5 -TERM + sleep 1 + } + + log "Sending KILL signal to all processes..."; { + killall5 -KILL + } + + log "Unmounting filesystems and disabling swap..." \ + "Remounting rootfs as readonly"; { + swapoff -a + umount -rat nosysfs,noproc,nodevtmpfs,notmpfs + mount -o remount,ro / + + sync + } + + log "Deactivating dmcrypt devices (if any exist)."; { + [ -x /bin/cryptsetup ] && [ -x /bin/dmsetup ] && { + dmsetup ls --target crypt \ + --exec "dmsetup info -c --noheadings -o open,name" | + while read -r drive; do + [ "${drive%%:*}" = "0" ] && cryptsetup close "${drive##*:}" + done + } + } +} + +main -- cgit v1.2.3