OSDN Git Service

66boot-* : adopt a somewhat common basic structure and more.
[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 # This scripts create basic trees and enable 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" ] && printf "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 if [ "$?" = 0 ]; then 66-yeller %g "Basic trees created and services enabled succesfully!"; fi