install-chroot.sh 2.55 KB
Newer Older
1
2
3
4
5
6
7
8
#!/bin/bash

set -e
set -x

ln -sf /usr/share/zoneinfo/UTC /etc/localtime
sed -i -e 's/^#\(en_US.UTF-8\)/\1/' /etc/locale.gen
locale-gen
9
echo 'LANG=en_US.UTF-8' >/etc/locale.conf
10
11
12
13
14
15

# setting vagrant user credentials
echo -e 'vagrant\nvagrant' | passwd
useradd -m -U vagrant
echo -e 'vagrant\nvagrant' | passwd vagrant

16
# setting automatic authentication for any action requiring admin rights via Polkit
17
cat <<EOF >/etc/polkit-1/rules.d/49-nopasswd_global.rules
18
19
20
21
22
23
24
polkit.addRule(function(action, subject) {
    if (subject.isInGroup("vagrant")) {
        return polkit.Result.YES;
    }
});
EOF

25
# setting sudo for vagrant user
26
cat <<EOF >/etc/sudoers.d/vagrant
27
28
29
30
31
32
33
34
35
36
37
Defaults:vagrant !requiretty
vagrant ALL=(ALL) NOPASSWD: ALL
EOF
chmod 440 /etc/sudoers.d/vagrant

# install vagrant ssh key
install --directory --owner=vagrant --group=vagrant --mode=0700 /home/vagrant/.ssh
curl --output /home/vagrant/.ssh/authorized_keys --location https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys

Christian Rebischke's avatar
Christian Rebischke committed
38
# setup network
39
cat <<EOF >/etc/systemd/network/eth0.network
40
41
42
43
44
45
46
[Match]
Name=eth0

[Network]
DHCP=ipv4
EOF

47
# Setup pacman-init.service for clean pacman keyring initialization
48
cat <<EOF >/etc/systemd/system/pacman-init.service
49
50
51
52
[Unit]
Description=Initializes Pacman keyring
Wants=haveged.service
After=haveged.service
53
Before=sshd.service
54
55
56
57
58
59
60
61
62
63
64
65
ConditionFirstBoot=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/pacman-key --init
ExecStart=/usr/bin/pacman-key --populate archlinux

[Install]
WantedBy=multi-user.target
EOF

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Add service for running reflector on first boot
cat <<EOF >/etc/systemd/system/reflector-init.service
[Unit]
Description=Initializes mirrors for the VM
After=network.target
Wants=network.target
ConditionFirstBoot=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=reflector --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

[Install]
WantedBy=multi-user.target
EOF

83
# enabling important services
84
systemctl daemon-reload
85
systemctl enable sshd
86
systemctl enable haveged
87
systemctl enable systemd-networkd
88
systemctl enable systemd-resolved
89
systemctl enable pacman-init.service
90
systemctl enable reflector-init.service
91

92
93
94
95
96
if [ -b "/dev/sda" ]; then
  grub-install /dev/sda
elif [ -b "/dev/vda" ]; then
  grub-install /dev/vda
fi
97
sed -i -e 's/^GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=1/' /etc/default/grub
98
99
# setup unpredictable kernel names
sed -i -e 's/^GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="net.ifnames=0"/' /etc/default/grub
100
grub-mkconfig -o /boot/grub/grub.cfg