mirror of
https://github.com/elasticdog/packer-arch.git
synced 2026-01-23 10:15:21 +00:00
Remove duplication in installation scripts
Instead of having mostly duplicate scripts for the entire installation process, we can split them up into the base installation steps and then run shell provisioners for anything specific to each of the types after the machine has rebooted. This structure will mean less chance of error when making changes to machines, and will also allow for expansion of the scripts to be run at the end, such as adding a minimization script to remove history and clear out space on the drive before compression.
This commit is contained in:
parent
ccb4986b83
commit
d5adbc3f10
6 changed files with 59 additions and 213 deletions
|
|
@ -6,6 +6,28 @@
|
|||
"ssh_timeout": "20m"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "parallels-iso",
|
||||
"parallels_tools_flavor": "lin",
|
||||
"parallels_tools_mode": "attach",
|
||||
"guest_os_type": "linux-2.6",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"http_directory": "srv",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-base.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
|
||||
"/usr/bin/bash ./install-base.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"ssh_username": "vagrant",
|
||||
"ssh_password": "vagrant",
|
||||
"ssh_timeout": "{{user `ssh_timeout`}}",
|
||||
"shutdown_command": "sudo systemctl start poweroff.timer"
|
||||
},
|
||||
{
|
||||
"type": "virtualbox-iso",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
|
|
@ -17,9 +39,9 @@
|
|||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-virtualbox.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-base.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
|
||||
"/usr/bin/bash ./install-virtualbox.sh<enter>"
|
||||
"/usr/bin/bash ./install-base.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"hard_drive_interface": "sata",
|
||||
|
|
@ -37,38 +59,29 @@
|
|||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-vmware.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-base.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
|
||||
"/usr/bin/bash ./install-vmware.sh<enter>"
|
||||
"/usr/bin/bash ./install-base.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"ssh_username": "vagrant",
|
||||
"ssh_password": "vagrant",
|
||||
"ssh_timeout": "{{user `ssh_timeout`}}",
|
||||
"shutdown_command": "sudo systemctl start poweroff.timer"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"only": ["parallels-iso"],
|
||||
"type": "shell",
|
||||
"execute_command": "{{.Vars}} sudo -E -S bash '{{.Path}}'",
|
||||
"script": "scripts/install-parallels.sh"
|
||||
},
|
||||
{
|
||||
"type": "parallels-iso",
|
||||
"parallels_tools_flavor": "lin",
|
||||
"parallels_tools_mode": "attach",
|
||||
"guest_os_type": "linux-2.6",
|
||||
"iso_url": "{{user `iso_url`}}",
|
||||
"iso_checksum": "{{user `iso_checksum`}}",
|
||||
"iso_checksum_type": "{{user `iso_checksum_type`}}",
|
||||
"http_directory": "srv",
|
||||
"boot_wait": "5s",
|
||||
"boot_command": [
|
||||
"<enter><wait10><wait10>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/install-parallels.sh<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/poweroff.timer<enter><wait5>",
|
||||
"/usr/bin/curl -O http://{{.HTTPIP}}:{{.HTTPPort}}/parallels-tools.sh<enter><wait5>",
|
||||
"/usr/bin/bash ./install-parallels.sh<enter>"
|
||||
],
|
||||
"disk_size": 20480,
|
||||
"ssh_username": "vagrant",
|
||||
"ssh_password": "vagrant",
|
||||
"ssh_timeout": "{{user `ssh_timeout`}}",
|
||||
"shutdown_command": "sudo /parallels_tools.sh && sudo rm /parallels_tools.sh && sudo systemctl start poweroff.timer"
|
||||
"only": ["virtualbox-iso"],
|
||||
"type": "shell",
|
||||
"execute_command": "{{.Vars}} sudo -E -S bash '{{.Path}}'",
|
||||
"script": "scripts/install-virtualbox.sh"
|
||||
}
|
||||
],
|
||||
"post-processors": [
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
# Install parallels tools (https://wiki.archlinux.org/index.php/Parallels)
|
||||
#!/usr/bin/bash -x
|
||||
|
||||
# Parallels Tools
|
||||
# https://wiki.archlinux.org/index.php/Parallels
|
||||
mount /dev/sr1 /mnt
|
||||
ln -sf /usr/lib/systemd/scripts/ /etc/init.d
|
||||
export def_sysconfdir=/etc/init.d
|
||||
|
|
@ -7,7 +10,7 @@ pacman -S --noconfirm python2 linux-headers
|
|||
ln -sf /usr/bin/python2 /usr/local/bin/python
|
||||
/mnt/install --install-unattended
|
||||
|
||||
# Cleanup after parallels tools installation
|
||||
# clean up
|
||||
umount /dev/sr1
|
||||
/usr/bin/pacman -Rcns --noconfirm python2 linux-headers
|
||||
rm -f /etc/init.d
|
||||
16
scripts/install-virtualbox.sh
Executable file
16
scripts/install-virtualbox.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/bash -x
|
||||
|
||||
# VirtualBox Guest Additions
|
||||
# https://wiki.archlinux.org/index.php/VirtualBox
|
||||
/usr/bin/pacman -S --noconfirm linux-headers virtualbox-guest-utils virtualbox-guest-dkms nfs-utils
|
||||
echo -e 'vboxguest\nvboxsf\nvboxvideo' > /etc/modules-load.d/virtualbox.conf
|
||||
guest_version=$(/usr/bin/pacman -Q virtualbox-guest-dkms | awk '{ print $2 }' | cut -d'-' -f1)
|
||||
kernel_version="$(/usr/bin/pacman -Q linux | awk '{ print $2 }')-ARCH"
|
||||
/usr/bin/dkms install "vboxguest/${guest_version}" -k "${kernel_version}/x86_64"
|
||||
/usr/bin/systemctl enable dkms.service
|
||||
/usr/bin/systemctl enable vboxservice.service
|
||||
/usr/bin/systemctl enable rpcbind.service
|
||||
|
||||
# Add groups for VirtualBox folder sharing
|
||||
/usr/bin/groupadd vagrant
|
||||
/usr/bin/usermod --append --groups vagrant,vboxsf vagrant
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
DISK='/dev/sda'
|
||||
FQDN='vagrant-arch.vagrantup.com'
|
||||
KEYMAP='us'
|
||||
LANGUAGE='en_US.UTF-8'
|
||||
PASSWORD=$(/usr/bin/openssl passwd -crypt 'vagrant')
|
||||
TIMEZONE='UTC'
|
||||
|
||||
CONFIG_SCRIPT='/usr/local/bin/arch-config.sh'
|
||||
ROOT_PARTITION="${DISK}1"
|
||||
TARGET_DIR='/mnt'
|
||||
|
||||
echo "==> clearing partition table on ${DISK}"
|
||||
/usr/bin/sgdisk --zap ${DISK}
|
||||
|
||||
echo "==> destroying magic strings and signatures on ${DISK}"
|
||||
/usr/bin/dd if=/dev/zero of=${DISK} bs=512 count=2048
|
||||
/usr/bin/wipefs --all ${DISK}
|
||||
|
||||
echo "==> creating /root partition on ${DISK}"
|
||||
/usr/bin/sgdisk --new=1:0:0 ${DISK}
|
||||
|
||||
echo "==> setting ${DISK} bootable"
|
||||
/usr/bin/sgdisk ${DISK} --attributes=1:set:2
|
||||
|
||||
echo '==> creating /root filesystem (ext4)'
|
||||
/usr/bin/mkfs.ext4 -F -m 0 -q -L root ${ROOT_PARTITION}
|
||||
|
||||
echo "==> mounting ${ROOT_PARTITION} to ${TARGET_DIR}"
|
||||
/usr/bin/mount -o noatime,errors=remount-ro ${ROOT_PARTITION} ${TARGET_DIR}
|
||||
|
||||
echo '==> bootstrapping the base installation'
|
||||
/usr/bin/pacstrap ${TARGET_DIR} base base-devel
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} pacman -S --noconfirm gptfdisk openssh syslinux
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} syslinux-install_update -i -a -m
|
||||
/usr/bin/sed -i 's/sda3/sda1/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"
|
||||
/usr/bin/sed -i 's/TIMEOUT 50/TIMEOUT 10/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"
|
||||
|
||||
echo '==> generating the filesystem table'
|
||||
/usr/bin/genfstab -p ${TARGET_DIR} >> "${TARGET_DIR}/etc/fstab"
|
||||
|
||||
echo '==> generating the system configuration script'
|
||||
/usr/bin/install --mode=0755 /dev/null "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
|
||||
cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
echo '${FQDN}' > /etc/hostname
|
||||
/usr/bin/ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
|
||||
echo 'KEYMAP=${KEYMAP}' > /etc/vconsole.conf
|
||||
/usr/bin/sed -i 's/#${LANGUAGE}/${LANGUAGE}/' /etc/locale.gen
|
||||
/usr/bin/locale-gen
|
||||
/usr/bin/mkinitcpio -p linux
|
||||
/usr/bin/usermod --password ${PASSWORD} root
|
||||
# https://wiki.archlinux.org/index.php/Network_Configuration#Device_names
|
||||
/usr/bin/ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
|
||||
/usr/bin/ln -s '/usr/lib/systemd/system/dhcpcd@.service' '/etc/systemd/system/multi-user.target.wants/dhcpcd@eth0.service'
|
||||
/usr/bin/sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
|
||||
/usr/bin/systemctl enable sshd.service
|
||||
|
||||
# Vagrant-specific configuration
|
||||
/usr/bin/useradd --password ${PASSWORD} --comment 'Vagrant User' --create-home --gid users vagrant
|
||||
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/10_vagrant
|
||||
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/10_vagrant
|
||||
/usr/bin/chmod 0440 /etc/sudoers.d/10_vagrant
|
||||
/usr/bin/install --directory --owner=vagrant --group=users --mode=0700 /home/vagrant/.ssh
|
||||
/usr/bin/curl --output /home/vagrant/.ssh/authorized_keys --location https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
|
||||
/usr/bin/chown vagrant:users /home/vagrant/.ssh/authorized_keys
|
||||
/usr/bin/chmod 0600 /home/vagrant/.ssh/authorized_keys
|
||||
|
||||
# clean up
|
||||
/usr/bin/pacman -Rcns --noconfirm gptfdisk
|
||||
/usr/bin/yes | /usr/bin/pacman -Scc
|
||||
EOF
|
||||
|
||||
echo '==> entering chroot and configuring system'
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} ${CONFIG_SCRIPT}
|
||||
rm "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
|
||||
# http://comments.gmane.org/gmane.linux.arch.general/48739
|
||||
echo '==> adding workaround for shutdown race condition'
|
||||
/usr/bin/install --mode=0644 poweroff.timer "${TARGET_DIR}/etc/systemd/system/poweroff.timer"
|
||||
|
||||
echo '==> Include parallels tools'
|
||||
/usr/bin/install --mode=0755 parallels_tools.sh "${TARGET_DIR}/parallels_tools.sh"
|
||||
|
||||
echo '==> installation complete!'
|
||||
/usr/bin/sleep 3
|
||||
/usr/bin/umount ${TARGET_DIR}
|
||||
/usr/bin/systemctl reboot
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
DISK='/dev/sda'
|
||||
FQDN='vagrant-arch.vagrantup.com'
|
||||
KEYMAP='us'
|
||||
LANGUAGE='en_US.UTF-8'
|
||||
PASSWORD=$(/usr/bin/openssl passwd -crypt 'vagrant')
|
||||
TIMEZONE='UTC'
|
||||
|
||||
CONFIG_SCRIPT='/usr/local/bin/arch-config.sh'
|
||||
ROOT_PARTITION="${DISK}1"
|
||||
TARGET_DIR='/mnt'
|
||||
|
||||
echo "==> clearing partition table on ${DISK}"
|
||||
/usr/bin/sgdisk --zap ${DISK}
|
||||
|
||||
echo "==> destroying magic strings and signatures on ${DISK}"
|
||||
/usr/bin/dd if=/dev/zero of=${DISK} bs=512 count=2048
|
||||
/usr/bin/wipefs --all ${DISK}
|
||||
|
||||
echo "==> creating /root partition on ${DISK}"
|
||||
/usr/bin/sgdisk --new=1:0:0 ${DISK}
|
||||
|
||||
echo "==> setting ${DISK} bootable"
|
||||
/usr/bin/sgdisk ${DISK} --attributes=1:set:2
|
||||
|
||||
echo '==> creating /root filesystem (ext4)'
|
||||
/usr/bin/mkfs.ext4 -F -m 0 -q -L root ${ROOT_PARTITION}
|
||||
|
||||
echo "==> mounting ${ROOT_PARTITION} to ${TARGET_DIR}"
|
||||
/usr/bin/mount -o noatime,errors=remount-ro ${ROOT_PARTITION} ${TARGET_DIR}
|
||||
|
||||
echo '==> bootstrapping the base installation'
|
||||
/usr/bin/pacstrap ${TARGET_DIR} base base-devel
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} pacman -S --noconfirm gptfdisk openssh syslinux
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} syslinux-install_update -i -a -m
|
||||
/usr/bin/sed -i 's/sda3/sda1/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"
|
||||
/usr/bin/sed -i 's/TIMEOUT 50/TIMEOUT 10/' "${TARGET_DIR}/boot/syslinux/syslinux.cfg"
|
||||
|
||||
echo '==> generating the filesystem table'
|
||||
/usr/bin/genfstab -p ${TARGET_DIR} >> "${TARGET_DIR}/etc/fstab"
|
||||
|
||||
echo '==> generating the system configuration script'
|
||||
/usr/bin/install --mode=0755 /dev/null "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
|
||||
cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
echo '${FQDN}' > /etc/hostname
|
||||
/usr/bin/ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
|
||||
echo 'KEYMAP=${KEYMAP}' > /etc/vconsole.conf
|
||||
/usr/bin/sed -i 's/#${LANGUAGE}/${LANGUAGE}/' /etc/locale.gen
|
||||
/usr/bin/locale-gen
|
||||
/usr/bin/mkinitcpio -p linux
|
||||
/usr/bin/usermod --password ${PASSWORD} root
|
||||
# https://wiki.archlinux.org/index.php/Network_Configuration#Device_names
|
||||
/usr/bin/ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
|
||||
/usr/bin/ln -s '/usr/lib/systemd/system/dhcpcd@.service' '/etc/systemd/system/multi-user.target.wants/dhcpcd@eth0.service'
|
||||
/usr/bin/sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
|
||||
/usr/bin/systemctl enable sshd.service
|
||||
|
||||
# VirtualBox Guest Additions
|
||||
/usr/bin/pacman -S --noconfirm linux-headers virtualbox-guest-utils virtualbox-guest-dkms nfs-utils
|
||||
echo -e 'vboxguest\nvboxsf\nvboxvideo' > /etc/modules-load.d/virtualbox.conf
|
||||
guest_version=\$(/usr/bin/pacman -Q virtualbox-guest-dkms | awk '{ print \$2 }' | cut -d'-' -f1)
|
||||
kernel_version="\$(/usr/bin/pacman -Q linux | awk '{ print \$2 }')-ARCH"
|
||||
/usr/bin/dkms install "vboxguest/\${guest_version}" -k "\${kernel_version}/x86_64"
|
||||
/usr/bin/systemctl enable dkms.service
|
||||
/usr/bin/systemctl enable vboxservice.service
|
||||
/usr/bin/systemctl enable rpcbind.service
|
||||
|
||||
# Vagrant-specific configuration
|
||||
/usr/bin/groupadd vagrant
|
||||
/usr/bin/useradd --password ${PASSWORD} --comment 'Vagrant User' --create-home --gid users --groups vagrant,vboxsf vagrant
|
||||
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/10_vagrant
|
||||
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/10_vagrant
|
||||
/usr/bin/chmod 0440 /etc/sudoers.d/10_vagrant
|
||||
/usr/bin/install --directory --owner=vagrant --group=users --mode=0700 /home/vagrant/.ssh
|
||||
/usr/bin/curl --output /home/vagrant/.ssh/authorized_keys --location https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
|
||||
/usr/bin/chown vagrant:users /home/vagrant/.ssh/authorized_keys
|
||||
/usr/bin/chmod 0600 /home/vagrant/.ssh/authorized_keys
|
||||
|
||||
# clean up
|
||||
/usr/bin/pacman -Rcns --noconfirm gptfdisk
|
||||
/usr/bin/yes | /usr/bin/pacman -Scc
|
||||
EOF
|
||||
|
||||
echo '==> entering chroot and configuring system'
|
||||
/usr/bin/arch-chroot ${TARGET_DIR} ${CONFIG_SCRIPT}
|
||||
rm "${TARGET_DIR}${CONFIG_SCRIPT}"
|
||||
|
||||
# http://comments.gmane.org/gmane.linux.arch.general/48739
|
||||
echo '==> adding workaround for shutdown race condition'
|
||||
/usr/bin/install --mode=0644 poweroff.timer "${TARGET_DIR}/etc/systemd/system/poweroff.timer"
|
||||
|
||||
echo '==> installation complete!'
|
||||
/usr/bin/sleep 3
|
||||
/usr/bin/umount ${TARGET_DIR}
|
||||
/usr/bin/systemctl reboot
|
||||
Loading…
Add table
Add a link
Reference in a new issue