OSDN Git Service

09abd73ace0472934ef08eaec349a7e64e129d07
[avyssos/66-voidlinux.git] / srcpkgs / boot-66serv / files / 66boot-initial-setup
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.
5 # SPDX short identifier: BSD-2-Clause
6
7 # Script must run as root, otherwise it creates trees
8 # as the user.
9 user=$(id -u)
10 [ "$user" != "0" ] && printf "You need to run this script as root! \n" && exit 1
11
12 # Variables for 66-yeller
13 export PROG="66boot-initial-setup"
14 export COLOR_ENABLED="1"
15 export CLOCK_ENABLED="0"
16
17 # Information for the user, in case of failure. 66 output is informative, this
18 # is just a pointer to the docs.
19 msg_trees() {
20         # ${1} is the name of the tree 
21         66-yeller -F %r "An action for the [${1}] tree failed.
22 Check the output before this message for a possibe cause and consult
23 the 66-tree documentation." %n
24         exit 1
25 }
26
27 msg_services() {
28         # ${1} is the name of a service
29         66-yeller -F %r "Enabling the [${1}] service failed.
30 Check the output before this message for a possibe cause and consult
31 the 66-enable documentation." %n
32         exit 1
33 }
34
35 # Create the mandatory boot tree.
36 66-tree -n boot || msg_trees boot
37 # Enable the boot@system service in the boot tree.
38 66-enable -F -t boot boot@system || msg_services boot@system
39
40 # Copy the default boot@conf so that it will survive updates and be accesible
41 # though /etc/66rc.conf. Also, remove the warning in the first lines of the file.
42 new_conf="/etc/66/conf/boot@system/version/boot@system"
43 [ ! -f "$new_conf" ] && cp /etc/66/conf/boot@system/version/.boot@system "$new_conf" && \
44 warn=$( sed -n -e "/##\ \[STARTWARN\]/p" /etc/66rc.conf | tr -d '[:space:]') && \
45  [ "$warn" = "##[STARTWARN]" ] && sed -i '1,5d' "$new_conf"
46
47 # Create default tree, enable it and make it current.
48 66-tree -nEc default || msg_trees default
49 # Enable switch-initutils oneshot service in the default tree.
50 66-enable switch-initutils || msg_services switch-initutils
51
52 # Create and enable runit tree.
53 66-tree -nE runit || msg_trees runit
54 # Enable the runit service in the runit tree.
55 66-enable -t runit runit || msg_services runit
56 # Start runit tree after the default tree.
57 66-tree -S default runit || msg_trees runit