galeb

Једноставна статичка дистрибуција заснована на musl-у
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување e448a0293e3cf502b2a2454e0af016e11f7ddfc1
родитељ 24f64234a926565f6dc7d22bb8285ac445c4e7dc
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Wed, 20 Jul 2022 12:43:52 +0200

fil/svc.d -> svc repo; change shutdown strategy; add opendoas; update TODO

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
M02-chroot.sh | 7+++++--
M03-packages.sh | 36++++++++++++++++++++++++++++++++++++
M04-finale.sh | 8+-------
MBUGS | 2++
MTODO | 33+++++++++++++++++++++++++++++----
Mfil/rc.d/g_fun.sh | 2+-
Mfil/rc.d/rc.init | 21+++++++++------------
Mfil/rc.d/rc.shutdown | 5+++++
Dfil/svc.d/avail/crond | 0
Dfil/svc.d/avail/hwclock | 18------------------
Dfil/svc.d/avail/metalog | 86-------------------------------------------------------------------------------
Dfil/svc.d/avail/sdhcp | 86-------------------------------------------------------------------------------
Dfil/svc.d/default/crond | 2--
Dfil/svc.d/default/hwclock | 3---
Dfil/svc.d/default/metalog | 2--
Dfil/svc.d/default/sdhcp | 2--
Mlib/perms.tsv | 9+++++----
Mlib/pkgs.tsv | 3++-
Apat/sdhcp-galeb/sdhcp-pid-file.patch | 38++++++++++++++++++++++++++++++++++++++
измењених датотека: 19, додавања: 133(+), брисања: 230(-)

diff --git a/02-chroot.sh b/02-chroot.sh @@ -129,8 +129,6 @@ cp_or_fail ${WD}/${FLD}/rc.d/rc.init ${GR}/bin/rc.init cp_or_fail ${WD}/${FLD}/rc.d/rc.shutdown ${GR}/bin/rc.shutdown cp_or_fail ${WD}/${FLD}/rc.d/rc.svc ${GR}/bin/rc.svc cp_or_fail ${WD}/${FLD}/rc.d/rc.local ${GR}/etc/rc.local -check_dir ${GR}/src/svc.d -cp_or_fail -r ${WD}/${FLD}/svc.d/* ${GR}/src/svc.d/ msg warn "Next run 03-packages.sh" @@ -141,6 +139,11 @@ case "${run_as_root}" in *) chroot ${GR} /${TLD}/bin/mksh -l +h;; esac +msg info "makewhatis /share/man" +makewhatis /share/man +msg info "makewhatis /sucks/share/man" +makewhatis /sucks/share/man + umount ${GR}/tmp umount ${GR}/run umount ${GR}/sys/firmware/efi/efivars diff --git a/03-packages.sh b/03-packages.sh @@ -4450,6 +4450,42 @@ mkpk_install() fi end_substep +begin_substep opendoas-6.8.2 +if [ -x /bin/doas ]; then + msg info "%s exists, skipping %s" /bin/doas ${pkg} +elif [ -e ${G_SPKG}/${pkg}.tar.xz ]; then + unpack_pkg ${pkg} / +else + extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz + ( + cd_or_fail ${G_SRC}/${pkg} + + cat <<! >MKPK +mkpk_name() +{ + printf "%s" "${pkg}" +} + +mkpk_install() +{ + CFLAGS='-Os -pipe -static --static -fcommon' + LDFLAGS='-static --static -fcommon -s' + DESTDIR=/build + export CFLAGS LDFLAGS DESTDIR + + ./configure --prefix=/ --with-timestamp || exit 1 + + make ${JN} || exit 1 + make install +} +! + mkpk ${pkg} + remove_dir ${G_SRC}/${pkg} + unpack_pkg ${pkg} / + ) || exit 1 +fi +end_substep + begin_substep galeb-utils-20220717 if [ ! -x /bin/umountall ]; then ( diff --git a/04-finale.sh b/04-finale.sh @@ -224,7 +224,7 @@ mkpk_install() fi end_substep -begin_substep svc-20220717 +begin_substep svc-20220720 if [ -x /bin/svc ]; then msg info "%s exists, skipping %s" /bin/svc ${pkg} elif [ -e ${G_SPKG}/${pkg}.tar.xz ]; then @@ -232,7 +232,6 @@ elif [ -e ${G_SPKG}/${pkg}.tar.xz ]; then else ( cd_or_fail ${G_SRC}/${pkg} - cp_or_fail -r ${GR}/src/svc.d/* ${GR}/bin/svc.d/ cat <<! >MKPK mkpk_name() @@ -246,11 +245,6 @@ mkpk_install() cp -r svc.d ../build/bin/ mkdir -p ../build/share/doc/${pkg} cp README.md ../build/share/doc/${pkg}/ - mkdir -p ../build/bin/svc.d/avail - cp -r /svc.d/avail/* ../build/bin/svc.d/avail/ - chmod 755 ../build/bin/svc.d/avail/* - mkdir -p ../build/bin/svc.d/default - cp -r /svc.d/default/* ../build/bin/svc.d/default/ } ! mkpk ${pkg} diff --git a/BUGS b/BUGS @@ -14,3 +14,5 @@ Known bugs/Errata be fully functional from that point on, due to sbase/ubase/9base utilities having only a subset of options of coreutils etc. You can revert this by uninstalling sbase, ubase and 9base. + +* mksh exits the current shell when Ctrl-C is pressed. (TODO: Fix.) diff --git a/TODO b/TODO @@ -2,25 +2,37 @@ TODO ==== [~] Fix init scripts - [ ] figure out how to bring down all services cleanly as a regular user - (svc group?) [ ] git://r-36.net/stali-init [ ] http://r-36.net/scm/ [ ] https://codemadness.org/git/ [ ] https://git.2f30.org/ [ ] https://git.suckless.org/ + [x] figure out how to bring down all services cleanly as a regular user + (svc group?) + - Regular user shutting down? Should be handled either by suid + (therefore: not script) calling other things or doas/sup. + Scripts/programs to do specific things like remounting + ro/umounting should just expect root or error out, shouldn't + be suid + - Conclusion (for now): call /bin/rc.shutdown as root with + doas/sup, otherwise error out. Alternative would be to create + dedicated shutdown suid executable (TODO) [x] shutdown, poweroff, reboot [x] Add sdhcp as ~oneshot~ longrun [x] hwclock on shutdown [x] shutdown as regular user (remount / ro) -[ ] Add -h to free +[ ] Fix mksh Ctrl-C bug + +[ ] Patch sdhcp [~] Add packages [ ] git://r-36.net/nldev [ ] git://r-36.net/nlmon [ ] git://r-36.net/rfkilld + [ ] Add X [ ] Add ssh(d) + [x] Add opendoas [x] Add tmux [x] fsck.vfat [x] Add curl (needed for git?) - needed @@ -35,8 +47,20 @@ TODO [/] Replace with axel if not installing curl [x] Add svc + +Low priority +------------ + +< > Create a dedicated shutdown suid executable + +< > Add -h to free + + +Done +---- + [x] Fix dcron - [x] crontab -e doesn't respect EDITOR? + [x] crontab -e doesn't respect EDITOR? - export. [x] Linux [x] /proc/sys/kernel/hotplug/create - Add hotplugging to Linux @@ -48,3 +72,4 @@ TODO [x] Remove /bin/bash in final system [x] suid/sgid doesn't get preserved? + diff --git a/fil/rc.d/g_fun.sh b/fil/rc.d/g_fun.sh @@ -43,7 +43,7 @@ msg() log=0 newline=0;; warn) icon_plain="=W=" - icon="${bgyellow}${black}${icon_plain}";; + icon="${bgyellow}${bold}${black}${icon_plain}";; *) ;; esac printf "%s %s " "${icon}" ${tstamp} diff --git a/fil/rc.d/rc.init b/fil/rc.d/rc.init @@ -75,15 +75,6 @@ if [ -n "${HOSTNAME}" ]; then hostname ${HOSTNAME} fi -msg info "Bringing up lo interface" -ip addr add 127.0.0.1/8 dev lo broadcast + scope host -ip link set lo up - -if [ -n "${INTERFACE}" ]; then - msg info "Bringing up %s" ${INTERFACE} - ip link set "${INTERFACE}" up -fi - msg info "Setting random seed" if [ -f /etc/random-seed ]; then cat /etc/random-seed >/dev/urandom @@ -106,11 +97,17 @@ if [ -x /bin/rc.modules ]; then /bin/rc.modules fi -if [ -x /bin/rc.svc ]; then - msg info "Starting /bin/rc.svc" - /bin/rc.svc +msg info "Bringing up lo interface" +ip addr add 127.0.0.1/8 dev lo broadcast + scope host +ip link set lo up + +if [ -n "${INTERFACE}" ]; then + msg info "Bringing up %s" ${INTERFACE} + ip link set "${INTERFACE}" up fi +service start all + if [ -x /bin/rc.local ]; then msg info "Starting /bin/rc.local" /bin/rc.local diff --git a/fil/rc.d/rc.shutdown b/fil/rc.d/rc.shutdown @@ -8,6 +8,11 @@ umask 022 PATH=/local/bin:/bin:/sucks/bin export PATH +if [ "$(id -u)" -ne 0 ]; then + msg err "You must be root to run $0" + exit 2 +fi + prog=${0##*/} param=$1 case ${prog} in diff --git a/fil/svc.d/avail/crond b/fil/svc.d/avail/crond diff --git a/fil/svc.d/avail/hwclock b/fil/svc.d/avail/hwclock @@ -1,18 +0,0 @@ -#!/bin/sh - -. /etc/rc.conf -. /bin/svc.d/default/hwclock - -if [ -n "${TIMEZONE}" ]; then - TZ=:${TIMEZONE} - export TZ -fi - -case $1 in - -e) ;; # one-shot - -s) hwclock -s ${PARAMS} >/dev/null 2>&1 || exit 2;; - -k) hwclock -w ${PARAMS} >/dev/null 2>&1 || exit 2;; - -r) exit 1;; - *) echo "usage: $0 -s|-k" >&2 - exit 2 -esac diff --git a/fil/svc.d/avail/metalog b/fil/svc.d/avail/metalog @@ -1,86 +0,0 @@ -#!/bin/sh - -svc=metalog -svcbin=/sucks/bin/metalog - -. /bin/svc.d/default/${svc} - -if [ -z "${PIDFILE}" ]; then - exit 2 -fi - -case $1 in - -e) if [ ! -e "${PIDFILE}" ]; then - exit 2 - elif [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ]; then - exit 2 - fi;; - -s) ${svcbin} ${PARAMS} >/dev/null 2>&1 & - tries=4 - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - while [ -z "${childpid}" ] - do - /bin/usleep 100000 - tries=$((tries-1)) - if [ "${tries}" -eq 0 ]; then - exit 2 - fi - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - done - echo "${childpid}" > "${PIDFILE}";; - -k) if [ ! -e "${PIDFILE}" ]; then - exit 1 - elif [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - rm "${PIDFILE}" - exit 1 - else - kill $(<"${PIDFILE}") >/dev/null 2>&1 - if [ -n "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - pkill -9 $(<"${PIDFILE}") >/dev/null 2>&1 \ - || exit 2 - fi - rm "${PIDFILE}" - fi;; - -r) if [ -e "${PIDFILE}" ]; then - if [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - rm "${PIDFILE}" - else - kill $(<"${PIDFILE}") >/dev/null 2>&1 - if [ -n "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - kill -9 $(<"${PIDFILE}") \ - >/dev/null 2>&1 || exit 2 - fi - rm "${PIDFILE}" - fi - fi - ${svcbin} ${PARAMS} >/dev/null 2>&1 & - tries=4 - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - while [ -z "${childpid}" ] - do - /bin/usleep 100000 - tries=$((tries-1)) - if [ "${tries}" -eq 0 ]; then - exit 2 - fi - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - done - echo "${childpid}" > "${PIDFILE}";; -esac diff --git a/fil/svc.d/avail/sdhcp b/fil/svc.d/avail/sdhcp @@ -1,86 +0,0 @@ -#!/bin/sh - -svc=sdhcp -svcbin=/bin/sdhcp - -. /bin/svc.d/default/${svc} - -if [ -z "${PIDFILE}" ]; then - exit 2 -fi - -case $1 in - -e) if [ ! -e "${PIDFILE}" ]; then - exit 2 - elif [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ]; then - exit 2 - fi;; - -s) ${svcbin} ${PARAMS} >/dev/null 2>&1 & - tries=4 - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - while [ -z "${childpid}" ] - do - /bin/usleep 100000 - tries=$((tries-1)) - if [ "${tries}" -eq 0 ]; then - exit 2 - fi - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - done - echo "${childpid}" > "${PIDFILE}";; - -k) if [ ! -e "${PIDFILE}" ]; then - exit 1 - elif [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - rm "${PIDFILE}" - exit 1 - else - kill $(<"${PIDFILE}") >/dev/null 2>&1 - if [ -n "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - pkill -9 $(<"${PIDFILE}") >/dev/null 2>&1 \ - || exit 2 - fi - rm "${PIDFILE}" - fi;; - -r) if [ -e "${PIDFILE}" ]; then - if [ -z "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - rm "${PIDFILE}" - else - kill $(<"${PIDFILE}") >/dev/null 2>&1 - if [ -n "$(ps -ef | awk '{print $2}' | \ - grep $(<"${PIDFILE}"))" ] - then - kill -9 $(<"${PIDFILE}") \ - >/dev/null 2>&1 || exit 2 - fi - rm "${PIDFILE}" - fi - fi - ${svcbin} ${PARAMS} >/dev/null 2>&1 & - tries=4 - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - while [ -z "${childpid}" ] - do - /bin/usleep 100000 - tries=$((tries-1)) - if [ "${tries}" -eq 0 ]; then - exit 2 - fi - childpid=$(ps -ef | \ - awk '{if ($3 = "1" && match($8, "'\ -${svcbin//\//\\\/}'")) print $2}') - done - echo "${childpid}" > "${PIDFILE}";; -esac diff --git a/fil/svc.d/default/crond b/fil/svc.d/default/crond @@ -1,2 +0,0 @@ -PARAMS="-S -l info" -LOGFILE=/var/log/crond.log diff --git a/fil/svc.d/default/hwclock b/fil/svc.d/default/hwclock @@ -1,3 +0,0 @@ -# sbase hwclock only has UTC support -PARAMS="-u /dev/rtc0" - diff --git a/fil/svc.d/default/metalog b/fil/svc.d/default/metalog @@ -1,2 +0,0 @@ -PARAMS="-B -g metalog" -PIDFILE=/var/run/metalog.pid diff --git a/fil/svc.d/default/sdhcp b/fil/svc.d/default/sdhcp @@ -1,2 +0,0 @@ -PARAMS="eth0" -PIDFILE=/var/run/sdhcp.pid diff --git a/lib/perms.tsv b/lib/perms.tsv @@ -4,7 +4,8 @@ Path Mode Owner Group /bin/su 4555 root root /bin/crond 4700 root root /bin/crontab 4750 root cron -/bin/halt 4550 root wheel +/bin/halt 500 root root +/bin/killall5 500 root root /var/log 775 root metalog /var/log/lastlog 664 root utmp /var/log/btmp 600 root utmp @@ -14,7 +15,7 @@ Path Mode Owner Group /var/spool/cron/crontabs 0755 root root /var/run/utmp 664 root utmp /bin/rc.init 555 root root -/bin/rc.shutdown 4555 root wheel +/bin/rc.shutdown 555 root root /bin/rc.svc 555 root root -/bin/remountroot 4750 root wheel -/bin/umountall 4750 root wheel +/bin/remountroot 500 root root +/bin/umountall 500 root root diff --git a/lib/pkgs.tsv b/lib/pkgs.tsv @@ -1,7 +1,7 @@ URL Directory/Tarball MD5 Sum git+https://git.adelielinux.org/adelie/musl-locales.git musl-locales-20220708 git+https://git.sr.ht/~strahinja/reflow reflow-20220716 -git+https://git.sr.ht/~strahinja/svc svc-20220717 +git+https://git.sr.ht/~strahinja/svc svc-20220720 git+https://github.com/cpeuvrel/usleep-aur usleep-20220718 git+https://github.com/mirbsd/mksh mksh-20220709 git+https://github.com/onetrueawk/awk awk-20220709 @@ -113,3 +113,4 @@ https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-29.tar.xz e81e63acd8069 https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-5.17.0.tar.xz 8ade96ee93f37fba7e1beec89f1a54bf https://www.leonerd.org.uk/code/libtermkey/libtermkey-0.22.tar.gz 08bf514d59660391c3a21b3977a16c8c https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tar.xz 11d12076311563252a995201248d17e5 +https://github.com/Duncaen/OpenDoas/releases/download/v6.8.2/opendoas-6.8.2.tar.xz 3ca653c34ec87c0fe8a07ca5f78af35c diff --git a/pat/sdhcp-galeb/sdhcp-pid-file.patch b/pat/sdhcp-galeb/sdhcp-pid-file.patch @@ -0,0 +1,38 @@ +--- sdhcp.c 2022-07-16 22:03:48.635446037 +0200 ++++ sdhcp.c 2022-07-20 11:52:33.300996870 +0200 +@@ -17,10 +17,13 @@ + #include <string.h> + #include <time.h> + #include <unistd.h> ++#include <syslog.h> + + #include "arg.h" + #include "util.h" + ++static const char* pidfile = "/var/run/sdhcp.pid"; ++ + typedef struct bootp { + unsigned char op [1]; + unsigned char htype [1]; +@@ -391,6 +394,7 @@ + int forked = 0, t; + struct itimerspec timeout = { 0 }; + uint32_t renewaltime, rebindingtime, lease; ++ FILE* pid = NULL; + + Init: + dhcpsend(DHCPdiscover, Broadcast); +@@ -447,6 +451,13 @@ + exit(0); + forked = 1; + } ++ if (!(pid = fopen(pidfile, "w"))) ++ syslog(LOG_DAEMON | LOG_ERR, "Cannot open pidfile %s", ++ pidfile); ++ else { ++ fprintf(pid, "%d\n", getpid()); ++ fclose(pid); ++ } + timeout.it_value.tv_sec = renewaltime; + settimeout(0, &timeout); + timeout.it_value.tv_sec = rebindingtime;