Files
vms/distros/alpine/3.19.0/http/in-chroot.sh
T
2024-01-09 11:45:17 -06:00

50 lines
1.5 KiB
Bash

#!/usr/bin/env sh
set -ex -o pipefail
# Enables packages like "sudo"
sed -i 's/#\(.*\/community\)/\1/' /etc/apk/repositories
# Install bare minimal packages
apk add curl efibootmgr openssh sudo virt-what
efibootmgr --bootnext "$(efibootmgr | grep 'Misc' | awk '{print $1}' | sed -E 's/[^0-9]//g')"
rc-update add sshd default
# Configure systems
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant-nopasswd
echo 'Defaults !requiretty' >> /etc/sudoers
sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config
cat > /etc/ssh/sshd_config.d/10-vagrant-insecure-rsa-key.conf <<EOF
# For now the vagrant insecure key is an rsa key
# https://github.com/hashicorp/vagrant/issues/11783
PubkeyAcceptedKeyTypes=+ssh-rsa
EOF
ssh-keygen -A
# Create and configure the vagrant user
adduser vagrant -D
# Add the vagrant user to the `wheel` group
addgroup vagrant wheel
[ -d /home/vagrant ] || exit 1
echo "vagrant:vagrant" | chpasswd
echo "root:vagrant" | chpasswd
# Do host-specific things
virt="$(virt-what)"
# Values I've found so far
# "microsoft" == Hyper-V
# "oracle" == VirtualBox
# "KVM" == KVM/Qemu
if [ "${virt}" == "microsoft" ]; then
apk add hvtools
rc-update add hv_fcopy_daemon
rc-update add hv_kvp_daemon
rc-update add hv_vss_daemon
elif [ "${virt}" == "kvm" -o "${virt}" == "qemu" ]; then
apk add qemu-guest-agent
rc-update add qemu-guest-agent
elif [ "${virt}" == "virtualbox" ]; then
apk add virtualbox-guest-additions
rc-update add virtualbox-guest-additions boot
fi