summaryrefslogtreecommitdiffstats
path: root/data/systemd/anaconda-generator
blob: 4c8b8286ba943fa808db09129c188467b38f0d0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# anaconda-generator: generate services needed for anaconda operation

# Source in the dracut lib so we can parse cmd line arguments
. /usr/lib/dracut/modules.d/99base/dracut-lib.sh

# set up dirs
systemd_dir=/lib/systemd/system
target_dir=$systemd_dir/anaconda.target.wants
mkdir -p $target_dir

# create symlink anaconda.target.wants/SERVICE@TTY.service
service_on_tty() {
    local service="$1" tty="$2"
    local service_instance="${service/@.service/@$tty.service}"
    ln -sf $systemd_dir/$service $target_dir/$service_instance
}

# find the real tty for /dev/console
tty="console"
while [ -f /sys/class/tty/$tty/active ]; do
    tty=$(< /sys/class/tty/$tty/active)
    tty=${tty##* } # last item in the list
done
consoletty="$tty"

# put anaconda on the real console
service_on_tty anaconda-tmux@.service $consoletty

# put a shell on tty2 and the first virtualization console we find
for tty in tty2 hvc0 hvc1 xvc0 hvsi0 hvsi1 hvsi2; do
    [ "$tty" = "$consoletty" ] && continue
    if [ -d /sys/class/tty/$tty ]; then
        service_on_tty anaconda-shell@.service $tty
        [ "$tty" != "tty2" ] && break
    fi
done

# enable the ssh service
# NOTE: We have a match for s390x here because the console sucks on that
# platform.  Really any platform with a crappy console that can't do curses
# or have multiple VTs should get sshd spawned automatically, but we don't
# yet have a good way of detecting these platforms.
if getargbool 0 inst.sshd || [ $(uname -m) = "s390x" ]; then
    ln -sf $systemd_dir/anaconda-sshd.service $target_dir/anaconda-sshd.service
fi