From 1d6f4634a16501b9746430a7e56a4e52ea075c14 Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Mon, 3 Aug 2020 12:27:15 +0200 Subject: [PATCH] Update alpine packer, add GUI --- packer/alpine-linux/.gitignore | 2 + packer/alpine-linux/README.rst | 28 ++++++++++ packer/alpine-linux/alpine-linux.json | 47 ---------------- packer/alpine-linux/alpine_cli.json | 68 +++++++++++++++++++++++ packer/alpine-linux/alpine_gui.json | 68 +++++++++++++++++++++++ packer/alpine-linux/scripts/gui.sh | 17 ++++++ packer/alpine-linux/scripts/install.sh | 28 ++++++++++ packer/alpine-linux/scripts/post_setup.sh | 10 ++-- packer/alpine-linux/scripts/serial.sh | 5 ++ packer/alpine-linux/scripts/setup.sh | 56 +++++++------------ 10 files changed, 241 insertions(+), 88 deletions(-) create mode 100644 packer/alpine-linux/.gitignore create mode 100644 packer/alpine-linux/README.rst delete mode 100644 packer/alpine-linux/alpine-linux.json create mode 100644 packer/alpine-linux/alpine_cli.json create mode 100644 packer/alpine-linux/alpine_gui.json create mode 100644 packer/alpine-linux/scripts/gui.sh create mode 100644 packer/alpine-linux/scripts/install.sh create mode 100644 packer/alpine-linux/scripts/serial.sh diff --git a/packer/alpine-linux/.gitignore b/packer/alpine-linux/.gitignore new file mode 100644 index 0000000..23cbc22 --- /dev/null +++ b/packer/alpine-linux/.gitignore @@ -0,0 +1,2 @@ +output-qemu +packer_cache diff --git a/packer/alpine-linux/README.rst b/packer/alpine-linux/README.rst new file mode 100644 index 0000000..9a0b27b --- /dev/null +++ b/packer/alpine-linux/README.rst @@ -0,0 +1,28 @@ +Packer for Alpine GNS3 appliance +================================ + +For building an Alpine appliance. + +https://alpinelinux.org/ + +CLI Linux installation +********************** + +The only added packages are: +* busybox-extras +* nano + +.. code:: bash + + packer build alpine_cli.json + + +GUI Linux installation +********************** + +The GUI version has XFCE4 installed. + +.. code:: bash + + packer build alpine_gui.json + diff --git a/packer/alpine-linux/alpine-linux.json b/packer/alpine-linux/alpine-linux.json deleted file mode 100644 index faf4ff3..0000000 --- a/packer/alpine-linux/alpine-linux.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "builders": - [ - { - "type": "qemu", - "iso_url": "http://wiki.alpinelinux.org/cgi-bin/dl.cgi/v3.2/releases/x86_64/alpine-mini-3.2.3-x86_64.iso", - "iso_checksum": "a718c78537a0d416fa0b7cfcef1dfb85d1e837aa", - "iso_checksum_type": "sha1", - "shutdown_command": "poweroff", - "format": "qcow2", - "headless": false, - "ssh_username": "root", - "ssh_password": "gns3", - "vm_name": "alpine-linux", - "accelerator": "none", - "disk_interface": "ide", - "net_device": "e1000", - "disk_size": 5000, - "boot_wait": "120s", - "http_directory": "http", - "ssh_wait_timeout": "60m", - "boot_command": - [ - "root", - "echo \"root:gns3\" | chpasswd", - "ifconfig eth0 up && udhcpc -i eth0", - "setup-apkrepos -r", - "setup-sshd -c openssh" - ] - } - ], - "provisioners": [ - { - "type": "shell", - "script": "scripts/setup.sh" - }, - { - "type": "shell", - "inline": [ "reboot" ] - }, - { - "type": "shell", - "pause_before": "60s", - "script": "scripts/post_setup.sh" - } - ] -} diff --git a/packer/alpine-linux/alpine_cli.json b/packer/alpine-linux/alpine_cli.json new file mode 100644 index 0000000..248be6f --- /dev/null +++ b/packer/alpine-linux/alpine_cli.json @@ -0,0 +1,68 @@ +{ + "variables": { + "iso_url": "http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso", + "iso_checksum": "fe694a34c0e2d30b9e5dea7e2c1a3892c1f14cb474b69cc5c557a52970071da5", + "vm_name": "alpine_cli.qcow2", + "setup_script": "setup.sh", + "disk_size": "500" + }, + "builders": [ + { + "type": "qemu", + "iso_url": "{{user `iso_url`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "sha256", + "shutdown_command": "poweroff", + "headless": true, + "ssh_username": "root", + "ssh_password": "root", + "vm_name": "{{user `vm_name`}}", + "disk_interface": "ide", + "disk_compression": true, + "net_device": "e1000", + "disk_size": "{{user `disk_size`}}", + "boot_wait": "20s", + "ssh_wait_timeout": "60s", + "boot_command": [ + "root", + "echo 'root:root' | chpasswd", + "ifconfig lo up", + "ifconfig eth0 up && udhcpc -i eth0", + "setup-sshd -c openssh", + "sed -i.orig '$aPermitRootLogin yes' /etc/ssh/sshd_config", + "service sshd restart" + ] + } + ], + "provisioners": [ + { + "type": "shell", + "script": "scripts/install.sh" + }, + { + "type": "shell", + "inline": [ + "reboot" + ] + }, + { + "type": "shell", + "pause_before": "20s", + "inline": [ + "apk upgrade --update-cache" + ] + }, + { + "type": "shell", + "script": "scripts/serial.sh" + }, + { + "type": "shell", + "script": "scripts/{{user `setup_script`}}" + }, + { + "type": "shell", + "script": "scripts/post_setup.sh" + } + ] +} diff --git a/packer/alpine-linux/alpine_gui.json b/packer/alpine-linux/alpine_gui.json new file mode 100644 index 0000000..f5b4c8e --- /dev/null +++ b/packer/alpine-linux/alpine_gui.json @@ -0,0 +1,68 @@ +{ + "variables": { + "iso_url": "http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso", + "iso_checksum": "fe694a34c0e2d30b9e5dea7e2c1a3892c1f14cb474b69cc5c557a52970071da5", + "vm_name": "alpine_gui.qcow2", + "setup_script": "setup.sh", + "disk_size": "1000" + }, + "builders": [ + { + "type": "qemu", + "iso_url": "{{user `iso_url`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "sha256", + "shutdown_command": "poweroff", + "headless": true, + "ssh_username": "root", + "ssh_password": "root", + "vm_name": "{{user `vm_name`}}", + "disk_interface": "ide", + "disk_compression": true, + "net_device": "e1000", + "disk_size": "{{user `disk_size`}}", + "boot_wait": "20s", + "ssh_wait_timeout": "60s", + "boot_command": [ + "root", + "echo 'root:root' | chpasswd", + "ifconfig lo up", + "ifconfig eth0 up && udhcpc -i eth0", + "setup-sshd -c openssh", + "sed -i.orig '$aPermitRootLogin yes' /etc/ssh/sshd_config", + "service sshd restart" + ] + } + ], + "provisioners": [ + { + "type": "shell", + "script": "scripts/install.sh" + }, + { + "type": "shell", + "inline": [ + "reboot" + ] + }, + { + "type": "shell", + "pause_before": "20s", + "inline": [ + "apk upgrade --update-cache" + ] + }, + { + "type": "shell", + "script": "scripts/gui.sh" + }, + { + "type": "shell", + "script": "scripts/{{user `setup_script`}}" + }, + { + "type": "shell", + "script": "scripts/post_setup.sh" + } + ] +} diff --git a/packer/alpine-linux/scripts/gui.sh b/packer/alpine-linux/scripts/gui.sh new file mode 100644 index 0000000..0519a32 --- /dev/null +++ b/packer/alpine-linux/scripts/gui.sh @@ -0,0 +1,17 @@ +# add community repository +sed -i 's/^#\(.*\/v.*\/community\)$/\1/' /etc/apk/repositories +apk update + +# install packages +setup-xorg-base lxdm xfwm4 xfdesktop xfce4-appfinder xfce4-session xfce4-settings xfce4-terminal dillo thunar exo adwaita-icon-theme ttf-dejavu xf86-video-qxl + +# configure packages +sed -i 's/^.*session=.*/session=\/usr\/bin\/startxfce4/' /etc/lxdm/lxdm.conf +echo "/sbin/poweroff" >> /etc/lxdm/PreShutdown +ln -s /usr/bin/dillo /usr/local/bin/firefox +rc-update add dbus +rc-update add lxdm + +# create user account +adduser -D -g "Linux User" user +passwd -u user diff --git a/packer/alpine-linux/scripts/install.sh b/packer/alpine-linux/scripts/install.sh new file mode 100644 index 0000000..908d4b0 --- /dev/null +++ b/packer/alpine-linux/scripts/install.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -e + +export HOSTNAMEOPTS="-n alpine" +export KEYMAPOPTS="us us" +export INTERFACESOPTS="auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp +" +export TIMEZONEOPTS="-z UTC" +export PROXYOPTS="none" +export APKREPOSOPTS="-1" +export SSHDOPTS="-c openssh" +export NTPOPTS="-c none" +export BOOT_SIZE=50 +export SWAP_SIZE=0 + +# Answer to password question twice and yes to format drive +setup-alpine <> etc/inittab +# restore default sshd configuration +mv /etc/ssh/sshd_config.orig /etc/ssh/sshd_config -apk add linux-virtgrsec -apk del linux-grsec -rm -Rf /lib/firmware +# clear cache rm -rf /var/cache/apk/* # Write 0 -dd if=/dev/zero of=/zero ; rm -f /zero +dd if=/dev/zero bs=1M of=/zero ; rm -f /zero diff --git a/packer/alpine-linux/scripts/serial.sh b/packer/alpine-linux/scripts/serial.sh new file mode 100644 index 0000000..7d99fb4 --- /dev/null +++ b/packer/alpine-linux/scripts/serial.sh @@ -0,0 +1,5 @@ +# use serial console +sed -i 's/\(APPEND .*\)/\1 console=ttyS0/' /boot/extlinux.conf + +# autologin on serial console +sed -i 's/^#* *ttyS0.*/ttyS0::respawn:\/bin\/login -f root/' /etc/inittab diff --git a/packer/alpine-linux/scripts/setup.sh b/packer/alpine-linux/scripts/setup.sh index 9114e5b..57f2cfc 100644 --- a/packer/alpine-linux/scripts/setup.sh +++ b/packer/alpine-linux/scripts/setup.sh @@ -1,43 +1,29 @@ -#!/bin/sh -# -# Copyright (C) 2015 GNS3 Technologies Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# install additional packages +apk add nano busybox-extras -set -e +# network configuration +cat > /etc/network/interfaces << EOF +# +# This is a sample network config, uncomment lines to configure the network +# -export KEYMAPOPTS="us us" -export HOSTNAMEOPTS="-n alpine" -export INTERFACESOPTS=" +# Loopback interface auto lo iface lo inet loopback -auto eth0 -iface eth0 inet dhcp" -export TIMEZONEOPTS="-z UTC" -export PROXYOPTS="none" -export APKREPOSOPTS="-r" -export SSHDOPTS="-c openssh" -export NTPOPTS="-c none" -export SWAP_SIZE=0 +# Static config for eth0 +#auto eth0 +#iface eth0 inet static +# address 192.168.0.2 +# netmask 255.255.255.0 +# gateway 192.168.0.1 +# up echo nameserver 192.168.0.1 > /etc/resolv.conf -# Answer to password question twice and yes to format drive -setup-alpine < /etc/resolv.conf << EOF +EOF