Browse Source

first commit

2.3.1
obarun 3 years ago
commit
c3f9e50170
  1. 4
      .gitignore
  2. 6
      AUTHORS
  3. 14
      LICENSE
  4. 44
      Makefile
  5. 5
      NEWS
  6. 380
      configure
  7. 3
      package/info
  8. 5
      package/modes
  9. 11
      package/targets.mak
  10. 106
      scripts/crypt.awk
  11. 71
      scripts/modules.sh
  12. 14
      scripts/rc.local
  13. 411
      scripts/tmpfiles.sh
  14. 12
      service/boot/All
  15. 17
      service/boot/all-Local
  16. 12
      service/boot/all-Mount
  17. 24
      service/boot/all-Runtime
  18. 19
      service/boot/all-System
  19. 9
      service/boot/earlier-service/tty12
  20. 31
      service/boot/local/local-authfiles
  21. 27
      service/boot/local/local-dmesg
  22. 46
      service/boot/local/local-ip6tables
  23. 46
      service/boot/local/local-iptables
  24. 17
      service/boot/local/local-loop
  25. 34
      service/boot/local/local-rc
  26. 21
      service/boot/local/local-time
  27. 23
      service/boot/local/local-tmpfiles
  28. 19
      service/boot/mount/00
  29. 12
      service/boot/mount/all-Mount
  30. 60
      service/boot/mount/mount-cgroups
  31. 22
      service/boot/mount/mount-dev
  32. 25
      service/boot/mount/mount-fstab
  33. 21
      service/boot/mount/mount-proc
  34. 39
      service/boot/mount/mount-pts
  35. 21
      service/boot/mount/mount-run
  36. 19
      service/boot/mount/mount-rw
  37. 39
      service/boot/mount/mount-shm
  38. 33
      service/boot/mount/mount-swap
  39. 21
      service/boot/mount/mount-sys
  40. 33
      service/boot/mount/mount-tmp
  41. 36
      service/boot/mount/mount-zfs
  42. 42
      service/boot/mount/populate/populate-dev
  43. 25
      service/boot/mount/populate/populate-run
  44. 66
      service/boot/mount/populate/populate-sys
  45. 15
      service/boot/mount/populate/populate-tmp
  46. 26
      service/boot/system/devices/devices-btrfs
  47. 32
      service/boot/system/devices/devices-crypttab
  48. 26
      service/boot/system/devices/devices-dmraid
  49. 32
      service/boot/system/devices/devices-lvm
  50. 24
      service/boot/system/modules/modules-kernel
  51. 21
      service/boot/system/modules/modules-system
  52. 12
      service/boot/system/system-Devices
  53. 26
      service/boot/system/system-fontnkey
  54. 35
      service/boot/system/system-fsck
  55. 19
      service/boot/system/system-hostname
  56. 49
      service/boot/system/system-hwclock
  57. 37
      service/boot/system/system-random
  58. 27
      service/boot/system/system-sysctl
  59. 18
      service/boot/system/udev/udevadm
  60. 25
      service/boot/system/udev/udevd
  61. 64
      tools/install.sh

4
.gitignore vendored

@ -0,0 +1,4 @@
boot-66serv/
config.mak
boot.conf

6
AUTHORS

@ -0,0 +1,6 @@
Main author:
Eric Vidal <eric@obarun.org>
Contributors:
Danilo Spinella <danyspin97@protonmail.com>

14
LICENSE

@ -0,0 +1,14 @@
Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
All rights reserved.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

44
Makefile

@ -0,0 +1,44 @@
#
# This Makefile requires GNU make.
#
# Do not make changes here.
# Use the included .mak files.
#
make_need := 3.81
ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))"
fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer)
endif
-include config.mak
include package/targets.mak
INSTALL := ./tools/install.sh
install: install-conf install-lib-scripts install-sysadm-scripts install-service
install-conf: $(CONF_TARGETS:boot.conf=$(DESTDIR)$(boot_conf))
install-lib-scripts: $(SCRIPTS_LIB_TARGETS:scripts/%=$(DESTDIR)$(scripts)/%)
install-sysadm-scripts: $(SCRIPTS_SYSADM_TARGETS:scripts/%=$(DESTDIR)$(sysconfdir)/%)
install-service: $(SERVICES_TARGETS:service/%=$(DESTDIR)$(service_directory)/%)
$(DESTDIR)$(boot_conf): boot.conf
exec $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(sysconfdir)/%: scripts/rc.local
exec $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(scripts)/%: scripts/%
exec $(INSTALL) -D -m 755 $< $@
sed -i -e 's,@BINDIR@,$(bindir),' $@
$(DESTDIR)$(service_directory)/%: service/%
exec $(INSTALL) -D -m 644 $< $@
sed -i -e 's,@BOOTCONF@,$(boot_conf),' -e 's,@SCRIPTS@,$(scripts),' \
-e 's,@INITCONF@,$(init_conf),' $@
version:
@echo $(version)
.PHONY: install version
.DELETE_ON_ERROR:

5
NEWS

@ -0,0 +1,5 @@
Changelog for boot-66serv
In 0.1.0.0
----------
- first commit.

380
configure vendored

@ -0,0 +1,380 @@
#!/bin/sh
. package/info
usage () {
cat <<EOF
Usage: $0 [OPTION]... [TARGET]
Defaults for the options are specified in brackets.
Installation directories:
--prefix=PREFIX main installation prefix [/]
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
Fine tuning of the installation directories:
--bindir=BINDIR user executables [EPREFIX/bin]
--libdir=LIBDIR static library files [PREFIX/lib/$ss_dir]
--sysconfdir=SYSDIR global configuration files [/etc/66]
--shebangdir=DIR absolute path for execline #\! invocations [BINDIR]
--with-service-directory=DIR service intallation directory [LIBDIR/service]
--with-boot-conf=DIR installation directory of boot.conf [SYSDIR]
--with-init-conf=DIR init.conf skeleton file of 66-boot [SYSDIR]
--with-scripts=DIR installation directory of scripts [LIBDIR/scripts]
Fine tunning of boot configuration:
--HOSTNAME=VALUE HOSTNAME of the system [obliveS6]
--HARDWARECLOCK=VALUE set the hardware clock [UTC]
--TZ=VALUE set timezone [GMT]
--KEYMAP=VALUE set the console keymap [!us]
--FONT=VALUE set the console font [!lat9w-16]
--FONT_MAP=VALUE set the console map []
--FONT_UNIMAP=VALUE set the console unimap []
--CRYPTTAB=BOOLEAN use crypttab by default [!no]
--IPTABLES=BOOLEAN use iptables by default [!no]
--IP6TABLES=BOOLEAN use ip6tables by default [!no]
--FSTAB=BOOLEAN mount devices from fstab [!yes]
--CGROUPS=BOOLEAN mount cgroups [!yes]
--SWAP=BOOLEAN mount swap [!no]
--LVM=BOOLEAN mount lvm devices [!no]
--DMRAID=BOOLEAN mount dmraid devices [!no]
--BTRFS=BOOLEAN mount btrfs devices [!no]
--ZFS=BOOLEAN mount zfs devices [!no]
--SYSCTL=BOOLEAN configure kernel runtime with sysctl [!yes]
--FORCECHCK=BOOLEAN force a check of the filesystem [!no]
--LOCAL=BOOLEAN use rc.local scripts [!no]
Use yes or no with lowercase character to set BOOLEAN values.
Empty value is a commented one in boot.conf file and not used at all.
An exclamation mark '!' at the begin of the value unexport the variable
for the environment after the use. This is avoid to poluate the environment
with tempory variables.
EOF
exit 0
}
# Helper functions
# If your system does not have printf, you can comment this, but it is
# generally not a good idea to use echo.
# See http://www.etalabs.net/sh_tricks.html
echo () {
IFS=" "
printf %s\\n "$*"
}
quote () {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
$1
EOF
echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g"
}
fail () {
echo "$*"
exit 1
}
fnmatch () {
eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac"
}
cmdexists () {
type "$1" >/dev/null 2>&1
}
stripdir () {
while eval "fnmatch '*/' \"\${$1}\"" ; do
eval "$1=\${$1%/}"
done
}
testval () {
if test -z ${1}; then
return 0 ;
else
return 1 ;
fi
}
# Actual script
prefix=
exec_prefix='$prefix'
bindir='$exec_prefix/bin'
libdir='$prefix/lib/$ss_dir'
sysconfdir='/etc/66'
shebangdir='$bindir'
service_directory='$libdir/service'
boot_conf='$sysconfdir/boot.conf'
init_conf='$sysconfdir/init.conf'
scripts='$libdir/scripts'
HOSTNAME='obliveS6'
HARDWARECLOCK='UTC'
TZ='GMT'
KEYMAP='!us'
FONT='!lat9w-16'
FONT_MAP=
FONT_UNIMAP=
CRYPTTAB='!no'
IPTABLES='!no'
IP6TABLES='!no'
FSTAB='!yes'
CGROUPS='!yes'
SWAP='!no'
LVM='!no'
DMRAID='!no'
BTRFS='!no'
ZFS='!no'
SYSCTL='!yes'
FORCECHCK='!no'
LOCAL='!no'
for arg ; do
case "$arg" in
--help) usage ;;
--prefix=*) prefix=${arg#*=} ;;
--exec-prefix=*) exec_prefix=${arg#*=} ;;
--bindir=*) bindir=${arg#*=} ;;
--libdir=*) libdir=${arg#*=} ;;
--sysconfdir=*) sysconfdir=${arg#*=} ;;
--datarootdir=*) datarootdir=${arg#*=} ;;
--shebangdir=*) shebangdir=${arg#*=} ;;
--with-service-directory=*) service_directory=${arg#*=} ;;
--with-boot-conf=*) boot_conf=${arg#*=} ;;
--with-init-conf=*) init_conf=${arg#*=} ;;
--with-scripts=*) scripts=${arg#*=} ;;
--HOSTNAME=*) HOSTNAME=${arg#*=} ;;
--HARDWARECLOCK=*) HARDWARECLOCK=${arg#*=} ;;
--TZ=*) TZ=${arg#*=} ;;
--KEYMAP=*) KEYMAP=${arg#*=} ;;
--FONT=*) FONT=${arg#*=} ;;
--FONT_MAP=*) FONT_MAP=${arg#*=} ;;
--FONT_UNIMAP=*) FONT_UNIMAP=${arg#*=} ;;
--CRYPTTAB=*) CRYPTTAB=${arg#*=} ;;
--IPTABLES=*) IPTABLES=${arg#*=} ;;
--IP6TABLES=*) IP6TABLES=${arg#*=} ;;
--FSTAB=*) FSTAB=${arg#*=} ;;
--CGROUPS=*) CGROUPS=${arg#*=} ;;
--SWAP=*) SWAP=${arg#*=} ;;
--LVM=*) LVM=${arg#*=} ;;
--DMRAID=*) DMRAID=${arg#*=} ;;
--BTRFS=*) BTRFS=${arg#*=} ;;
--ZFS=*) ZFS=${arg#*=} ;;
--SYSCTL=*) SYSCTL=${arg#*=} ;;
--FORCECHCK=*) FORCECHCK=${arg#*=} ;;
--LOCAL=*) LOCAL=${arg#*=} ;;
-* ) echo "$0: unknown option $arg" ;;
*=*) ;;
*) target=$arg ;;
esac
done
# Add /usr in the default case
if test -z "$prefix" ; then
if test "$libdir" = '$prefix/lib/$ss_dir' ; then
libdir=/usr/lib/$ss_dir
fi
fi
if test -z "$sysconfdir" ; then
if test "$sysconfdir" = '$sysconfdir' ; then
sysconfdir = '/etc/66'
fi
if test "$boot_conf" = '$sysconfdir/boot.conf' ; then
boot_conf = '$sysconfdir/boot.conf'
fi
if test "$init_conf" = '$sysconfdir/init.conf' ; then
boot_conf = '$sysconfdir/init.conf'
fi
fi
# Expand installation directories
stripdir prefix
for i in exec_prefix bindir libdir shebangdir ; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
done
stripdir sysconfdir
for i in service_directory scripts boot_conf init_conf; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
done
for i in HOSTNAME HARDWARECLOCK TZ KEYMAP FONT FONT_MAP \
FONT_UNIMAP CRYPTTAB IPTABLES IP6TABLES FSTAB \
CGROUPS SWAP LVM DMRAID BTRFS ZFS \
SYSCTL FORCECHCK LOCAL ; do
eval tmp=\${$i}
if testval $tmp; then
eval $i='#${i}='
else
eval $i='$i=$tmp'
fi
done
# Get usable temp filenames
i=0
set -C
while : ; do
i=$(($i+1))
tmpc="./tmp-configure-$$-$PPID-$i.c"
tmpe="./tmp-configure-$$-$PPID-$i.tmp"
2>|/dev/null > "$tmpc" && break
2>|/dev/null > "$tmpe" && break
test "$i" -gt 50 && fail "$0: cannot create temporary files"
done
set +C
trap 'rm -f "$tmpc" "$tmpe"' EXIT ABRT INT QUIT TERM HUP
echo "creating config.mak..."
cmdline=$(quote "$0")
for i ; do cmdline="$cmdline $(quote "$i")" ; done
exec 3>&1 1>config.mak
cat << EOF
# This file was generated by:
# $cmdline
# Any changes made here will be lost if configure is re-run.
version := $version
prefix := $prefix
exec_prefix := $exec_prefix
bindir := $bindir
libdir := $libdir
sysconfdir := $sysconfdir
shebangdir := $shebangdir
service_directory := $service_directory
boot_conf := $boot_conf
init_conf := $init_conf
scripts := $scripts
EOF
exec 1>&3 3>&-
echo " ... done."
echo "creating boot.conf..."
exec 3>&1 1> boot.conf
cat <<EOF
# Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# $boot_conf - system configuration for Obarun running s6/s6-rc supervision suite
# and handled by 66 suite program.
#
# Do not use quotes or double-quotes on this file
#
# The '!' is used to unexport the variable from the environment.
# If you want to keep it, remove the exclamation mark '!'.
######################
## MAIN ##
######################
## Set the HOSTNAME.
$HOSTNAME
## Set RTC [UTC|localtime].
$HARDWARECLOCK
## Set timezone, availables timezones at /usr/share/zoneinfo.
$TZ
## keymap to load, see loadkeys(8).
$KEYMAP
## Console font to load, see setfont(8).
$FONT
## Console map to load, see setfont(8).
$FONT_MAP
## Console unimap to load, see setfont(8).
$FONT_UNIMAP
######################
## SECURITY ##
######################
## Active encrypted devices [yes|no].
$CRYPTTAB
## Use iptables [yes|no].
$IPTABLES
## Use ip6tables [yes|no].
$IP6TABLES
######################
## DEVICES ##
######################
## Mount devices from FSTAB file [yes|no].
$FSTAB
## Mount cgroups [yes|no].
$CGROUPS
## Active swap [yes|no].
$SWAP
## Active lvm devices [yes|no].
$LVM
## Active dmraid devices [yes|no].
$DMRAID
## Active btrfs devices [yes|no].
$BTRFS
## Mount zfs devices [yes|no].
$ZFS
######################
## SYSTEM ##
######################
## Kernel configuration with sysctl [yes|no].
$SYSCTL
## Force a check of filesystem partition [yes|no].
$FORCECHCK
## Use rc.local script [yes|no].
$LOCAL
EOF
exec 1>&3 3>&-
echo " ... done."

3
package/info

@ -0,0 +1,3 @@
package=boot-66serv
version=0.1.0.0
ss_dir=66

5
package/modes

@ -0,0 +1,5 @@
crypt.awk 0644
modules.sh 0755
rc.local 0755
tmpfiles.sh 0755
boot.conf 0644

11
package/targets.mak

@ -0,0 +1,11 @@
SCRIPTS_LIB_TARGETS := \
scripts/crypt.awk \
scripts/modules.sh \
scripts/tmpfiles.sh
SCRIPTS_SYSADM_TARGETS := scripts/rc.local
CONF_TARGETS := boot.conf
SERVICES_TARGETS := $(shell find service/boot -type f)

106
scripts/crypt.awk

@ -0,0 +1,106 @@
/^#/ || /^$/ { next }
# This file come from Void distribution (https://github.com/void-linux/void-runit/blob/master/crypt.awk)
# All credits goes to this team.
# Many thanks at them to provide this good awk program.
NF>4 { print "a valid crypttab has max 4 cols not " NF >"/dev/stderr"; next }
{
# decode the src variants
split($2, o_src, "=")
if (o_src[1] == "UUID") ("blkid -l -o device -t " $2) | getline src;
else src=o_src[1];
# no password or none is given, ask fo it
if ( NF == 2 ) {
ccmd="cryptsetup luksOpen " src " " $1;
system(ccmd);
ccmd="";
}
else if (NF == 3 ) {
dest=$1
key=$3
split($3, po, "=");
if ( po[1] == "none") ccmd="cryptsetup luksOpen " src " " dest;
else ccmd="cryptsetup luksOpen -d " key " " src" " dest;
system(ccmd);
ccmd="";
}
else {
# the option field is not empty parse the options
dest=$1
key=$3
split($4, opts, ",");
commonopts="";
swapopts="";
luksopts="";
for(i in opts) {
split(opts[i], para, "=");
par=para[1];
val=para[2];
if ( par == "readonly" || par == "read-only") commonopts=commonopts "-r ";
else if ( par == "discard" ) commonopts=commonopts "--allow-discards ";
else if ( par == "tries" ) commonopts=commonopts "-T " val " ";
else if ( par == "swap" ) makeswap="y";
else if ( par == "cipher" ) swapopts=swapopts "-c " val " ";
else if ( par == "size" ) swapopts=swapopts "-s " val " ";
else if ( par == "hash" ) swapopts=swapopts "-h " val " ";
else if ( par == "offset" ) swapopts=swapopts "-o " val " ";
else if ( par == "skip" ) swapopts=swapopts "-p " val " ";
else if ( par == "verify" ) swapopts=swapopts "-y ";
#else if ( par == "noauto" )
#else if ( par == "nofail" )
#else if ( par == "plain" )
#else if ( par == "timeout" )
#else if ( par == "tmp" )
else if ( par == "luks" ) use_luks="y";
else if ( par == "keyscript" ) {use_keyscript="y"; keyscript=val;}
else if ( par == "keyslot" || par == "key-slot" ) luksopts=luksopts "-S " val " ";
else if ( par == "keyfile-size" ) luksopts=luksopts "-l " val " ";
else if ( par == "keyfile-offset" ) luksopts=luksopts "-keyfile-offset=" val " ";
else if ( par == "header" ) luksopts=luksopts "--header=" val " ";
else {
print "option: " par " not supported " >"/dev/stderr";
makeswap="";
use_luks="";
use_keyscript="";
next;
}
}
if ( makeswap == "y" && use_luks != "y" ) {
ccmd="cryptsetup " swapopts commonopts "-d " key " create " dest " " src;
ccmd_2="mkswap /dev/mapper/" dest;
makeswap="";
use_luks="";
use_keyscript="";
system(ccmd);
system(ccmd_2);
ccmd="";
ccmd_2="";
next;
}
if ( use_luks == "y" && makeswap != "y" ){
if ( use_keyscript == "y") {
ccmd=keyscript " | cryptsetup " luksopts commonopts "luksOpen -d - " src " " dest;
use_keyscript="";
}
else {
if ( key == "none" ){
ccmd="cryptsetup " luksopts commonopts "luksOpen " src " " dest;
}
else {
ccmd="cryptsetup " luksopts commonopts "luksOpen -d " key " " src " " dest;
}
}
}
else {
print "use swap OR luks as option" >"/dev/stderr";
ccmd="";
}
makeswap="";
use_luks="";
use_keyscript="";
if ( ccmd != ""){
system(ccmd);
ccmd=""
}
}
}

71
scripts/modules.sh

@ -0,0 +1,71 @@
#!@BINDIR@/bash
# Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
# Configuration files are read from directories in
# /usr/lib/modules-load.d, /run/modules-load.d, and /etc/modules-load.d,
# in order of precedence
MODULES_PATH=( "/etc/modules-load.d" "/run/modules-load.d" "/usr/lib/modules-load.d" )
MODULES_NAME=""
MODULES_RESULT=""
check_elements(){
for e in "${@:2}"; do [[ $e == $1 ]] && return 0; done; return 1;
}
check_file(){
local tidy_loop conf
for tidy_loop in ${MODULES_PATH[@]}; do
if [[ -d "${tidy_loop}" ]]; then
for conf in "${tidy_loop}"/*.conf ; do
check_elements ${conf##*/} ${MODULES_NAME[@]}
if (( $? )); then
MODULES_NAME+=("${conf##*/}")
fi
done
fi
done
unset tidy_loop conf
}
check_path(){
local path tidy_loop
for path in ${MODULES_PATH[@]}; do
for tidy_loop in ${MODULES_NAME[@]}; do
if [[ -f "${path}/${tidy_loop}" ]]; then
check_elements "${tidy_loop}" ${MODULES_RESULT[@]##*/}
if (( $? ));then
MODULES_RESULT+=("${path}/${tidy_loop}")
fi
fi
done
done
}
check_file
if [[ -n ${MODULES_NAME[@]} ]]; then
check_path
else
echo "No modules found -- nothing to do"
exit 0
fi
for mod in ${MODULES_RESULT[@]}; do
while read line; do
if [[ "${line:0:1}" == "#" ]] || [[ -z "${line}" ]];then
continue
fi
for check in ${line};do
modprobe -b "${check}" -v | sed 's:insmod [^ ]*/:Load modules :g; s:\.ko\(\.gz\)\? ::g'
done
done < "${mod}"
done
exit 0

14
scripts/rc.local

@ -0,0 +1,14 @@
# Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
#
# Default rc.local for Obarun; add your custom commands here.
#
# This is run by s6 before the user services are executed.
# This file is declared as oneshot service on 66, do not try to launch any daemon with this file.
# Do not forget to set the shebang.

411
scripts/tmpfiles.sh

@ -0,0 +1,411 @@
#!@BINDIR@/sh
# This is a reimplementation of the systemd tmpfiles.d code
# Control creation, deletion, and cleaning of volatile and temporary files
#
# Copyright (c) 2012 Gentoo Foundation
# Released under the 2-clause BSD license.
#
# This instance is a pure-POSIX sh version, written by Robin H Johnson
# <robbat2@gentoo.org>, based on the Arch Linux version as of 2012/01/01:
# http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
#
# See the tmpfiles.d manpage as well:
# http://0pointer.de/public/systemd-man/tmpfiles.d.html
# This script should match the manpage as of 2012/03/12
#
# This file was modified by Eric Vidal <eric@obarun.org> for Obarun
DRYRUN=0
checkprefix() {
n=$1
shift
for x in $@; do
case $n in
${x}*) return 0 ;;
esac
done
return 1
}
warninvalid() {
printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE"
error=$(( error+1 ))
} >&2
dryrun_or_real() {
local dryrun=
[ $DRYRUN -eq 1 ] && dryrun=echo
$dryrun "$@"
}
relabel() {
local path
local paths=$1 mode=$2 uid=$3 gid=$4
for path in ${paths}; do
if [ -e "$path" ]; then
[ -x /sbin/restorecon ] && dryrun_or_real restorecon $CHOPTS "$path"
[ "$uid" != '-' ] && dryrun_or_real chown $CHOPTS "$uid" "$path"
[ "$gid" != '-' ] && dryrun_or_real chgrp $CHOPTS "$gid" "$path"
[ "$mode" != '-' ] && dryrun_or_real chmod $CHOPTS "$mode" "$path"
fi
done
}
splitpath() {
local path=$1
while [ -n "$path" ]; do
echo $path
path=${path%/*}
done
}
_restorecon() {
local path=$1
if [ -x /sbin/restorecon ]; then
dryrun_or_real restorecon -F $(splitpath "$path")
fi
}
_b() {
# Create a block device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
_restorecon "$path"
dryrun_or_real chown $uid:$gid $path
fi
}
_c() {
# Create a character device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
_restorecon "$path"
dryrun_or_real chown $uid:$gid $path
fi
}
_C() {
# recursively copy a file or directory
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real cp -r "$arg" "$path"
_restorecon "$path"
[ "$uid" != '-' ] && dryrun_or_real chown "$uid" "$path"
[ "$gid" != '-' ] && dryrun_or_real chgrp "$gid" "$path"
[ "$mode" != '-' ] && dryrun_or_real chmod "$mode" "$path"
fi
}
_f() {
# Create a file if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ $CREATE -gt 0 ] || return 0
if [ ! -e "$path" ]; then
#dryrun_or_real $CHECKPATH -fq -m "$mode" -o "$uid:$gid" "$path"
dryrun_or_real touch "$path"
dryrun_or_real chmod "$mode" "$path"
dryrun_or_real chown "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
fi
}
_F() {
# Create or truncate a file
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ $CREATE -gt 0 ] || return 0
if [ -e "$path" ]; then
[ -z "$arg" ] || _w "$@"
else
#dryrun_or_real $CHECKPATH -Fq -m "$mode" -o "$uid:$gid" "$path"
dryrun_or_real touch "$path"
dryrun_or_real chmod "$mode" "$path"
dryrun_or_real chown "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
fi
}
_d() {
# Create a directory if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4
[ $CREATE -gt 0 ] || return 0
if [ ! -d "$path" ]; then
dryrun_or_real mkdir -p "$path" 2>/dev/null
_restorecon "$path"
#dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
dryrun_or_real chmod "$mode" "$path"
dryrun_or_real chown "$uid:$gid" "$path"
fi
}
_D() {
# Create or empty a directory
local path=$1 mode=$2 uid=$3 gid=$4
if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
dryrun_or_real find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
_restorecon "$path"
fi
if [ $CREATE -gt 0 ]; then
dryrun_or_real mkdir -p "$path" 2>/dev/null
_restorecon "$path"
#dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
dryrun_or_real chmod "$mode" "$path"
dryrun_or_real chown "$uid:$gid" "$path"
fi
}
_v() {
# Create a subvolume if the path does not exist yet and the file system
# supports this (btrfs). Otherwise create a normal directory.
# TODO: Implement btrfs subvol creation.
_d "$@"
}
_L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && dryrun_or_real ln -s "$arg" "$path"
_restorecon "$path"
}
_p() {
# Create a named pipe (FIFO) if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4
[ $CREATE -gt 0 ] || return 0
if [ ! -p "$path" ]; then
#dryrun_or_real $CHECKPATH -pq -m $mode -o "$uid:$gid" "$path"
dryrun_or_real mkfifo -m "$mode" "$path"
dryrun_or_real chown "$uid:$gid" "$path"
fi
}
_x() {
# Ignore a path during cleaning. Use this type to exclude paths from clean-up as
# controlled with the Age parameter. Note that lines of this type do not
# influence the effect of r or R lines. Lines of this type accept shell-style
# globs in place of of normal path names.
:
# XXX: we don't implement this
}
_X() {
# Ignore a path during cleanup. Use this type to prevent path
# removal as controled with the age parameter. Note that if path is
# a directory, the content of the directory is not excluded from
# clean-up, only the directory itself.
# Lines of this type accept shell-style globs in place of normal path names.
:
# XXX: we don't implement this
}
_r() {
# Remove a file or directory if it exists. This may not be used to remove
# non-empty directories, use R for that. Lines of this type accept shell-style
# globs in place of normal path names.
local path
local paths=$1
[ $REMOVE -gt 0 ] || return 0
for path in ${paths}; do
if [ -f "$path" ]; then
dryrun_or_real rm -f "$path"
elif [ -d "$path" ]; then
dryrun_or_real rmdir "$path"
fi
done
}
_R() {
# Recursively remove a path and all its subdirectories (if it is a directory).
# Lines of this type accept shell-style globs in place of normal path names.
local path
local paths=$1
[ $REMOVE -gt 0 ] || return 0
for path in ${paths}; do
[ -d "$path" ] && dryrun_or_real rm -rf --one-file-system "$path"
done
}
_w() {
# Write the argument parameter to a file, if it exists.
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ -f "$path" ]; then
if [ $DRYRUN -eq 1 ]; then
echo "echo \"$arg\" >>\"$path\""
else
echo "$arg" >>"$path"
fi
fi
}
_z() {
# Set ownership, access mode and relabel security context of a file or
# directory if it exists. Lines of this type accept shell-style globs in
# place of normal path names.
[ $CREATE -gt 0 ] || return 0
relabel "$@"
}
_Z() {
# Recursively set ownership, access mode and relabel security context of a
# path and all its subdirectories (if it is a directory). Lines of this type
# accept shell-style globs in place of normal path names.
[ $CREATE -gt 0 ] || return 0
CHOPTS=-R relabel "$@"
}
BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
EXCLUDE=
PREFIX=
FILE=
fragments=
# XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
tmpfiles_dirs='/usr/lib/tmpfiles.d/ /run/tmpfiles.d/ /etc/tmpfiles.d/'
tmpfiles_basenames=''
tmpfiles_d=''
# Build a list of sorted unique basenames
# directories declared later in the tmpfiles_d array will override earlier
# directories, on a per file basename basis.
# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
for d in ${tmpfiles_dirs} ; do
[ -d $d ] && for f in ${d}/*.conf ; do
case "${f##*/}" in
systemd.conf|systemd-*.conf) continue;;
esac
[ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
done # for f in ${d}
done # for d in ${tmpfiles_dirs}
tmpfiles_basenames="$(printf "${tmpfiles_basenames}\n" | sort -u )"
for b in $tmpfiles_basenames ; do
real_f=''
for d in $tmpfiles_dirs ; do
f=${d}/${b}
[ -f "${f}" ] && real_f=$f
done
[ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
done
while [ $# -gt 0 ]; do
case $1 in
--boot) BOOT=1 ;;
--create) CREATE=1 ;;
--remove) REMOVE=1 ;;
--clean) CLEAN=1 ;; # TODO: Not implemented
--verbose) VERBOSE=1 ;;
--dryrun|--dry-run) DRYRUN=1 ;;
--exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} " ;;
--prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
esac
shift
done
if [ $(( CLEAN )) -eq 1 ] ; then
printf '%s clean mode is not implemented\n' "${0##*/}"
exit 1
fi
if [ "$CREATE$REMOVE" = '00' ]; then
printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--boot] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
exit 1
fi
error=0
# loop through the gathered fragments, sorted globally by filename.
# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
for FILE in $tmpfiles_d ; do
LINENUM=0
### FILE FORMAT ###
# XXX: We ignore the 'Age' parameter
# 1 2 3 4 5 6 7
# Cmd Path Mode UID GID Age Argument
# d /run/user 0755 root root 10d -
# Mode, UID, GID, Age, Argument may be omitted!
# If Cmd ends with !, the line is only processed if --boot is passed
# XXX: Upstream says whitespace is NOT permitted in the Path argument.
# But IS allowed when globs are expanded for the x/r/R/z/Z types.
while read cmd path mode uid gid age arg; do
LINENUM=$(( LINENUM+1 ))
FORCE=0
# Unless we have both command and path, skip this line.
if [ -z "$cmd" -o -z "$path" ]; then
continue
fi
case $cmd in
\#*) continue ;;
esac
while [ ${#cmd} -gt 1 ]; do
case $cmd in
*!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || continue 2 ;;
*+) cmd=${cmd%+}; FORCE=1; ;;
*) warninvalid ; continue 2 ;;
esac
done
# whine about invalid entries
case $cmd in
f|F|w|d|D|v|p|L|c|C|b|x|X|r|R|z|Z) ;;
*) warninvalid ; continue ;;
esac
# fall back on defaults when parameters are passed as '-'
if [ "$mode" = '-' -o "$mode" = '' ]; then
case "$cmd" in
p|f|F) mode=0644 ;;
d|D|v) mode=0755 ;;
C|z|Z|x|r|R|L) ;;
esac
fi
[ "$uid" = '-' -o "$uid" = '' ] && uid=0
[ "$gid" = '-' -o "$gid" = '' ] && gid=0
[ "$age" = '-' -o "$age" = '' ] && age=0
[ "$arg" = '-' -o "$arg" = '' ] && arg=''
set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg"
[ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue
[ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue
if [ $FORCE -gt 0 ]; then
case $cmd in
p|L|c|b) [ -f "$path" ] && dryrun_or_real rm -f "$path"
esac
fi
[ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
_$cmd "$@"
rc=$?
if [ "${DRYRUN}" -eq "0" ]; then
[ $rc -ne 0 ] && error=$((error + 1))
fi
done <$FILE
done
exit $error
# vim: set ts=2 sw=2 sts=2 noet ft=sh:

12
service/boot/All

@ -0,0 +1,12 @@
[main]
@type = bundle
@name = All
@description = "First service called to start the system"
@user = ( root )
@contents =
(
all-Mount
all-System
all-Local
all-Runtime
)

17
service/boot/all-Local

@ -0,0 +1,17 @@
[main]
@type = bundle
@name = all-Local
@description = "Local configuration"
@user = ( root )
@contents =
(
mount-rw
local-iptables
local-ip6tables
local-loop
local-time
local-authfiles
local-tmpfiles
local-rc
local-dmesg
)

12
service/boot/all-Mount

@ -0,0 +1,12 @@
[main]
@type=bundle
@name=all-Mount
@description= "Mount all devices"
@user=(root)
@contents=
(
00
mount-cgroups
mount-swap
mount-zfs
)

24
service/boot/all-Runtime

@ -0,0 +1,24 @@
[main]
@type = oneshot
@name = all-Runtime
@description = "Launch all tree enabled of root user"
@user = ( root )
@depends = ( all-Mount all-System all-Local )
@options = ( env )
[start]
@build = auto
@execute = (
execl-envfile ${CONFILE}
66-all -v${VERBOSITY} -l ${LIVE} up
)
[stop]
@build = auto
@execute = (
execl-envfile ${CONFILE}
66-all -v${VERBOSITY} -l ${LIVE} down
)
[environment]
CONFILE=!@INITCONF@

19
service/boot/all-System

@ -0,0 +1,19 @@
[main]
@type = bundle
@name = all-System
@description = "System configuration"
@user = ( root )
@contents =
(
system-hwclock
modules-kernel
system-random
modules-system
system-sysctl
udevd
udevadm
system-fontnkey
system-Devices
system-fsck
mount-fstab
)

9
service/boot/earlier-service/tty12

@ -0,0 +1,9 @@
[main]
@type = classic
@name = tty12
@description = "Launch tty12"
@user = ( root )
[start]
@build = auto
@execute = ( agetty --delay 2 -J 38400 tty12 )

31
service/boot/local/local-authfiles

@ -0,0 +1,31 @@
[main]
@type = oneshot
@name = local-authfiles
@description = "Create tempory authentification files"
@depends = ( mount-rw )
@user = ( root )
@options = ( env )
[start]
@build = auto
@execute =
(
if { 66-echo -- [local-authfiles] starts... }
if -t {
if -nt { s6-test -e ${WTMP} }
foreground {
install -m0664 -o root -g utmp /dev/null ${WTMP}
}
}
if -t {
if -nt { s6-test -e ${BTMP} }
foreground {
install -m0600 -o root -g utmp /dev/null ${BTMP}
}
}
66-echo -- [local-authfiles] started successfully
)
[environment]
WTMP=!/var/log/wtmp
BTMP=!/var/log/btmp

27
service/boot/local/local-dmesg

@ -0,0 +1,27 @@
[main]
@type = oneshot
@name = local-dmesg
@description = "Saves logs of dmesg"
@options = ( env )
@depends = ( local-rc )
@user = ( root )
[start]
@build = auto
@execute =
(
if { 66-echo -- [local-dmesg] starts... }
foreground {
execl-cmdline -s {
redirfd -w 1 ${LOGFILE}
dmesg ${CMD_ARGS}
}
}
importas ? ?
if { test ${?} == 0 }
66-echo -- [local-dmesg] started successfully
)
[environment]
CMD_ARGS=!--console-off -T
LOGFILE=!/var/log/dmesg.log

46
service/boot/local/local-ip6tables

@ -0,0 +1,46 @@
[main]
@type = oneshot
@name = local-ip6tables
@description = "Restore ip6tables rules"
@depends = ( mount-rw )
@user = ( root )
@options = ( env )
[start]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test ${IP6TABLES} = yes }
{
if { s6-test -e ${IPRULES} }
if { 66-echo -- [local-iptables] starts... }
foreground {
ip6tables-restore ${IPRULES}
}
importas ? ?
if { test ${?} == 0 }
66-echo -- [local-ip6tables] started successfully
}
66-echo -- [local-ip6tables] desactived
)
[stop]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test ${IP6TABLES} = yes }
{
if { s6-test -x ${IPFLUSH} }
if { 66-echo -- [local-ip6tables] stops... }
if { ${IPFLUSH} }
66-echo -- [local-ip6tables] stopped successfully
}
66-echo -- [local-ip6tables] desactived
)
[environment]
CONFILE=!@BOOTCONF@
IPRULES=!/etc/iptables/ip6tables.rules
IPFLUSH=!/usr/lib/iptables/scripts/ip6tables-flush

46
service/boot/local/local-iptables

@ -0,0 +1,46 @@
[main]
@type = oneshot
@name = local-iptables
@description = "Restore iptables rules"
@depends = ( mount-rw )
@user = ( root )
@options = ( env )
[start]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test ${IPTABLES} = yes }
{
if { s6-test -e ${IPRULES} }
if { 66-echo -- [local-iptables] starts... }
foreground {
iptables-restore ${IPRULES}
}
importas ? ?
if { test ${?} == 0 }
66-echo -- [local-iptables] started successfully
}
66-echo -- [local-iptables] desactived
)
[stop]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test ${IPTABLES} = yes }
{
if { s6-test -x ${IPFLUSH} }
if { 66-echo -- [system-iptables] stops... }
if { ${IPFLUSH} }
66-echo -- [local-iptables] stopped successfully
}
66-echo -- [local-iptables] desactived
)
[environment]
CONFILE=!@BOOTCONF@
IPRULES=!/etc/iptables/iptables.rules
IPFLUSH=!/usr/lib/iptables/scripts/iptables-flush

17
service/boot/local/local-loop

@ -0,0 +1,17 @@
[main]
@type = oneshot
@name = local-loop
@description = "Active loop devices"
@depends = ( mount-rw local-iptables local-ip6tables )
@user = ( root )
[start]
@build = auto
@execute =
(
if { 66-echo -- [local-loop] starts... }
if { ip link set up dev lo }
66-echo -- [local-loop] started successfully
)

34
service/boot/local/local-rc

@ -0,0 +1,34 @@
[main]
@type = oneshot
@name = local-rc
@description = "Run rc.local script"
@options = ( env )
@user = ( root )
@depends = (
mount-rw
local-iptables
local-ip6tables
local-loop
local-time
local-authfiles
local-tmpfiles )
[start]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test $LOCAL = yes }
{
if { 66-echo -- [local-rc] starts... }
foreground { ${SCRIPTS} }
importas ? ?
if { test ${?} == 0 }
66-echo -- [local-rc] started successfully
}
66-echo -- [local-rc] desactived
)
[environment]
CONFILE=!@BOOTCONF@
SCRIPTS=!@SCRIPTS@/rc.local

21
service/boot/local/local-time

@ -0,0 +1,21 @@
[main]
@type = oneshot
@name = local-time
@description = "Set localtime"
@options = ( env )
@depends = ( mount-rw )
@user = ( root )
[start]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
if { 66-echo -- [local-time] starts... }
if { s6-ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime }
66-echo -- [local-time] started successfully
)
[environment]
CONFILE=!@BOOTCONF@

23
service/boot/local/local-tmpfiles

@ -0,0 +1,23 @@
[main]
@type = oneshot
@name = local-tmpfiles
@description = "Create tempory files"
@depends = ( mount-rw )
@user = ( root )
@options = ( env )
[start]
@build = auto
@execute =
(
if { 66-echo -- [local-tmpfiles] starts... }
foreground {
execl-cmdline -s { ${SCRIPTS} }
}
importas -u ? ?
if { test ${?} == 0 }
66-echo -- [local-tmpfiles] started successfully
)
[environment]
SCRIPTS=!@SCRIPTS@/tmpfiles.sh --create --verbose

19
service/boot/mount/00

@ -0,0 +1,19 @@
[main]
@type = bundle
@name = 00
@description = "Set the hostname and mount filesystem"
@user = ( root )
@contents = (
system-hostname
mount-run
populate-run
mount-tmp
populate-tmp
mount-proc
mount-sys
populate-sys
mount-dev
mount-pts
mount-shm
populate-dev
)

12
service/boot/mount/all-Mount

@ -0,0 +1,12 @@
[main]
@type=bundle
@name=all-Mount
@user=(root)
@contents=
(
00
mount-cgroups
mount-fstab
mount-swap
mount-zfs
)

60
service/boot/mount/mount-cgroups

<
@ -0,0 +1,60 @@
[main]
@type = oneshot
@name = mount-cgroups
@description = "mount cgroups hierarchy"
@options = ( env )
@user = ( root )
@depends = ( mount-sys )
[start]
@build = auto
@execute =
(
execl-envfile ${CONFILE}
ifelse -X { s6-test ${CGROUPS} = yes }
{
foreground
{
if { 66-echo -- [mount-cgroups] starts... }
if { mkdir -p -m 0755 /sys/fs/cgroup }
if { s6-mount -wt tmpfs cgroup /sys/fs/cgroup }
redirfd -r 0 /proc/cgroups
pipeline { s6-tail -n +2 }
pipeline { s6-cut -d"\t" -f1 }
pipeline { s6-grep -vF -- devices }
forstdin -d"\n" -- i
importas -iu i i
if { s6-mkdir /sys/fs/cgroup/${i} }
foreground { s6-mount -t cgroup -o ${i} -- cgroup /sys/fs/cgroup/${i} }
}
66-echo -- [mount-cgroups] started successfully
}
66-echo -- [mount-cgroups] desactived
)