#!/bin/mkpkg # description: A UNIX init scheme with service supervision # url: http://smarden.org/runit/ # Depends on: musl name=runit version=2.3.1 release=2 source=(https://smarden.org/runit/$name-$version.tar.gz clearmem.patch pause.c pause.1 runit-1 runit-2 runit-3 ctrlaltdel rc.local rc.shutdown) sha256sums=( "634f23c8c4d1d440043be0fe928ddf904626289e97bfe7c5826e93aaf2cc6fe9" "668fd39e94ab68700bcdae3b222525c3255f3f28d43694db017aef9f6e6945a4" "83091fb46163582397acf1235bd7058c2d8466fbbba6a56624f57347b0f4f1fd" "6ecfe607c4cbfa8dd7c21c17aea0c9eea9717bc11b1db85c80b83292dac42ba9" "88f81e4450fadffd032fd56396050c2de37101c7848765510c1a0bd4ce18bb26" "ae562bf4f3be0be448817aefeede23000fadea8f0fa5f8d930ebf57e5e5dd33d" "78b7467339fb909e1491e08ad0af3a0d5fdaab854345bc0aff189f940f5f3ad2" "4c4ccd8a997eeef0b8095620b79e4e72785d28c069bf8c4ff79582bcab074ea7" "d5ad9ed29d75e6c2e6356179b8fb8df35db3c0747b60df9b586e3aa99b88b801" "f49c574801eb148ec744e744ad76659e915ebdbea693dbc48a84d4d4e58fa77c" ) build() { cd "admin/$name-$version" echo "${CC:-cc} ${CFLAGS:--O2 -Wall}" > src/conf-cc echo "${CC:-cc} ${LDFLAGS} -s" > src/conf-ld patch -p1 -i "$SRC/clearmem.patch" ./package/compile ./package/check install -d "$PKG/sbin" install -m755 command/* "$PKG/sbin/" ln -sf runit-init "$PKG/sbin/init" # Reboot/halt/poweroff wrappers (runit doesn't ship these) printf '#!/bin/sh\ntouch /etc/runit/reboot\nchmod 100 /etc/runit/stopit\nkill -CONT 1\n' > "$PKG/sbin/reboot" chmod 755 "$PKG/sbin/reboot" printf '#!/bin/sh\nrm -f /etc/runit/reboot\nchmod 100 /etc/runit/stopit\nkill -CONT 1\n' > "$PKG/sbin/poweroff" chmod 755 "$PKG/sbin/poweroff" ln -sf poweroff "$PKG/sbin/halt" install -d "$PKG/etc/runit" install -d "$PKG/etc/runit/runsvdir/default" install -d "$PKG/etc/runit/runsvdir/single" install -d "$PKG/etc/sv" install -d "$PKG/service" install -m755 "$SRC/runit-1" "$PKG/etc/runit/1" install -m755 "$SRC/runit-2" "$PKG/etc/runit/2" install -m755 "$SRC/runit-3" "$PKG/etc/runit/3" install -m755 "$SRC/ctrlaltdel" "$PKG/etc/runit/" # User-customizable rc scripts go in /etc/ install -m755 "$SRC/rc.local" "$PKG/etc/" install -m755 "$SRC/rc.shutdown" "$PKG/etc/" ln -s "/etc/runit/runsvdir/default" "$PKG/etc/runit/runsvdir/current" # Create agetty services for tty1-6 for i in 1 2 3 4 5 6; do svdir="$PKG/etc/sv/agetty-tty$i" install -d "$svdir" if [ "$i" -eq 1 ]; then printf '#!/bin/sh\nPATH=/bin:/sbin\nexec setsid agetty --noclear tty%s 38400 linux\n' "$i" > "$svdir/run" else printf '#!/bin/sh\nPATH=/bin:/sbin\nexec setsid agetty tty%s 38400 linux\n' "$i" > "$svdir/run" fi chmod 755 "$svdir/run" printf '#!/bin/sh\nPATH=/bin:/sbin\nexec utmpset -w tty%s\n' "$i" > "$svdir/finish" chmod 755 "$svdir/finish" ln -s "/etc/sv/agetty-tty$i" "$PKG/etc/runit/runsvdir/default/" ln -s "/etc/sv/agetty-tty$i" "$PKG/service/" done # Serial getty -- shipped but deliberately NOT linked into # default/ or /service/. A headless install (VPS, `qemu # -nographic`) has no other console and needs it; a laptop with a # registered but unconnected UART does not, and a getty spawning # into a dead port is worse than no getty at all. Enable with: # # ln -s /etc/sv/agetty-ttyS0 /service/ # # ttyS0 must also be in /etc/securetty, or login refuses root there # even with autologin: agetty execs `login -f root`, which skips the # password but still consults securetty. # # The guard matters because a run script that exits immediately # respawns forever, and on hardware with no UART the device node may # not exist at all -- enabling this on the wrong machine would # otherwise give a silent one-per-second fork loop. # # 115200 is what every provider's serial console uses. vt100 rather # than linux: a serial client is not a Linux VT, and claiming # otherwise breaks arrow keys and line drawing. svdir="$PKG/etc/sv/agetty-ttyS0" install -d "$svdir" printf '#!/bin/sh\nPATH=/bin:/sbin\n[ -c /dev/ttyS0 ] || exec sleep 3600\nexec setsid agetty --noclear ttyS0 115200 vt100\n' > "$svdir/run" chmod 755 "$svdir/run" printf '#!/bin/sh\nPATH=/bin:/sbin\nexec utmpset -w ttyS0\n' > "$svdir/finish" chmod 755 "$svdir/finish" # Build and install pause(1) ${CC:-cc} ${CFLAGS:--O2 -Wall} -o "$SRC/pause" "$SRC/pause.c" install -m755 "$SRC/pause" "$PKG/sbin/" install -d "$PKG/usr/share/man/man1" install -m644 "$SRC/pause.1" "$PKG/usr/share/man/man1/" # Create sulogin service for single-user mode sulogindir="$PKG/etc/sv/sulogin" install -d "$sulogindir" printf '#!/bin/sh\nPATH=/bin:/sbin\n[ -r conf ] && . ./conf\nread -r tty < /sys/class/tty/console/active\ntty="/dev/${tty##* }"\nexec setsid sulogin ${OPTS:=-p} < "$tty" > "$tty" 2>&1\n' > "$sulogindir/run" chmod 755 "$sulogindir/run" ln -s "/etc/sv/sulogin" "$PKG/etc/runit/runsvdir/single/" } signify() { untrusted comment: public key RWTZ9IduCSQ/mL8337TEUinPwT92xFEUpD92hkS7IxcOnzTt9QdpohT3 } # vim: filetype=sh