Skip to content

Commit 0a94cb4

Browse files
committed
New package: boot-66serv-2.4.1
1 parent a9c6cec commit 0a94cb4

12 files changed

Lines changed: 2351 additions & 0 deletions

srcpkgs/boot-66serv/INSTALL.msg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Please re-enable the boot@system service after an update,
2+
by running '66-enable -t boot -F boot@system".

srcpkgs/boot-66serv/files/66

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/execlineb -P
2+
66-boot -b "Booting Void Linux" -m
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
# Copyright 2021 mobinmob <mobinmob@disroot.org>
3+
# Use of this source code is governed by the 2-Clause BSD License
4+
# that can be found in the LICENSE file at the root project directory.
5+
# SPDX short identifier: BSD-2-Clause
6+
7+
# This scripts create basic trees and enables services.
8+
# Excluding the common posix userland commands, the script needs 66-yeller
9+
# (from 66-tools), 66-env, 66-tree and 66-enable (from 66).
10+
11+
# Variables for 66-yeller
12+
export PROG="66boot-initial-setup"
13+
export COLOR_ENABLED="1"
14+
export CLOCK_ENABLED="0"
15+
16+
# Script must run as root, otherwise it creates trees
17+
# as the user.
18+
user=$(id -u)
19+
[ "$user" != "0" ] && 66-yeller -F %r You need to run this script as root! %n && exit 1
20+
21+
# Information for the user, in case of failure. 66 output is informative, this
22+
# is just a pointer to the docs.
23+
msg_trees() {
24+
# ${1} is the name of the tree
25+
66-yeller -W %b "An action for the [${1}] tree failed.
26+
Check the output before this message for a possibe cause and consult
27+
the 66-tree documentation." %n
28+
}
29+
30+
msg_services() {
31+
# ${1} is the name of a service
32+
66-yeller -F %r "Enabling the [${1}] service failed.
33+
Check the output before this message for a possibe cause and consult
34+
the 66-enable documentation." %n
35+
exit 1
36+
}
37+
38+
# Create the mandatory boot tree.
39+
66-tree -nz boot || msg_trees boot
40+
# Enable the boot@system service in the boot tree.
41+
66-enable -z -F -t boot boot@system || msg_services boot@system
42+
43+
# Copy the default boot@conf so that it will survive updates and be accesible
44+
# though /etc/66rc.conf. Also, remove the warning in the first lines of the file.
45+
new_conf="/etc/66/conf/boot@system/version/boot@system"
46+
[ ! -f "$new_conf" ] && cp /etc/66/conf/boot@system/version/.boot@system "$new_conf" && \
47+
warn=$( sed -n -e "/##\ \[STARTWARN\]/p" /etc/66rc.conf | tr -d '[:space:]') && \
48+
[ "$warn" = "##[STARTWARN]" ] && sed -i '1,5d' "$new_conf"
49+
50+
# Create default tree, enable it and make it current.
51+
66-tree -z -nEc default || msg_trees default
52+
# Enable switch-initutils oneshot service in the default tree.
53+
66-enable -z switch-initutils || msg_services switch-initutils
54+
55+
# Create and enable runit tree.
56+
66-tree -z -nE runit || msg_trees runit
57+
# Enable the runit service in the runit tree.
58+
66-enable -z -t runit runit || msg_services runit
59+
# Start runit tree after the default tree.
60+
66-tree -z -S default runit || msg_trees runit
61+
62+
# Print on succesfull completion
63+
# shellcheck disable=SC2181
64+
if [ "$?" = 0 ]; then 66-yeller %g "Basic trees created and services enabled succesfully!"; fi
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/sh
2+
# Copyright 2021 mobinmob <mobinmob@disroot.org>
3+
# Use of this source code is governed by the 2-Clause BSD License
4+
# that can be found in the LICENSE file at the root project directory.
5+
# SPDX short identifier: BSD-2-Clause
6+
7+
# This script reads a **valid** rc.conf and writes the values to the
8+
# corresponding configuration options in the boot@system environment file.
9+
# Excluding the common posix userland commands, the script needs 66-yeller
10+
# (from 66-tools) and 66-env (from 66).
11+
12+
# Variables for 66-yeller
13+
export PROG="66boot-rcdotconf"
14+
export COLOR_ENABLED="1"
15+
export CLOCK_ENABLED="0"
16+
17+
18+
# Script must run as root.
19+
user=$(id -u)
20+
[ "$user" != "0" ] && 66-yeller -F %r You need to run this script as root! %n && exit 1
21+
22+
HOSTNAME=
23+
HOSTNAME1=
24+
HARDWARECLOCK=
25+
TIMEZONE=
26+
KEYMAP=
27+
FONT=
28+
FONT_MAP=
29+
FONT_UNIMAP=
30+
TTYS=
31+
32+
apply_conf_from_to(){
33+
# Set configuration value ${3} from ${1} to ${2}
34+
# ${1} is the conf option from /etc/rc.conf
35+
# ${2} is the conf option from the boot@ conf file
36+
# ${3} is the value from the /etc/rc.conf option/var
37+
if [ -n "${3}" ]
38+
then
39+
66-env -t boot -r "${2}"=!"${3}" boot@system
40+
66-yeller %g "${2} set to [${3}]." %n
41+
fi
42+
}
43+
44+
set_hostname() {
45+
# ${1} HOSTNAME value
46+
[ -r /etc/hostname ] && HOSTNAME1="$( cat /etc/hostname )" && export HOSTNAME1
47+
48+
if [ -n "${1}" ]
49+
then
50+
66-env -t boot -r HOSTNAME=!"${1}" boot@system
51+
66-yeller %g "HOSTNAME set to [${1}]." %n
52+
elif [ -n "$HOSTNAME1" ]
53+
then
54+
66-env -t boot -r HOSTNAME=!"$HOSTNAME1" boot@system
55+
66-yeller %g "HOSTNAME set to [$HOSTNAME1]." %n
56+
elif [ -z "${1}" ] && [ -z "$HOSTNAME1" ]
57+
then
58+
66-env -t boot -r HOSTNAME=!void-live boot@system
59+
66-yeller -W %b "No HOSTNAME set, reverting
60+
to the default [void-live]." %n
61+
fi
62+
}
63+
64+
set_ttys() {
65+
# Same positional args as apply_conf_from_to
66+
if [ -n "${3}" ]
67+
then
68+
if [ "${3}" -lt 11 ] && [ "${3}" -gt 0 ]
69+
then
70+
apply_conf_from_to "${1}" "${2}" "${3}"
71+
else
72+
66-env -t boot -r TTY=!4 boot@system
73+
66-yeller -W %b "${3} TTYS is not valid as a tty number,
74+
reverting to the default [4]." %n
75+
exit 1
76+
fi
77+
else
78+
66-env -t boot -r TTY=!4 boot@system
79+
66-yeller -W %b "TTY number not set, reverting
80+
to the default [4]." %n
81+
fi
82+
}
83+
84+
check_tz() {
85+
# On installation timezone can be set by symlink and not by the
86+
# TIMEZONE key in rc.conf. In that case follow the symlink.
87+
if [ "$(realpath /etc/localtime | cut -d / -f 1,2,3,4)" = "/usr/share/zoneinfo" ]; then
88+
TIMEZONE="$(realpath /etc/localtime | cut -d / -f 5,6)"
89+
export TIMEZONE
90+
fi
91+
}
92+
93+
94+
# shellcheck disable=SC1091
95+
. /etc/rc.conf
96+
97+
check_tz
98+
set_hostname "$HOSTNAME"
99+
apply_conf_from_to TIMEZONE TZ "$TIMEZONE"
100+
apply_conf_from_to HARDWARECLOCK HARDWARECLOCK "$HARDWARECLOCK"
101+
apply_conf_from_to KEYMAP KEYMAP "$KEYMAP"
102+
apply_conf_from_to FONT_MAP FONT_MAP "$FONT_MAP"
103+
apply_conf_from_to FONT FONT "$FONT"
104+
apply_conf_from_to FONT_UNIMAP FONT_UNIMAP "$FONT_UNIMAP"
105+
set_ttys TTYS TTY "$TTYS"
106+
107+
66-yeller %g "Please re-enable the boot@system service
108+
for the changes to take effect by running (as root):
109+
'66-enable -F -t boot boot@system' " %n
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/sh
2+
3+
# Copyright 2021 mobinmob <mobinmob@disroot.org>
4+
# Use of this source code is governed by the 2-Clause BSD License
5+
# that can be found in the LICENSE file at the root project directory.
6+
# SPDX short identifier: BSD-2-Clause
7+
8+
# This script determines if the system has dmraid, luks, zfs, btrfs,
9+
# volumes, a swap partition or swapfile and configures the environment
10+
# file of the boot@system service accordingly.
11+
# Excluding the common posix userland commands, the script needs 66-which and 66-yeller
12+
# (from 66-tools), 66-env (from 66) and blkid (from util-linux).
13+
14+
# Variables for 66-yeller
15+
export PROG="66boot-storage-autoconf"
16+
export COLOR_ENABLED="1"
17+
export CLOCK_ENABLED="0"
18+
19+
# Script must run as root.
20+
user=$(id -u)
21+
[ "$user" != "0" ] && 66-yeller -F %r You need to run this script as root! %n && exit 1
22+
23+
# blkid(8) from util-linux should be available for the script to function.
24+
[ "$(blkid -v | grep util-linux -c)" != "1" ] && \
25+
66-yeller -F %r You need blkid from util-linux to run this program! %n && exit 1
26+
27+
detect_fs() {
28+
# Uses blkid to detect partition TYPEs. The result is the number
29+
# of detected partitions. TYPEs are available with `blkid -k`.
30+
export "${1}"_detected="$(blkid -c /dev/null --match-token=TYPE="${1}" | wc -l )"
31+
}
32+
33+
detect_swapfile() {
34+
# Finds swap references in /etc/fstab.
35+
swapfile_detected="$(awk '!/^(#)/' /etc/fstab | awk '$3=="swap" ' | wc -l )"
36+
export swapfile_detected
37+
}
38+
39+
detect_util() {
40+
# Uses 66-which to determine if a utility exists.
41+
# Output is $fs_util_exitst=0 (or 1)
42+
# ${1} is the variable for the utility, in the form of "$fs_util"
43+
# ${2} is the name of the executable
44+
export "${1}"_exists="$(66-which "${2}" | wc -l)"
45+
}
46+
47+
check_and_apply_conf() {
48+
# Checks for partition types and the existance of the relevant utilities.
49+
# Outputs user information
50+
# ${1} is in the form of $fs_detected
51+
# ${2} is in the form of $fs_name_exists
52+
# ${3} is the name of the configuration variable
53+
# ${4} is the user-friendly name for the configuration option
54+
# ${5} name of the utility needed for the block device type
55+
# ${6} is the name of the package that contains the program
56+
# ${6} is **distribution-dependent**
57+
if [ "${1}" != "0" ] && [ "${2}" = "1" ]
58+
then
59+
66-env -t boot -r "${3}"=!yes boot@system
60+
66-yeller %g "${4} detected and enabled!" %n
61+
elif [ "${1}" != "0" ] && [ "${2}" = "0" ]
62+
then
63+
66-env -t boot -r "${3}"=!no boot@system
64+
66-yeller -W %y "${4} detected but cannot be enabled,\n because the ${5} program is not installed. Please install the ${6} \n package and run this script again!" %n
65+
elif [ "${1}" = "0" ]
66+
then
67+
66-env -t boot -r "${3}"=!no boot@system
68+
66-yeller %b "${4} not detected!" %n
69+
fi
70+
71+
}
72+
73+
check_and_apply_conf_zpool() {
74+
# Checks for the zfs pool import method if ZFS is enabled.
75+
# Outputs user information
76+
# ${1} is in the form of $fs_detected
77+
# ${2} is in the form of $fs_name_exists
78+
if [ "${1}" != "0" ] && [ "${2}" = "1" ]
79+
then
80+
66-env -t boot -r "ZFS"=!yes boot@system
81+
if [ -e /etc/zfs/zpool.cache ]
82+
then
83+
66-env -t boot -r ZFS_IMPORT=!zpoolcache boot@system
84+
66-yeller %g "ZFS import method configured as zpoolcache." %n
85+
else
86+
66-env -t boot -r ZFS_IMPORT=!scan boot@system
87+
66-yeller %g "ZFS import method configured as scan." %n
88+
fi
89+
fi
90+
91+
}
92+
93+
# devices_to_detect is a list of some device TYPEs we want to detect
94+
devices_to_detect="btrfs zfs_member crypto_LUKS linux_raid_member LVM2_member swap"
95+
96+
# Use detect fs for all members of devices_to_detect we want
97+
for key in $devices_to_detect; do detect_fs "$key" ; done
98+
99+
# dmraid supports multiple TYPEs of *-raid-member devices.
100+
# find them first and add the sum of the *_detected values to
101+
# dmraid_detected.
102+
103+
# dmraid_TYPEs holds the device TYPEs dmraid handles
104+
dmraid_TYPEs="ddf_raid_member isw_raid_member lsi_mega_raid_member \
105+
via_raid_member silicon_medley_raid_member nvidia_raid_member \
106+
promise_fasttrack_raid_member hpt45x_raid_member hpt37x_raid_member \
107+
adaptec_raid_member jmicron_raid_member"
108+
109+
for TYPE in $dmraid_TYPEs; do detect_fs "$TYPE" ; done
110+
111+
# shellcheck disable=SC2154
112+
dmraid_detected=$((ddf_raid_member_detected+isw_raid_member_detected\
113+
+lsi_mega_raid_member_detected+via_raid_member_detected\
114+
+silicon_medley_raid_member_detected+nvidia_raid_member_detected\
115+
+promise_fasttrack_raid_member_detected+hpt37x_raid_member_detecter\
116+
+hpt45x_raid_member_detected+adaptec_raid_member_detected\
117+
+jmicron_raid_member_detected))
118+
119+
# swap can be detected by blkid if it is a partition or it can be a swapfile
120+
# declared in fstab
121+
detect_swapfile
122+
swap_detected=$((swap_detected+swapfile_detected))
123+
124+
# Use detect_util for all utilities
125+
detect_util btrfs_util btrfs
126+
detect_util zfs_util zfs
127+
detect_util luks_util cryptsetup
128+
detect_util lvm_util lvchange
129+
detect_util dmraid_util dmraid
130+
detect_util swap_util swapon
131+
detect_util mdraid_util mdadm
132+
133+
# Finally detect and apply the configuration
134+
# shellcheck disable=SC2154
135+
check_and_apply_conf "$btrfs_detected" "$btrfs_util_exists" BTRFS BTRFS btrfs "[btrfs_progs]"
136+
# shellcheck disable=SC2154
137+
check_and_apply_conf "$zfs_member_detected" "$zfs_util_exists" ZFS ZFS zfs "[zfs]"
138+
# shellcheck disable=SC2154
139+
check_and_apply_conf_zpool "$zfs_member_detected" "$zfs_util_exists" ZFS
140+
# shellcheck disable=SC2154
141+
check_and_apply_conf "$crypto_LUKS_detected" "$luks_util_exists" CRYPTTAB LUKS cryptsetup "[cryptsetup]"
142+
# shellcheck disable=SC2154
143+
check_and_apply_conf "$LVM2_member_detected" "$lvm_util_exists" LVM LVM lvchange "[lvm2]"
144+
# shellcheck disable=SC2154
145+
check_and_apply_conf "$dmraid_detected" "$dmraid_util_exists" DMRAID DMRAID dmraid "[dmraid]"
146+
# shellcheck disable=SC2154
147+
check_and_apply_conf "$swap_detected" "$swap_util_exists" SWAP SWAP swapon "[util-linux]"
148+
# shellcheck disable=SC2154
149+
check_and_apply_conf "$linux_raid_member_detected" "$mdraid_util_exists" MDRAID MDRAID mdadm "[mdadm]"
150+
151+
152+
66-yeller %g "Please re-enable the boot@system service
153+
for the changes to take effect by running (as root):
154+
'66-enable -F -t boot boot@system'" %n

srcpkgs/boot-66serv/files/runit

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[main]
2+
@type = classic
3+
@version = @VERSION@
4+
@description = "runit"
5+
@user = (root)
6+
7+
[start]
8+
@build = custom
9+
@shebang = "/bin/sh"
10+
@execute = (
11+
exec 2>&1
12+
13+
PATH=/usr/bin:/usr/sbin
14+
runlevel=66
15+
16+
runsvchdir "${runlevel}"
17+
s6-mkdir -v -p /run/runit/runsvdir
18+
ln -s /etc/runit/runsvdir/current /run/runit/runsvdir/current
19+
s6-rmrf /var/service/current
20+
s6-rmrf /var/service/supervise
21+
22+
exec s6-env -i PATH=$PATH \
23+
runsvdir -P /run/runit/runsvdir/current
24+
)
25+
26+
[stop]
27+
@build = custom
28+
@shebang = "/bin/sh -c"
29+
@execute = (
30+
sv force-stop /var/service/* &&
31+
sv exit /var/service/* )
32+
33+
[logger]
34+
@backup = 3
35+
@maxsize = 1000000
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The service takes the runit service name as @I - e.g. runit-wrapsv@cupsd
2+
[main]
3+
@type = classic
4+
@version = @VERSION@
5+
@description = "wrapper for @I runit service"
6+
@user = ( root )
7+
8+
[start]
9+
@execute = ( /etc/sv/@I/run )
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This core service checks for /usr/bin/{reboot,poweroff,halt,shutdown}
2+
# and if they are part of 66 it deletes them and moves the runit
3+
# utilities in their place. It runs by default. There is a similar
4+
# oneshot service for 66 that does the opposite and should be enabled.
5+
# The script make sure that the user has the proper utilities for the
6+
# init system they are currently running.
7+
8+
for i in reboot poweroff halt shutdown; do
9+
if test -e /usr/bin/${i}.runit; then
10+
rm /usr/bin/${i}
11+
mv /usr/bin/${i}.runit /usr/bin/${i}
12+
fi
13+
done

0 commit comments

Comments
 (0)