#!/bin/sh
# The Lazy Init System for Lazy People
# ------------------------------------
# by: Ethan McTague <ethan@tague.me>
# Copyright 2018 Ethan McTague
# ------------------------------------
#
# This is an init system that sets up
# critical things, opens a login
# screen, and then shuts down when you
# log out.
#
# To use, put it wherver your kernel
# is set to init from (usually /init
# or /sbin/init) and make it
# executable.
#
# Only tested in user-mode linux.
# Might work elsewhere.
# You have been warned.
#
# ------------------------------------
#
# Benefits:
# - Fast boot is convenient for UML.
# - Predictable - literally only bash
# will be running on your system
# once it's booted.
# - It isn't systemd.
#
# Drawbacks:
# - No daemon initialization.
# - Hard-coded mounting behavior.
# - Doesn't use /etc/initctl.
# - Generally a bad idea.
# - Obnoxiously large header comment.
# - It isn't systemd.
#
# ------------------------------------
# Mount Filesystems
mount -t proc proc /proc -o nosuid,noexec,nodev
mount -t sysfs sys /sys -o nosuid,noexec,nodev
mount -t tmpfs run /run -o mode=0755,nosuid,nodev
mount -t devtmpfs dev /dev -o mode=0755,nosuid
mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
# Set Hostname
cat /etc/hostname > /proc/sys/kernel/hostname
# Start Shell (Yes, it must run nested like this.)
/bin/bash -c 'agetty tty0'
# Shut Down
echo e > /proc/sysrq-trigger # SIGTERM to all processes except this one
echo s > /proc/sysrq-trigger # Sync Filesystems
echo u > /proc/sysrq-trigger # Unmount Filysystems
echo o > /proc/sysrq-trigger # Power off
# Wait for Shutdown to Finish
sleep infinity