README: Program name does not need /usr/bin path.
[a-fedora-appliance.git] / firstboot
1 #!/bin/bash -
2 # a-fedora-appliance
3 # Copyright (C) 2011-2014 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # supermin doesn't run any RPM %pre or %post scripts.  For
20 # libguestfs this doesn't matter, but when trying to boot a real
21 # distro it matters quite a bit.  This script runs once, the first
22 # time the appliance boots.  It contains a selection of %post scripts
23 # from important packages.
24 #
25 # In debootstrap, this is generated from the packages themselves.  We
26 # should generate it for supermin too.  (XXX)
27
28 # There is no /etc/fstab in Fedora.  It is possibly generated by
29 # Anaconda for a normal distro.  Fake one here.
30 cat <<EOF >/etc/fstab
31 /dev/root / ext2 defaults 1 1
32 EOF
33
34 # This is probably also done by Anaconda.
35 rm -f /etc/mtab
36 ln -s /proc/mounts /etc/mtab
37
38 # Also probably Anaconda.
39 cat <<EOF >/etc/sysconfig/network
40 HOSTNAME=localhost.localnet
41 NETWORKING=yes
42 EOF
43 cat <<EOF >/etc/sysconfig/network-scripts/ifcfg-eth0
44 DEVICE=eth0
45 TYPE=Ethernet
46 BOOTPROTO=dhcp
47 ONBOOT=yes
48 EOF
49
50 # Combined user accounts from all packages.  XXX Because useradd and
51 # groupadd are non-readable by non-root, they are not copied into the
52 # appliance.
53
54 cat <<EOF >>/etc/passwd
55 sshd:x:74:482:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
56 dbus:x:81:81:System message bus:/:/sbin/nologin
57 EOF
58
59 cat <<EOF >>/etc/shadow
60 sshd:!!:14742::::::
61 dbus:!!:14742::::::
62 EOF
63
64 cat <<EOF >>/etc/group
65 cdrom:x:11:
66 dialout:x:18:
67 floppy:x:19:
68 utmp:x:22:
69 tape:x:33:
70 utempter:x:35:
71 dbus:x:81
72 ssh_keys:x:106:
73 sshd:x:482:
74 EOF
75
76 cat <<EOF >>/etc/gshadow
77 cdrom:!::
78 dialout:!::
79 floppy:!::
80 utmp:!::
81 tape:!::
82 utempter:!::
83 dbus:!::
84 ssh_keys:!::
85 sshd:!::
86 EOF
87
88 # systemd
89 /bin/systemd-machine-id-setup
90 /bin/systemctl daemon-reexec
91
92 # systemd-units
93 target="/lib/systemd/system/runlevel2.target"
94 ln -sf "$target" /etc/systemd/system/default.target
95 /bin/systemctl enable getty@tty1.service
96
97 # openssh-server
98 /bin/systemctl enable sshd.service
99 /bin/systemctl enable sshd-keygen.service
100 chown root.root /var/empty/sshd
101
102 # syslog
103 touch /var/log/messages
104 touch /var/log/secure
105 /bin/systemctl enable rsyslog.service
106
107 # NetworkManager
108 /sbin/chkconfig --add NetworkManager
109 /sbin/chkconfig NetworkManager resetpriorities
110 /bin/systemctl enable NetworkManager.service
111
112 # Set the root password to empty string.
113 mv /etc/passwd /etc/passwd-
114 sed 's/^root:[^:]*:/root::/' < /etc/passwd- > /etc/passwd
115
116 # Set up an /etc/issue file.
117 cat <<'EOF' >/etc/issue
118
119 Welcome to a-fedora-appliance, a small Fedora appliance.
120
121 Log in with 'root', no password.
122
123 EOF
124
125 # Only run this script once.
126 touch /firstboot.done