diff --git a/packer/alpine-linux/README.rst b/packer/alpine-linux/README.rst index ce6adec..2964c6f 100644 --- a/packer/alpine-linux/README.rst +++ b/packer/alpine-linux/README.rst @@ -15,7 +15,7 @@ The only added packages are: .. code:: bash - packer build alpine_cli.json + packer build alpine.json FRR @@ -25,7 +25,7 @@ A build of Alpine with FRRouting preinstalled. .. code:: bash - packer build -var-file=frr.json alpine_cli.json + packer build -var-file=frr.json alpine.json Alpine GUI installation @@ -35,5 +35,15 @@ The GUI version has XFCE4 installed. .. code:: bash - packer build alpine_gui.json + packer build -var-file=gui.json alpine.json + + +Ostinato +''''''''' + +A build of Alpine with Ostinato GUI and drone preinstalled. + +.. code:: bash + + packer build -var-file=ostinato.json alpine.json diff --git a/packer/alpine-linux/alpine_cli.json b/packer/alpine-linux/alpine.json similarity index 85% rename from packer/alpine-linux/alpine_cli.json rename to packer/alpine-linux/alpine.json index 248be6f..ad16271 100644 --- a/packer/alpine-linux/alpine_cli.json +++ b/packer/alpine-linux/alpine.json @@ -2,7 +2,9 @@ "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", + "ui_mode": "cli", "vm_name": "alpine_cli.qcow2", + "file_source": "README.rst", "setup_script": "setup.sh", "disk_size": "500" }, @@ -49,12 +51,18 @@ "type": "shell", "pause_before": "20s", "inline": [ - "apk upgrade --update-cache" + "apk upgrade --update-cache", + "mkdir -p /tmp/uploads" ] }, { "type": "shell", - "script": "scripts/serial.sh" + "script": "scripts/{{user `ui_mode`}}.sh" + }, + { + "type": "file", + "source": "files/{{user `file_source`}}", + "destination": "/tmp/uploads/" }, { "type": "shell", diff --git a/packer/alpine-linux/alpine_gui.json b/packer/alpine-linux/alpine_gui.json deleted file mode 100644 index f5b4c8e..0000000 --- a/packer/alpine-linux/alpine_gui.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "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/files/README.rst b/packer/alpine-linux/files/README.rst new file mode 100644 index 0000000..22b48b9 --- /dev/null +++ b/packer/alpine-linux/files/README.rst @@ -0,0 +1,5 @@ +Upload directory +================ + +A file/directory from this folder can be uploaded to the VM +by entering it in the variable "file_source". diff --git a/packer/alpine-linux/files/ostinato/3.12/ostinato-1.1-r0.apk b/packer/alpine-linux/files/ostinato/3.12/ostinato-1.1-r0.apk new file mode 100644 index 0000000..1a55d1a Binary files /dev/null and b/packer/alpine-linux/files/ostinato/3.12/ostinato-1.1-r0.apk differ diff --git a/packer/alpine-linux/files/ostinato/3.12/ostinato-drone-1.1-r0.apk b/packer/alpine-linux/files/ostinato/3.12/ostinato-drone-1.1-r0.apk new file mode 100644 index 0000000..4d80557 Binary files /dev/null and b/packer/alpine-linux/files/ostinato/3.12/ostinato-drone-1.1-r0.apk differ diff --git a/packer/alpine-linux/files/ostinato/3.12/ostinato-gui-1.1-r0.apk b/packer/alpine-linux/files/ostinato/3.12/ostinato-gui-1.1-r0.apk new file mode 100644 index 0000000..ae339c4 Binary files /dev/null and b/packer/alpine-linux/files/ostinato/3.12/ostinato-gui-1.1-r0.apk differ diff --git a/packer/alpine-linux/files/ostinato/build-package b/packer/alpine-linux/files/ostinato/build-package new file mode 100755 index 0000000..59ff4eb --- /dev/null +++ b/packer/alpine-linux/files/ostinato/build-package @@ -0,0 +1,20 @@ +#!/bin/sh + +alpine_version=3.12 + +mkdir -p "$alpine_version" +docker run --rm -i -v "$PWD/$alpine_version:/package" alpine:$alpine_version << 'EOF' +cd +apk add alpine-sdk +mkdir -p .abuild +echo 'PACKAGER="GNS3 Packer "' > .abuild/abuild.conf +abuild-keygen -a -n -q + +git clone --depth 1 git://git.alpinelinux.org/aports +cd aports/*/ostinato +abuild -F -r +cd + +find packages -name "*.apk" -type f -exec cp -p {} /package \; +chown $(stat -c '%u:%g' /package) /package/* +EOF diff --git a/packer/alpine-linux/files/ostinato/logo_256x256.png b/packer/alpine-linux/files/ostinato/logo_256x256.png new file mode 100644 index 0000000..3e56102 Binary files /dev/null and b/packer/alpine-linux/files/ostinato/logo_256x256.png differ diff --git a/packer/alpine-linux/gui.json b/packer/alpine-linux/gui.json new file mode 100644 index 0000000..55f2001 --- /dev/null +++ b/packer/alpine-linux/gui.json @@ -0,0 +1,5 @@ +{ + "ui_mode": "gui", + "vm_name": "alpine_gui.qcow2", + "disk_size": "1000" +} diff --git a/packer/alpine-linux/ostinato.json b/packer/alpine-linux/ostinato.json new file mode 100644 index 0000000..0bbaf0d --- /dev/null +++ b/packer/alpine-linux/ostinato.json @@ -0,0 +1,7 @@ +{ + "ui_mode": "gui", + "vm_name": "ostinato.qcow2", + "file_source": "ostinato", + "setup_script": "ostinato.sh", + "disk_size": "1000" +} diff --git a/packer/alpine-linux/scripts/serial.sh b/packer/alpine-linux/scripts/cli.sh similarity index 100% rename from packer/alpine-linux/scripts/serial.sh rename to packer/alpine-linux/scripts/cli.sh diff --git a/packer/alpine-linux/scripts/frr.sh b/packer/alpine-linux/scripts/frr.sh index 001e076..8b6ba6d 100644 --- a/packer/alpine-linux/scripts/frr.sh +++ b/packer/alpine-linux/scripts/frr.sh @@ -69,6 +69,7 @@ cat > /etc/network/interfaces << EOF # Loopback interface auto lo iface lo inet loopback + # Static config for eth0 #auto eth0 #iface eth0 inet static diff --git a/packer/alpine-linux/scripts/ostinato.sh b/packer/alpine-linux/scripts/ostinato.sh new file mode 100644 index 0000000..6793cf4 --- /dev/null +++ b/packer/alpine-linux/scripts/ostinato.sh @@ -0,0 +1,112 @@ +# install packages +alpine_version=$(cat /etc/alpine-release) +alpine_version=${alpine_version%.*} +apk add nano mousepad +apk add --allow-untrusted \ + /tmp/uploads/ostinato/$alpine_version/ostinato-drone*.apk \ + /tmp/uploads/ostinato/$alpine_version/ostinato-gui*.apk +apk add tshark wireshark + +# desktop integration +cat > /usr/share/applications/ostinato.desktop << 'EOF' +[Desktop Entry] +Type=Application +Name=Ostinato +Icon=ostinato +Exec=sh -c 'ostinato > /tmp/ostinato.log 2>&1' +Categories=Network;Monitor;Qt; +EOF +cp -p /tmp/uploads/ostinato/logo_256x256.png /usr/share/icons/hicolor/256x256/apps/ostinato.png +gtk-update-icon-cache -f /usr/share/icons/hicolor + +# change hostname +sed -i -e "s/^127\.0\.0\.1.*/127.0.0.1\tostinato.$(hostname -d) ostinato localhost.localdomain localhost/" /etc/hosts +echo ostinato > /etc/hostname +hostname ostinato + +# configure ostinato +mkdir -p /etc/xdg/Ostinato +printf '[General]\nRateAccuracy=Low\n[PortList]\nExclude=any,lo*\n' > /etc/xdg/Ostinato/drone.ini + +# allow ostinato group to run drone +addgroup -S ostinato +chgrp ostinato /usr/bin/drone +chmod 750 /usr/bin/drone +setcap cap_net_admin,cap_net_raw=eip /usr/bin/drone + +# add user to ostinato and wireshark group +addgroup user ostinato +addgroup user wireshark + +# create .profile +cat > /root/.profile << 'EOF' +# ~/.profile: executed by Bourne-compatible login shells. + +# reset terminal modes +[ -t 1 ] && printf '\e[?5l\e[?7h\e[?8h' + +if [ "$BASH" ]; then + if [ -f ~/.bashrc ]; then + . ~/.bashrc + fi +fi + +mesg n || true +EOF + +find /home -type d -mindepth 1 -maxdepth 1 | while read -r home; do + cp -p /root/.profile "$home/" + chown $(stat -c '%u:%g' "$home") "$home/.profile" +done + +# network configuration +cat > /etc/network/interfaces << EOF +# +# This is a sample network config, uncomment lines to configure the network +# +# Loopback interface +auto lo +iface lo inet loopback + +# 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 + +# DHCP config for eth0 +#auto eth0 +#iface eth0 inet dhcp +# hostname $(hostname) + +# Minimal configuration for ethernet interfaces +# If static IP or DHCP is enabled for eth0, comment the config for eth0 +auto eth0 +iface eth0 inet manual + pre-up sysctl -q -w net.ipv6.conf.\$IFACE.disable_ipv6=1 + up ip link set dev \$IFACE mtu 9000 up + down ip link set dev \$IFACE down + +auto eth1 +iface eth1 inet manual + pre-up sysctl -q -w net.ipv6.conf.\$IFACE.disable_ipv6=1 + up ip link set dev \$IFACE mtu 9000 up + down ip link set dev \$IFACE down + +auto eth2 +iface eth2 inet manual + pre-up sysctl -q -w net.ipv6.conf.\$IFACE.disable_ipv6=1 + up ip link set dev \$IFACE mtu 9000 up + down ip link set dev \$IFACE down + +auto eth3 +iface eth3 inet manual + pre-up sysctl -q -w net.ipv6.conf.\$IFACE.disable_ipv6=1 + up ip link set dev \$IFACE mtu 9000 up + down ip link set dev \$IFACE down +EOF + +cat > /etc/resolv.conf << EOF +EOF diff --git a/packer/alpine-linux/scripts/post_setup.sh b/packer/alpine-linux/scripts/post_setup.sh index bfeebfc..7d7ad9a 100644 --- a/packer/alpine-linux/scripts/post_setup.sh +++ b/packer/alpine-linux/scripts/post_setup.sh @@ -4,5 +4,8 @@ mv /etc/ssh/sshd_config.orig /etc/ssh/sshd_config # clear cache rm -rf /var/cache/apk/* +# clear uploads +rm -rf /tmp/uploads + # Write 0 dd if=/dev/zero bs=1M of=/zero ; rm -f /zero