install-vagrant.sh 829 Bytes
Newer Older
1
#!/bin/bash
2
3
4
5
# shellcheck disable=SC2034
NEWUSER="vagrant"

post() {
6
7
8
9
10
11
12
13
14
15
16
  # setting the user credentials
  useradd -m -U "${NEWUSER}"
  echo -e "${NEWUSER}\n${NEWUSER}" | passwd "${NEWUSER}"

  # setting sudo for the user
  cat <<EOF >"/etc/sudoers.d/${NEWUSER}"
Defaults:${NEWUSER} !requiretty
${NEWUSER} ALL=(ALL) NOPASSWD: ALL
EOF
  chmod 440 "/etc/sudoers.d/${NEWUSER}"

17
18
19
20
21
22
23
24
25
  # setup network
  cat <<EOF >/etc/systemd/network/eth0.network
[Match]
Name=eth0

[Network]
DHCP=ipv4
EOF

26
27
28
29
30
31
  # 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
}