added
This commit is contained in:
parent
eaf6ffdbef
commit
c417a6f3f9
37
Makefile
37
Makefile
@ -28,14 +28,6 @@ VERBOSE=2
|
||||
|
||||
all: install lint build check run test
|
||||
|
||||
# groddy but works for me
|
||||
install::
|
||||
# ( /usr/local/src ; ansible-galaxy collection install \
|
||||
# file:///usr/local/src/community.general )
|
||||
[ -e $(ANSIBLE_PLUGINS)/connection/libvirt_qemu.py ] \
|
||||
|| ln -s ${PWD}/lib/plugins/libvirt_qemu.py \
|
||||
$(ANSIBLE_PLUGINS)/connection/q || true
|
||||
|
||||
lint::
|
||||
@sudo xmllint -noout roles/ansible-gentoo_install/templates/etc/libvirt/qemu/gentoo.xml
|
||||
@yamllint -c .yamllint.yml -f standard *.yml roles/*/*s/*yml 2>&1| \
|
||||
@ -44,18 +36,29 @@ lint::
|
||||
grep -B 2 error | tee .yamllint.err || true
|
||||
grep Error .yamllint.out || true
|
||||
|
||||
build:: build_base
|
||||
# groddy but works for me
|
||||
install:: lint
|
||||
# ( /usr/local/src ; ansible-galaxy collection install \
|
||||
# file:///usr/local/src/community.general )
|
||||
[ -e $(ANSIBLE_PLUGINS)/connection/libvirt_qemu.py ] \
|
||||
|| ln -s ${PWD}/lib/plugins/libvirt_qemu.py \
|
||||
$(ANSIBLE_PLUGINS)/connection/q || true
|
||||
@[ -f ${BOX_NBD_BASE_QCOW} ] || { \
|
||||
echo ERROR: not created BOX_NBD_DEV="${BOX_NBD_DEV}" - use ; \
|
||||
echo qemu-img create -f qcow2 "${BOX_NBD_BASE_QCOW}" 20G ; \
|
||||
exit 2 ; }
|
||||
@( ps ax | grep -v grep | \
|
||||
grep "qemu-nbd.*/dev/nbd.*${BOX_NBD_BASE_QCOW}" ) || { \
|
||||
echo ERROR: not mounted BOX_NBD_DEV="${BOX_NBD_DEV}" - use ; \
|
||||
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 ${BOX_NBD_BASE_QCOW} ;\
|
||||
exit 1 ; }
|
||||
|
||||
build::
|
||||
sudo $(MAKE) -$(MAKEFLAGS) build_base
|
||||
sudo $(MAKE) -$(MAKEFLAGS) build_overlay
|
||||
|
||||
build_base:: lint
|
||||
build_base:: install
|
||||
echo INFO: $@ "${BOX_NBD_BASE_QCOW}"
|
||||
@[ ! -f ${BOX_NBD_BASE_QCOW} ] || { \
|
||||
echo WARN looks like theres already a build of \
|
||||
"${BOX_NBD_BASE_QCOW}" ; exit 2 ; }
|
||||
@( ! ps ax | grep -v grep | \
|
||||
grep "qemu-nbd.*/dev/nbd.*${BOX_NBD_BASE_QCOW}" ) ||{ \
|
||||
echo WARN looks like theres an active nbd mount of \
|
||||
"${BOX_NBD_BASE_QCOW}" && exit 1 ; }
|
||||
echo INFO running the toxcore role will build ${BOX_NBD_BASE_QCOW}
|
||||
sudo sh ansible_local.bash --diff -i ${PWD}/hosts.yml \
|
||||
-l ${LOCALHOST} -c local --verbose ${VERBOSE} \
|
||||
|
38
README.md
38
README.md
@ -77,26 +77,36 @@ the hosts.yml file from the host called gentoo1 in the linux_libvirt_group.
|
||||
There are 3 ansible roles:
|
||||
|
||||
1. base : The base role sets up the basics and is required to be run.
|
||||
|
||||
It sets up the essential parameters to run roles on the host or client.
|
||||
Check the settings in roles/base/defaults/main.yml before running the role.
|
||||
|
||||
2. proxy : The proxy role sets up the networking with proxies,
|
||||
and is required to be run, even if you don't use a proxy.
|
||||
It sets proxying and installs basic packages on the host or client.
|
||||
Check the settings in roles/proxy/defaults/main.yml before running the role.
|
||||
|
||||
3. toxcore :
|
||||
This role sets up the software to run libvirt on the host.
|
||||
Check the settings in roles/toxcore/defaults/main.yml before running the role.
|
||||
|
||||
In addition, toxcore calls an included role ansible-gentoo_install.
|
||||
This is an updated version of the abandonned
|
||||
https://github.com/agaffney/ansible-gentoo_install/ This role,
|
||||
when run on the host, builds the Gentoo base qcow image. As a safety
|
||||
feature, you must create the qcow2 image and activate it with:
|
||||
|
||||
The host creates the base qcow2 image and then creates the overlay
|
||||
image. When both are created, it install Tox software on the host and
|
||||
client.
|
||||
|
||||
In addition, toxcore calls an included role ansible-gentoo_install.
|
||||
This is an updated version of the abandonned
|
||||
https://github.com/agaffney/ansible-gentoo_install/ This role,
|
||||
when run on the host, builds the Gentoo base qcow image. As a safety
|
||||
feature, you must create the qcow2 image and activate it with:
|
||||
modprobe nbd
|
||||
qemu-img $BOX_NBD_BASE_QCOW 20G
|
||||
qemu-nbd -c $BOX_NBD_DEV $BOX_NBD_BASE_QCOW
|
||||
|
||||
modprobe nbd
|
||||
qemu-img $BOX_NBD_BASE_QCOW 20G
|
||||
qemu-nbd -c $BOX_NBD_DEV $BOX_NBD_BASE_QCOW
|
||||
|
||||
and put these values into the hosts.yml file in the pentoo or devuan
|
||||
target, depending on your host operating system. The filesytem that
|
||||
holds base qcow2 $BOX_NBD_BASE_QCOW must have at least 12G available,
|
||||
and may grow to almost 20G.
|
||||
and put these values into the hosts.yml file in the pentoo or devuan
|
||||
target, depending on your host operating system. The filesytem that
|
||||
holds base qcow2 $BOX_NBD_BASE_QCOW must have at least 12G available,
|
||||
and may grow to almost 20G.
|
||||
|
||||
After you have finished building the base qcow2 image, you will want
|
||||
to dismount it with qemu-nbd -d $BOX_NBD_DEV. Be careful and look
|
||||
|
@ -259,7 +259,7 @@ all:
|
||||
# for a non-root login: ansible_ssh_extra_args: "--userspec=foo:adm"
|
||||
vars: # linux_unix_group
|
||||
# toxcore
|
||||
BOX_NBD_DEV: nbd3
|
||||
BOX_NBD_DEV: nbd1
|
||||
BOX_NBD_MP: /mnt/gentoo
|
||||
BOX_NBD_OVERLAY_NAME: "gentoo1"
|
||||
BOX_NBD_FILES: "/i/data/Agile/tmp/Topics/GentooImgr"
|
||||
|
@ -163,7 +163,8 @@ def run_module():
|
||||
action=dict(type='str', required=True),
|
||||
loglevel=dict(type='int', required=False, default=logging.INFO),
|
||||
threads=dict(type='int', required=False, default=1),
|
||||
config=dict(type='path', default=def_config, required=True),
|
||||
# Module error: required and default are mutually exclusive for config
|
||||
config=dict(type='path', default=def_config),
|
||||
profile=dict(type='str', required=False),
|
||||
kernel_dir=dict(type='path', required=False),
|
||||
portage=dict(type='path', required=False),
|
||||
|
@ -1,183 +0,0 @@
|
||||
# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
|
||||
---
|
||||
- name: "DEBUG: ansible-gentoo_install local"
|
||||
debug:
|
||||
verbosity: 0
|
||||
msg: "DEBUG: ansible-gentoo_install local BOX_NBD_DEV={{BOX_NBD_DEV}}"
|
||||
check_mode: no
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'{{BOX_NBD_DEV}}' != ''"
|
||||
when: ansible_connection in ['local', 'chroot']
|
||||
|
||||
- set_fact:
|
||||
AGI_use_local_kernel: true
|
||||
when:
|
||||
- ansible_distribution == 'Gentoo' or BOX_GENTOO_FROM_MP not in ['/', '']
|
||||
|
||||
- set_fact:
|
||||
AGI_PROXY_MODE: "{{PROXY_MODE|default('')}}"
|
||||
when:
|
||||
- PROXY_MODE|default('') != ''
|
||||
check_mode: no
|
||||
|
||||
- set_fact:
|
||||
AGI_PROXY_MODE: "{{BOX_PROXY_MODE|default('')}}"
|
||||
when:
|
||||
- AGI_PROXY_MODE == ''
|
||||
check_mode: no
|
||||
|
||||
- block:
|
||||
|
||||
- name: check for mounted disk
|
||||
shell: |
|
||||
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 0
|
||||
ps ax | grep -v grep | \
|
||||
grep "qemu-nbd.*/dev/nbd.*{{BOX_NBD_BASE_QCOW}}" && \
|
||||
echo WARN looks like theres an active nbd mount of \
|
||||
"${BOX_NBD_BASE_QCOW}" && exit 1
|
||||
exit 2
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
register: check_mounted_disk
|
||||
check_mode: no
|
||||
|
||||
- name: partition if disk not mounted
|
||||
fail:
|
||||
msg: "looks like theres an active nbd mount of {{BOX_NBD_BASE_QCOW}}"
|
||||
when:
|
||||
- check_mounted_disk.rc == 1
|
||||
check_mode: no
|
||||
|
||||
- name: partition if disk not mounted or active
|
||||
include: disk.yml
|
||||
when:
|
||||
- check_mounted_disk.rc > 1
|
||||
check_mode: no
|
||||
|
||||
- name: mount root partition
|
||||
mount:
|
||||
name: "{{AGI_NBD_MP}}"
|
||||
src: "{{ AGI_install_disk }}p3"
|
||||
fstype: ext4
|
||||
state: mounted
|
||||
check_mode: false
|
||||
|
||||
- name: create /boot mountpoint
|
||||
file:
|
||||
path: "{{AGI_NBD_MP}}/boot"
|
||||
state: directory
|
||||
check_mode: false
|
||||
|
||||
- name: mount boot partition
|
||||
mount:
|
||||
name: "{{AGI_NBD_MP}}/boot"
|
||||
src: "{{ AGI_install_disk }}p1"
|
||||
fstype: ext2
|
||||
state: mounted
|
||||
check_mode: false
|
||||
|
||||
- include: tarball.yml
|
||||
- include: copy.yml
|
||||
when: AGI_use_local_kernel
|
||||
|
||||
- name: mount distfiles
|
||||
delegate_to: localhost
|
||||
shell: |
|
||||
[ -d "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] || exit 1
|
||||
grep {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} /proc/mounts && exit 0
|
||||
[ -d {{AGI_NBD_MP}}/usr/portage/ ] || exit 0
|
||||
[ -d {{AGI_NBD_MP}}/usr/portage/distfiles ] || mkdir {{AGI_NBD_MP}}/usr/portage/distfiles
|
||||
mount --bind {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} {{AGI_NBD_MP}}/usr/portage/distfiles
|
||||
when:
|
||||
- "MOUNT_GENTOO_DISTFILES_ARCHIVES != ''"
|
||||
- "AGI_NBD_MP != ''"
|
||||
|
||||
- include: chroot.yml
|
||||
|
||||
delegate_to: localhost
|
||||
when: ansible_connection in ['chroot', 'local'] # libvirt?
|
||||
|
||||
- block:
|
||||
|
||||
- name: check chroot wrapper installed
|
||||
shell: |
|
||||
[ -x /var/tmp/chroot_wrapper.sh ] || exit 1
|
||||
df /mnt/gentoo || exit 2
|
||||
/var/tmp/chroot_wrapper.sh /bin/df | grep /mnt/gentoo && exit 4
|
||||
exit 0
|
||||
register: chroot_out
|
||||
check_mode: false
|
||||
|
||||
- name: enable chroot wrapper
|
||||
set_fact:
|
||||
ansible_shell_executable: /var/tmp/chroot_wrapper.sh
|
||||
old_ansible_python_interpreter: "{{ansible_python_interpreter}}"
|
||||
ansible_python_interpreter: "/usr/bin/python3"
|
||||
check_mode: false
|
||||
|
||||
when: ansible_connection in ['local']
|
||||
|
||||
- block:
|
||||
|
||||
- include: portage.yml
|
||||
- include: misc.yml
|
||||
|
||||
- include: network.yml
|
||||
|
||||
- include: kernel.yml
|
||||
when: not AGI_use_local_kernel
|
||||
|
||||
- include: bootloader.yml
|
||||
- include: daemons.yml
|
||||
|
||||
# - include: finish.yml
|
||||
|
||||
check_mode: false
|
||||
when:
|
||||
- "ansible_connection in ['chroot'] or (ansible_connection in ['local'] or and chroot_out.rc|default(1) == 0)"
|
||||
rescue:
|
||||
- debug:
|
||||
msg: "ERROR: error during chroot execution"
|
||||
|
||||
- name: disable chroot wrapper
|
||||
set_fact:
|
||||
ansible_shell_executable: /bin/sh
|
||||
ansible_python_interpreter: "{{old_ansible_python_interpreter}}"
|
||||
when:
|
||||
- "ansible_connection in ['local'] and chroot_out.rc|default(1) == 0"
|
||||
check_mode: false
|
||||
|
||||
- name: unmount filesystems
|
||||
mount:
|
||||
name: "{{AGI_NBD_MP}}/{{ item }}"
|
||||
state: unmounted
|
||||
with_items:
|
||||
- proc
|
||||
- sys
|
||||
- dev/pts
|
||||
- dev/shm
|
||||
- dev
|
||||
- boot
|
||||
- ''
|
||||
loop_control:
|
||||
label: "{{AGI_NBD_MP}}/{{ item }}"
|
||||
when:
|
||||
- "ansible_connection in ['local'] and chroot_out.rc|default(1) == 0"
|
||||
- false # leave it mounted for testing
|
||||
|
||||
- name: dismount any other mounts
|
||||
shell: |
|
||||
if [ -z "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] && \
|
||||
[ -d "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] && \
|
||||
grep {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} /proc/mounts ; then
|
||||
umount {{MOUNT_GENTOO_DISTFILES_ARCHIVES}}
|
||||
fi
|
||||
df -a | grep "{{AGI_NBD_MP}}" | sed -e 's/.* //' | tac | while read elt;do
|
||||
umount $elt
|
||||
done
|
||||
base_chroot_unbind.bash "{{AGI_NBD_MP}}"
|
||||
when:
|
||||
- "ansible_connection in ['chroot'] or chroot_out.rc|default(1) == 0"
|
||||
- false # leave it mounted for testing
|
@ -39,12 +39,12 @@
|
||||
- name: copy kernel sources
|
||||
copy:
|
||||
src: "{{AGI_GENTOO_FROM_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
dest: "{{AGI_NBD_MP}}/usr/src"
|
||||
dest: "{{AGI_NBD_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
remote_src: no
|
||||
creates: "{{AGI_NBD_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
when:
|
||||
- kernel_out.rc|default(1) == 0
|
||||
- AGI_use_local_kernel
|
||||
- false
|
||||
|
||||
- name: resolve kver
|
||||
shell: |
|
||||
@ -99,6 +99,8 @@
|
||||
when:
|
||||
- AGI_use_local_kernel
|
||||
- ramfs_out.rc|default(1) == 0
|
||||
- false
|
||||
ignore_errors: true
|
||||
|
||||
- name: make directories
|
||||
shell: |
|
||||
@ -111,6 +113,6 @@
|
||||
[ -f "{{AGI_NBD_MP}}/$file" ] && continue
|
||||
cp -np "$file" "{{AGI_NBD_MP}}/$file"
|
||||
done
|
||||
ignore_errors: false
|
||||
ignore_errors: true
|
||||
|
||||
# dracut
|
||||
|
@ -32,12 +32,19 @@
|
||||
|
||||
- name: check for mounted disk
|
||||
shell: |
|
||||
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 0
|
||||
ps ax | grep -v grep | \
|
||||
grep "qemu-nbd.*/dev/nbd.*{{BOX_NBD_BASE_QCOW}}" && \
|
||||
echo WARN looks like theres an active nbd mount of \
|
||||
"${BOX_NBD_BASE_QCOW}" && exit 1
|
||||
exit 2
|
||||
grep '/dev/{{AGI_NBD_DEV}}p3' /proc/mounts && exit 0
|
||||
if [ ! -f "{{BOX_NBD_BASE_QCOW}}" ] ; then
|
||||
echo ERROR: not created BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use
|
||||
echo qemu-img create -f qcow2 "{{BOX_NBD_BASE_QCOW}}" 20G
|
||||
exit 1
|
||||
fi
|
||||
if ! ps ax | grep -v grep | \
|
||||
grep "qemu-nbd.*{{AGI_NBD_DEV}}.*{{BOX_NBD_BASE_QCOW}}" ; then
|
||||
echo ERROR: not mounted BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use
|
||||
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 {{BOX_NBD_BASE_QCOW}}
|
||||
exit 2
|
||||
fi
|
||||
exit 3
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
register: check_mounted_disk
|
||||
@ -45,15 +52,15 @@
|
||||
|
||||
- name: partition if disk not mounted
|
||||
fail:
|
||||
msg: "looks like theres an active nbd mount of {{BOX_NBD_BASE_QCOW}}"
|
||||
msg: "make and nbd mount {{BOX_NBD_BASE_QCOW}}"
|
||||
when:
|
||||
- check_mounted_disk.rc == 1
|
||||
- check_mounted_disk.rc in [2, 1]
|
||||
check_mode: no
|
||||
|
||||
- name: partition if disk not mounted or active
|
||||
include: disk.yml
|
||||
when:
|
||||
- check_mounted_disk.rc > 1
|
||||
- check_mounted_disk.rc > 2
|
||||
check_mode: no
|
||||
|
||||
- name: mount root partition
|
||||
|
@ -52,6 +52,8 @@
|
||||
fi
|
||||
if ! grep -q "{{BOX_NBD_DEV}}" /proc/partitions ; then
|
||||
echo ERROR: not mounted BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use qemu-nbd
|
||||
echo qemu-img create -f qcow2 /a/tmp/GentooImgr/gentoo.qcow2 20G
|
||||
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 /a/tmp/GentooImgr/gentoo.qcow
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
@ -71,19 +73,27 @@
|
||||
fi
|
||||
fi
|
||||
# should operate on json with jq
|
||||
# "imgsize": "20G",
|
||||
# "memory": 4096,
|
||||
# "mountpoint": "/mnt/gentoo",
|
||||
# "imagename": null,
|
||||
# "initsys": "openrc",
|
||||
# "iso": null,
|
||||
# "portage": null,
|
||||
# "stage3": null,
|
||||
# "partition": 1
|
||||
if [ -f "$tofile" ] ; then
|
||||
# "imgsize": "20G",
|
||||
sed -i -e 's@"imgsize": ".*"@"imgsize": "{{BOX_NBD_OVERLAY_GB}}"@' $tofile
|
||||
# "memory": 4096,
|
||||
sed -i -e 's@"memory": ".*"@"imgsize": "{{BOX_NBD_OVERLAY_RAM}}"@' $tofile
|
||||
# "mountpoint": "/mnt/gentoo",
|
||||
sed -i -e 's@"mountpoint": ".*"@"mountpoint": "{{BOX_NBD_MP}}"@' $tofile
|
||||
# "imagename": null,
|
||||
sed -i -e 's@"imagename": ".*"@"imagename": "{{BOX_NBD_OVERLAY_NAME}}"@' $tofile
|
||||
# "initsys": "openrc",
|
||||
sed -i -e 's@"initsys": ".*"@"initsys: "{{BOX_NBD_BASE_PROFILE}}"@' $tofile
|
||||
# "iso": null,
|
||||
# "portage": null,
|
||||
sed -i -e 's@""portage": ".*"@""portage: "{{BOX_NBD_PORTAGE_FILE}}"@' $tofile
|
||||
# "stage3": null,
|
||||
sed -i -e 's@""stage3": ".*"@""stage3: "{{BOX_NBD_STAGE3_FILE}}"@' $tofile
|
||||
# "partition": 1
|
||||
sed -i -e 's@"partition": ".*"@"partition": 3@' $tofile
|
||||
# but this is crucial
|
||||
# "disk": "/dev/sda",
|
||||
sed -i -e 's@"disk": ".*"@"disk": "'{{BOX_NBD_DEV}}'"@' $tofile
|
||||
sed -i -e 's@"disk": ".*"@"disk": "{{BOX_NBD_DEV}}"@' $tofile
|
||||
grep {{BOX_NBD_DEV}} $tofile || exit 4
|
||||
fi
|
||||
|
||||
|
193
roles/toxcore/files/gentoo.xml
Normal file
193
roles/toxcore/files/gentoo.xml
Normal file
@ -0,0 +1,193 @@
|
||||
<!--
|
||||
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
|
||||
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
|
||||
virsh edit gentoo
|
||||
or other application using the libvirt API.
|
||||
-->
|
||||
|
||||
<domain type='kvm'>
|
||||
<name>gentoo</name>
|
||||
<uuid>1362f7fd-ea55-4f2f-91c5-3b61ec26c1a0</uuid>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://gentoo.org/gentoo/rolling"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit='KiB'>3121152</memory>
|
||||
<currentMemory unit='KiB'>2097152</currentMemory>
|
||||
<memoryBacking>
|
||||
<source type='memfd'/>
|
||||
<access mode='shared'/>
|
||||
</memoryBacking>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-q35-8.1'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<vmport state='off'/>
|
||||
</features>
|
||||
<cpu mode='host-passthrough' check='none' migratable='on'/>
|
||||
<clock offset='utc'>
|
||||
<timer name='rtc' tickpolicy='catchup'/>
|
||||
<timer name='pit' tickpolicy='delay'/>
|
||||
<timer name='hpet' present='no'/>
|
||||
</clock>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<pm>
|
||||
<suspend-to-mem enabled='no'/>
|
||||
<suspend-to-disk enabled='no'/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/var/lib/libvirt/images/gentoo1.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<target dev='sda' bus='sata'/>
|
||||
<readonly/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pcie-root'/>
|
||||
<controller type='pci' index='1' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='1' port='0x10'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
|
||||
</controller>
|
||||
<controller type='pci' index='2' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='2' port='0x11'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='3' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='3' port='0x12'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='4' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='4' port='0x13'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
|
||||
</controller>
|
||||
<controller type='pci' index='5' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='5' port='0x14'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
|
||||
</controller>
|
||||
<controller type='pci' index='6' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='6' port='0x15'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
|
||||
</controller>
|
||||
<controller type='pci' index='7' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='7' port='0x16'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
|
||||
</controller>
|
||||
<controller type='pci' index='8' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='8' port='0x17'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
|
||||
</controller>
|
||||
<controller type='pci' index='9' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='9' port='0x18'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
|
||||
</controller>
|
||||
<controller type='pci' index='10' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='10' port='0x19'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='11' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='11' port='0x1a'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='12' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='12' port='0x1b'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
|
||||
</controller>
|
||||
<controller type='pci' index='13' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='13' port='0x1c'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
|
||||
</controller>
|
||||
<controller type='pci' index='14' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='14' port='0x1d'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
|
||||
</controller>
|
||||
<controller type='sata' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='virtio-serial' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:be:61:e1'/>
|
||||
<source network='Whonix-External'/>
|
||||
<model type='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
|
||||
</interface>
|
||||
<serial type='pty'>
|
||||
<target type='isa-serial' port='0'>
|
||||
<model name='isa-serial'/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type='pty'>
|
||||
<target type='serial' port='0'/>
|
||||
</console>
|
||||
<channel type='unix'>
|
||||
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='1'/>
|
||||
</channel>
|
||||
<channel type='spicevmc'>
|
||||
<target type='virtio' name='com.redhat.spice.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='2'/>
|
||||
</channel>
|
||||
<input type='tablet' bus='usb'>
|
||||
<address type='usb' bus='0' port='1'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<sound model='ich9'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
|
||||
</sound>
|
||||
<audio id='1' type='spice'/>
|
||||
<video>
|
||||
<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
|
||||
</video>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='2'/>
|
||||
</redirdev>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='3'/>
|
||||
</redirdev>
|
||||
<watchdog model='itco' action='reset'/>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
|
||||
</memballoon>
|
||||
<rng model='virtio'>
|
||||
<backend model='random'>/dev/urandom</backend>
|
||||
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
|
||||
</rng>
|
||||
</devices>
|
||||
</domain>
|
92
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_build_overlay_qcow.bash
Executable file
92
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_build_overlay_qcow.bash
Executable file
@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
# from https://github.com/earlruby/create-vm/
|
||||
|
||||
[ -f /usr/local/bin/usr_local_tput.bash ] && \
|
||||
. /usr/local/bin/usr_local_tput.bash || {
|
||||
DBUG() { echo DEBUG $* ; }
|
||||
INFO() { echo INFO $* ; }
|
||||
WARN() { echo WARN $* ; }
|
||||
ERROR() { echo ERROR $* ; }
|
||||
}
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
BOX=gentoo
|
||||
|
||||
export BASE_SRC_ANSIBLE=/o/var/local/src/play_tox
|
||||
yamllint -c $BASE_SRC_ANSIBLE/.yamllint.rc $BASE_SRC_ANSIBLE/hosts.yml|| {
|
||||
ERROR
|
||||
exit 1
|
||||
}
|
||||
|
||||
# put these values in $BASE_SRC_ANSIBLE/hosts.yml
|
||||
[ -n "$BOX_NBD_OVERLAY_NAME" ] || \
|
||||
BOX_NBD_OVERLAY_NAME=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_NAME $BOX)
|
||||
[ -n "$BOX_NBD_BASE_PUBKEY" ] || \
|
||||
BOX_NBD_BASE_PUBKEY=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_BASE_PUBKEY $BOX)
|
||||
[ -n "$BOX_NBD_BASE_QCOW" ] || \
|
||||
BOX_NBD_BASE_QCOW=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_BASE_QCOW $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_GB" ] || \
|
||||
BOX_NBD_OVERLAY_GB=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_GB $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_CPUS" ] || \
|
||||
BOX_NBD_OVERLAY_CPUS=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_CPUS $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_RAM" ] || \
|
||||
BOX_NBD_OVERLAY_RAM=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_RAM $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_DIR" ] || \
|
||||
BOX_NBD_OVERLAY_DIR=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_DIR $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_BR" ] || \
|
||||
BOX_NBD_OVERLAY_BR=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_BR $BOX)
|
||||
#[ -n "$BOX_NBD_OVERLAY_NETWORK" ] || \
|
||||
# BOX_NBD_OVERLAY_NETWORK=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_NETWORK $BOX)
|
||||
[ -n "$BOX_NBD_OVERLAY_PASS" ] || \
|
||||
BOX_NBD_OVERLAY_PASS=$( /usr/local/bin/ansible_get_inventory.bash BOX_NBD_OVERLAY_PASS $BOX)
|
||||
|
||||
[ ! -f "$BOX_NBD_BASE_QCOW" ] && \
|
||||
ERROR BOX_NBD_BASE_QCOW=$BOX_NBD_BASE_QCOW must exist && exit 3
|
||||
[ ! -d "$BOX_NBD_OVERLAY_DIR" ] && \
|
||||
ERROR BOX_NBD_OVERLAY_DIR=$BOX_NBD_OVERLAY_DIR must exist && exit 5
|
||||
|
||||
[ -z "$BOX_NBD_OVERLAY_BR" ] && \
|
||||
ERROR BOX_NBD_OVERLAY_BR=$BOX_NBD_OVERLAY_BR must not be null && exit 5
|
||||
|
||||
[ -n "$BOX_NBD_DEV" ] && grep "$BOX_NBD_DEV" /proc/mounts && WARN "$BOX_NBD_DEV" is mounted
|
||||
export BOX_NBD_OVERLAY_DIR
|
||||
|
||||
# libvirt.libvirtError: Network not found: no network with matching name 'default'a
|
||||
DBUG bash toxcore_create-vm.bash \
|
||||
-n $BOX_NBD_OVERLAY_NAME \
|
||||
-k $BOX_NBD_BASE_PUBKEY \
|
||||
-i $BOX_NBD_BASE_QCOW \
|
||||
-s $BOX_NBD_OVERLAY_GB \
|
||||
-b $BOX_NBD_OVERLAY_BR \
|
||||
-c $BOX_NBD_OVERLAY_CPUS \
|
||||
-r $BOX_NBD_OVERLAY_RAM \
|
||||
-d $BOX_NBD_OVERLAY_DIR \
|
||||
-p $BOX_NBD_OVERLAY_PASS \
|
||||
-o gentoo
|
||||
bash toxcore_create-vm.bash \
|
||||
-n $BOX_NBD_OVERLAY_NAME \
|
||||
-k $BOX_NBD_BASE_PUBKEY \
|
||||
-i $BOX_NBD_BASE_QCOW \
|
||||
-s $BOX_NBD_OVERLAY_GB \
|
||||
-b $BOX_NBD_OVERLAY_BR \
|
||||
-c $BOX_NBD_OVERLAY_CPUS \
|
||||
-r $BOX_NBD_OVERLAY_RAM \
|
||||
-d $BOX_NBD_OVERLAY_DIR \
|
||||
-p $BOX_NBD_OVERLAY_PASS \
|
||||
-o gentoo < /dev/null
|
||||
retval=$?
|
||||
[ $retval -gt 0 ] && exit 1$retval
|
||||
[ -f $BOX_NBD_OVERLAY_DIR/images/$BOX_NBD_OVERLAY_NAME.img ] && \
|
||||
INFO $BOX_NBD_OVERLAY_DIR/images/$BOX_NBD_OVERLAY_NAME.img || {
|
||||
ERROR NO $BOX_NBD_OVERLAY_DIR/images/$BOX_NBD_OVERLAY_NAME.img ; exit 2$retval ; }
|
||||
|
||||
INFO virsh define $BOX_NBD_OVERLAY_NAME
|
||||
virsh define $BOX_NBD_OVERLAY_DIR/$BOX_NBD_OVERLAY_NAME.img
|
||||
sleep 5
|
||||
INFO virsh net-dhcp-leases default
|
||||
sudo virsh net-dhcp-leases default
|
||||
sudo find /var/lib/libvirt/qemu/channel/target/*${BOX_NBD_OVERLAY_NAME}* \
|
||||
-name org.qemu.guest_agent.0
|
125
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_check_modules.bash
Executable file
125
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_check_modules.bash
Executable file
@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
|
||||
. /usr/local/bin/usr_local_tput.bash || exit 2
|
||||
|
||||
|
||||
# FixMe - systemd
|
||||
|
||||
|
||||
MYID=`id -u`
|
||||
# or use sudo? or just diagnostics? $prog should be run as root $MYID
|
||||
[ $MYID -eq 0 ] && sudo= || sudo="WARN as root - sudo"
|
||||
|
||||
grep -q iommu=pt /proc/cmdline || WARN 'iommu=pt not on command line'
|
||||
grep -q intel_iommu=on /proc/cmdline || WARN 'intel_iommu=on not on command line'
|
||||
|
||||
# https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Setting_up_IOMMU
|
||||
shopt -s nullglob
|
||||
if [ $MYID -eq 0 ] ; then
|
||||
[ -s "$TOXCORE_LOG_DIR"/iommu_groups.log ] || \
|
||||
for g in /sys/kernel/iommu_groups/*; do
|
||||
echo "IOMMU Group ${g##*/}:"
|
||||
for d in $g/devices/*; do
|
||||
echo -e "\t$(lspci -nns ${d##*/})"
|
||||
done
|
||||
done 2>&1|tee "$TOXCORE_LOG_DIR"/iommu_groups.log
|
||||
|
||||
b=`wc -l "$TOXCORE_LOG_DIR"/iommu_groups.log|sed -e 's/ .*//'`
|
||||
[ $? -eq 0 -a -n "$b" -a "$b" -gt 0 ] || dmesg | grep -q 'DMAR: IOMMU enabled' || WARN 'IOMMU not active'
|
||||
fi
|
||||
|
||||
if ifconfig -a | grep ^eth ; then
|
||||
INFO eth present
|
||||
else
|
||||
WARN eth NOT present
|
||||
lspci -v | grep '0[1-9]:00.0 Ethernet controller' || {
|
||||
WARN Ethernet NOT present
|
||||
rmmod r8169
|
||||
modprobe r8169 debug=6
|
||||
}
|
||||
true || [ -f /var/lib/libvirt/net.xml ] || cat > /var/lib/libvirt/net.xml << EOF
|
||||
<network>
|
||||
<name>network</name>
|
||||
<uuid>3f1b2eb3-98da-4e6d-8ad8-30e0e05a21d4</uuid>
|
||||
<forward mode="nat"/>
|
||||
<bridge name="virbr0" stp="on" delay="0"/>
|
||||
<mac address="52:54:00:14:17:cf"/>
|
||||
<domain name="network"/>
|
||||
<ip address="192.168.100.1" netmask="255.255.255.0">
|
||||
<dhcp>
|
||||
<range start="192.168.100.128" end="192.168.100.254"/>
|
||||
</dhcp>
|
||||
</ip>
|
||||
</network>
|
||||
EOF
|
||||
ifconfig -a |grep ^eth && {
|
||||
ifconfig -a |grep ^virbr || {
|
||||
$sudo virsh net-create /var/lib/libvirt/net.xml
|
||||
}
|
||||
}
|
||||
fi
|
||||
|
||||
#4?
|
||||
MODS4=(
|
||||
nf_conntrack_ipv4
|
||||
nf_nat_ipv4
|
||||
)
|
||||
|
||||
MODS=(
|
||||
ip_tables
|
||||
iptable_filter
|
||||
iptable_nat
|
||||
iptable_mangle
|
||||
|
||||
ipt_REJECT
|
||||
|
||||
nf_conntrack
|
||||
nf_defrag_ipv4
|
||||
#5? nf_log_common
|
||||
#5? nf_log_syslog
|
||||
nf_log_ipv4
|
||||
nf_nat
|
||||
|
||||
nf_reject_ipv4
|
||||
nft_masq
|
||||
|
||||
xt_MASQUERADE
|
||||
x_tables
|
||||
|
||||
bridge
|
||||
br_netfilter
|
||||
)
|
||||
# bridge: filtering via arp/ip/ip6tables is no longer available by default. Update your scripts to load br_netfilter if you need this.
|
||||
|
||||
lsmod | sort > /tmp/$$.lsmod
|
||||
for mod in "${MODS[@]}" ; do
|
||||
grep -q ^$mod /tmp/$$.lsmod || $sudo modprobe $mod
|
||||
done
|
||||
rm -f /tmp/$$.lsmod
|
||||
|
||||
# selectively activate runtime features
|
||||
[ "$#" -eq 0 ] && exit 0
|
||||
|
||||
if [ "$1" = "libvirt" ] ; then
|
||||
/etc/init.d/libvirtd status || $sudo /etc/init.d/libvirtd start
|
||||
ifconfig -a | grep virbr0 || {
|
||||
WARN virbr0 not present - modprobe "${MODS[@]}" ; }
|
||||
fi
|
||||
if [ "$1" = "qemu" ] ; then
|
||||
lsmod | grep -q kvm || $sudo modprobe kvm
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "docker" ] ; then
|
||||
#? modules for docker?
|
||||
/etc/init.d/docker status || $sudo /etc/init.d/docker start
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
14385
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_create-ga.sh
Executable file
14385
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_create-ga.sh
Executable file
File diff suppressed because it is too large
Load Diff
420
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_create-vm.bash
Executable file
420
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_create-vm.bash
Executable file
@ -0,0 +1,420 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
# from https://github.com/earlruby/create-vm/
|
||||
|
||||
[ -f /usr/local/bin/usr_local_tput.bash ] && \
|
||||
. /usr/local/bin/usr_local_tput.bash || {
|
||||
DBUG() { echo DEBUG $* ; }
|
||||
INFO() { echo INFO $* ; }
|
||||
WARN() { echo WARN $* ; }
|
||||
ERROR() { echo ERROR $* ; }
|
||||
}
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
|
||||
# create-vm - Quickly create guest VMs using cloud image files and cloud-init.
|
||||
|
||||
# Copyright 2018-2023 Earl C. Ruby III
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
|
||||
# Set BOX_NBD_OVERLAY_DIR environment variable to override default storage location for VMs
|
||||
HOSTNAME=
|
||||
IMG_FQN=
|
||||
AUTH_KEYS_FQN=
|
||||
RAM=2048
|
||||
VCPUS=1
|
||||
STORAGE=20
|
||||
BRIDGE=virbr1
|
||||
MAC='52:54:00:1d:9c:6f'
|
||||
VERBOSE=
|
||||
PASS=
|
||||
OSINFO=gentoo
|
||||
password=ansible
|
||||
OUTDIR=${BOX_NBD_OVERLAY_DIRs:-"${HOME}/vms/virsh"}
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << EOF
|
||||
usage: $0 options
|
||||
|
||||
Quickly create guest VMs using cloud image files and cloud-init.
|
||||
|
||||
OPTIONS:
|
||||
-h Show this message
|
||||
-n Host name (required)
|
||||
-i Full path and name of the base .img file to use (required)
|
||||
-k Full path and name of the ansible user's public key file (required)
|
||||
-d Output directory for the overlay qcow2 and related files
|
||||
-r RAM in MB (defaults to ${RAM})
|
||||
-c Number of VCPUs (defaults to ${VCPUS})
|
||||
-s Amount of storage to allocate in GB (defaults to ${STORAGE})
|
||||
-b Bridge interface to use (defaults to ${BRIDGE})
|
||||
-m MAC address to use (default is to use a randomly-generated MAC)
|
||||
-o OSINFO name like win11, win10, fedora32, gentoo, ububtu20
|
||||
-p ansible users plaintext password
|
||||
-v Verbose
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts "h:n:i:k:r:c:s:b:m:o:p:d:v" option; do
|
||||
case "${option}"
|
||||
in
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
n) HOSTNAME=${OPTARG};;
|
||||
i) IMG_FQN=${OPTARG};;
|
||||
k) AUTH_KEYS_FQN=${OPTARG};;
|
||||
r) RAM=${OPTARG};;
|
||||
c) VCPUS=${OPTARG};;
|
||||
s) STORAGE=${OPTARG};;
|
||||
b) BRIDGE=${OPTARG};;
|
||||
m) MAC=${OPTARG};;
|
||||
p) PASS=${OPTARG};;
|
||||
o) password=${OPTARG};;
|
||||
d) OUTDIR=${OPTARG};
|
||||
BOX_NBD_OVERLAY_DIR=${OUTDIR};;
|
||||
v) VERBOSE=1;;
|
||||
*)
|
||||
ERROR unhandled option "${option}" ${OPTARG}
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z $HOSTNAME ]]; then
|
||||
ERROR "Host name is required"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z $IMG_FQN ]]; then
|
||||
ERROR "Base cloud image file name is required"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z $BOX_NBD_OVERLAY_DIR ]]; then
|
||||
ERROR "Output image directory is required BOX_NBD_OVERLAY_DIR"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z $AUTH_KEYS_FQN ]]; then
|
||||
ERROR "ansible public key file $AUTH_KEYS_FQN not found"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [[ -f $IMG_FQN ]]; then
|
||||
ERROR "$IMG_FQN file not found"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $VERBOSE ]]; then
|
||||
INFO "Building ${HOSTNAME} in $BOX_NBD_OVERLAY_DIR"
|
||||
set -xv
|
||||
fi
|
||||
|
||||
mkdir -p "$BOX_NBD_OVERLAY_DIR"/{images,xml,init,base} || exit 2
|
||||
|
||||
echo "Creating a qcow2 image file ${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img that uses the cloud image file ${IMG_FQN} as its base"
|
||||
|
||||
INFO qemu-img create -b "${IMG_FQN}" -f qcow2 -F qcow2 "${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img" "${STORAGE}G"
|
||||
qemu-img create -b "${IMG_FQN}" -f qcow2 -F qcow2 "${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img" "${STORAGE}G" || exit 3
|
||||
|
||||
echo "Creating meta-data file $BOX_NBD_OVERLAY_DIR/init/meta-data"
|
||||
cat > "$BOX_NBD_OVERLAY_DIR/init/meta-data" << EOF
|
||||
instance-id: ${HOSTNAME}
|
||||
local-hostname: ${HOSTNAME}
|
||||
EOF
|
||||
|
||||
# echo "Creating meta-data file $BOX_NBD_OVERLAY_DIR/init/meta-data.json"
|
||||
# cat > "$BOX_NBD_OVERLAY_DIR/init/meta-data.json" << EOF
|
||||
cat > /dev/null << EOF
|
||||
{
|
||||
"admin_pass": "root",
|
||||
"availability_zone": "nova",
|
||||
"hostname": "test.novalocal",
|
||||
"launch_index": 0,
|
||||
"name": "gentoo6",
|
||||
"meta": {
|
||||
"role": "webservers",
|
||||
"essential": "false"
|
||||
},
|
||||
"public_keys": {
|
||||
"mykey": " ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDRCJCQ1UD9QslWDSw5Pwsvba0Wsf1pO4how5BtNaZn0xLZpTq2nqFEJshUkd/zCWF7DWyhmNphQ8c+U+wcmdNVcg2pI1kPxq0VZzBfZ7cDwhjgeLsIvTXvU+HVRtsXh4c5FlUXpRjf/x+a3vqFRvNsRd1DE+5ZqQHbOVbnsStk3PZppaByMg+AZZMx56OUk2pZCgvpCwj6LIixqwuxNKPxmJf45RyOsPUXwCwkq9UD4me5jksTPPkt3oeUWw1ZSSF8F/141moWsGxSnd5NxCbPUWGoRfYcHc865E70nN4WrZkM7RFI/s5mvQtuj8dRL67JUEwvdvEDO0EBz21FV/iOracXd2omlTUSK+wYrWGtiwQwEgr4r5bimxDKy9L8UlaJZ+ONhLTP8ecTHYkaU1C75sLX9ZYd5YtqjiNGsNF+wdW6WrXrQiWeyrGK7ZwbA7lagSxIa7yeqnKDjdkcJvQXCYGLM9AMBKWeJaOpwqZ+dOunMDLd5VZrDCU2lpCSJ1M="
|
||||
|
||||
},
|
||||
"uuid": "83679162-1378-4288-a2d4-70e13ec132aa"
|
||||
}
|
||||
EOF
|
||||
|
||||
# password=`openssl passwd -1 -stdin <<< $password`
|
||||
echo "Creating user-data file $BOX_NBD_OVERLAY_DIR/init/user-data"
|
||||
# https://techglimpse.com/nova-boot-instance-with-password/
|
||||
cat > "$BOX_NBD_OVERLAY_DIR/init/user-data" << EOF
|
||||
#cloud-config
|
||||
# password: ansible
|
||||
# chpasswd: { expire: False }
|
||||
|
||||
ssh_pwauth: true
|
||||
|
||||
runcmd:
|
||||
- "rc-update add qemu-guest-agent"
|
||||
- "chmod 755 /etc/init.d/qemu-guest-agent"
|
||||
- "/etc/init.d/qemu-guest-agent start"
|
||||
- "echo /etc/init.d/qemu-guest-agent start >> /etc/rc.local"
|
||||
|
||||
users:
|
||||
- default
|
||||
- name: ansible
|
||||
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
|
||||
groups:
|
||||
- wheel
|
||||
- adm
|
||||
shell: /bin/bash
|
||||
plain_text_password: "$password"
|
||||
chpasswd: { expire: False }
|
||||
homedir: /home/ansible
|
||||
ssh_pwauth: true
|
||||
ssh_authorized_keys:
|
||||
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDRCJCQ1UD9QslWDSw5Pwsvba0Wsf1pO4how5BtNaZn0xLZpTq2nqFEJshUkd/zCWF7DWyhmNphQ8c+U+wcmdNVcg2pI1kPxq0VZzBfZ7cDwhjgeLsIvTXvU+HVRtsXh4c5FlUXpRjf/x+a3vqFRvNsRd1DE+5ZqQHbOVbnsStk3PZppaByMg+AZZMx56OUk2pZCgvpCwj6LIixqwuxNKPxmJf45RyOsPUXwCwkq9UD4me5jksTPPkt3oeUWw1ZSSF8F/141moWsGxSnd5NxCbPUWGoRfYcHc865E70nN4WrZkM7RFI/s5mvQtuj8dRL67JUEwvdvEDO0EBz21FV/iOracXd2omlTUSK+wYrWGtiwQwEgr4r5bimxDKy9L8UlaJZ+ONhLTP8ecTHYkaU1C75sLX9ZYd5YtqjiNGsNF+wdW6WrXrQiWeyrGK7ZwbA7lagSxIa7yeqnKDjdkcJvQXCYGLM9AMBKWeJaOpwqZ+dOunMDLd5VZrDCU2lpCSJ1M="
|
||||
EOF
|
||||
|
||||
echo "Adding keys from the public key file $AUTH_KEYS_FQN to the user-data file"
|
||||
while IFS= read -r key; do
|
||||
echo " - $key" >> "$BOX_NBD_OVERLAY_DIR/init/user-data"
|
||||
done < <(grep -v '^ *#' < "$AUTH_KEYS_FQN")
|
||||
|
||||
VM_IMAGE_DIR="$BOX_NBD_OVERLAY_DIR"
|
||||
#old . /usr/local/bin/toxcore_create-ga.sh || exit 4
|
||||
cat > "$BOX_NBD_OVERLAY_DIR/init/user-data" << \EOF
|
||||
#!/bin/bash
|
||||
|
||||
# typically only executes on first boot
|
||||
|
||||
echo "############# user_data executing ##############"
|
||||
|
||||
#grep gentoo /etc/shadow
|
||||
|
||||
sed -e 's/#-:ALL:ALL/+:gentoo:ALL/' -i /etc/security/access.conf
|
||||
PW=`echo $PASS | openssl passwd -1 --stdin `
|
||||
grep -q ^gentoo /etc/passwd || \
|
||||
useradd --gid 4 --uid 1000 --home-dir /home/gentoo \
|
||||
--comment Gentoo --password "$PW" \
|
||||
-G adm,wheel --shell /bin/bash gentoo
|
||||
|
||||
usermod --password "$PW" -G adm,wheel gentoo
|
||||
# root
|
||||
usermod --password '$1$1Ho4y/W8$5VymfKWWAhLxwkkPZiWTZ1' root
|
||||
# unlock account
|
||||
passwd -u gentoo
|
||||
passwd -u root
|
||||
|
||||
sed -e 's/# %wheel /%wheel /' -i /etc/sudoers
|
||||
sed -e 's/PasswordAuthentication no/PasswordAuthentication yes/' -i /etc//ssh/sshd_config
|
||||
sed -e 's/PermitRootLogin.*/PermitRootLogin yes/' -i /etc//ssh/sshd_config
|
||||
|
||||
grep net.ipv4.ip_forward=1 /etc/sysctl.conf || \
|
||||
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
|
||||
|
||||
cd /etc/init.d
|
||||
[ -e net.eth0 ] || ln -s net.lo net.eth0
|
||||
|
||||
for elt in i o linuxPen19 ; do
|
||||
grep -q $elt /etc/fstab && continue
|
||||
echo "$elt /mnt/$elt virtiofs defaults 0 0" >> /etc/fstab
|
||||
done
|
||||
|
||||
#grep gentoo /etc/shadow
|
||||
EOF
|
||||
|
||||
echo "Generating the cidata ISO file $BOX_NBD_OVERLAY_DIR/images/${HOSTNAME}-cidata.iso"
|
||||
(
|
||||
cd "$BOX_NBD_OVERLAY_DIR/init/"
|
||||
genisoimage \
|
||||
-output "$BOX_NBD_OVERLAY_DIR/images/${HOSTNAME}-cidata.img" \
|
||||
-volid cidata \
|
||||
-rational-rock \
|
||||
-joliet \
|
||||
-input-charset utf-8 \
|
||||
user-data meta-data
|
||||
) || exit 5
|
||||
|
||||
MACCMD=
|
||||
if [[ -n $MAC ]]; then
|
||||
MACCMD="--mac=${MAC}"
|
||||
fi
|
||||
|
||||
[ -f ${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img ] || exit 5
|
||||
[ -f $BOX_NBD_OVERLAY_DIR/images/${HOSTNAME}-cidata.img ] || exit 6
|
||||
|
||||
# libvirt.libvirtError: /usr/lib/qemu/qemu-bridge-helper --use-vnet --br=-c --fd=31: failed to communicate with bridge helper: stderr=failed to parse default acl file `/etc/qemu/bridge.conf'
|
||||
if [ ! -f "/etc/qemu/bridge.conf" ] ; then
|
||||
echo allow $BRIDGE >> "/etc/qemu/bridge.conf"
|
||||
elif ! grep $BRIDGE "/etc/qemu/bridge.conf" ; then
|
||||
echo allow $BRIDGE >> "/etc/qemu/bridge.conf"
|
||||
fi
|
||||
if [ $BRIDGE = virbr0 ] ; then
|
||||
network=default
|
||||
# 192.168.122.248/24
|
||||
elif [ $BRIDGE = virbr1 ] ; then
|
||||
network=Whonix-External
|
||||
else
|
||||
WARN unrecognized $BRIDGE
|
||||
fi
|
||||
if [ "$network" != '' ] ; then
|
||||
virsh net-list | grep -q $network || \
|
||||
virsh net-start $network
|
||||
fi
|
||||
sudo ifconfig -a | grep $BRIDGE && \
|
||||
NETWORK="--network bridge=${BRIDGE},model=virtio" || \
|
||||
WARN bridge $BRIDGE not running. not adding a network
|
||||
NETWORK="--network network=default,model=virtio"
|
||||
|
||||
INFO virt-install \
|
||||
--name="${HOSTNAME}" \
|
||||
--osinfo "$OSINFO" \
|
||||
--import \
|
||||
--name="${HOSTNAME}" \
|
||||
--disk "path=${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img,format=qcow2" \
|
||||
--disk "path=$BOX_NBD_OVERLAY_DIR/images/${HOSTNAME}-cidata.img,device=cdrom" \
|
||||
--ram="${RAM}" \
|
||||
--vcpus="${VCPUS}" \
|
||||
--autostart \
|
||||
--hvm \
|
||||
--arch x86_64 \
|
||||
--accelerate \
|
||||
--check-cpu \
|
||||
--force \
|
||||
--watchdog=default \
|
||||
--graphics spice,listen=socket \
|
||||
--channel spicevmc,target.type=virtio,target.name=com.redhat.spice.0 \
|
||||
--channel type=unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
|
||||
--network "bridge=${BRIDGE},model=virtio" \
|
||||
--rng /dev/urandom \
|
||||
--os-variant detect=on,name=$OSINFO \
|
||||
--noautoconsole
|
||||
|
||||
# squelch warnings
|
||||
python3.sh `which virt-install` \
|
||||
--name="${HOSTNAME}" \
|
||||
--osinfo "$OSINFO" \
|
||||
--import \
|
||||
--disk "path=${BOX_NBD_OVERLAY_DIR}/images/${HOSTNAME}.img,format=qcow2" \
|
||||
--disk "path=$BOX_NBD_OVERLAY_DIR/images/${HOSTNAME}-cidata.img,device=cdrom" \
|
||||
--ram="${RAM}" \
|
||||
--vcpus="${VCPUS}" \
|
||||
--autostart \
|
||||
--hvm \
|
||||
--arch x86_64 \
|
||||
--accelerate \
|
||||
--check-cpu \
|
||||
--force \
|
||||
--watchdog=default \
|
||||
--graphics spice,listen=socket \
|
||||
--filesystem /,/mnt/linuxPen19 \
|
||||
--channel spicevmc,target.type=virtio,target.name=com.redhat.spice.0 \
|
||||
--channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
|
||||
$NETWORK \
|
||||
--rng /dev/urandom \
|
||||
--os-variant detect=on,name=$OSINFO \
|
||||
--noautoconsole \
|
||||
|| exit 7
|
||||
# --debug
|
||||
#? --shmem name=shmem_server,type="memfd",mode="shared"
|
||||
# --shmem name=shmem0 ivshmem device is not supported with this QEMU binary
|
||||
|
||||
# was --graphics vnc,listen=0.0.0.0
|
||||
# --osinfo "$OSINFO" \
|
||||
|
||||
# Make a backup of the VM's XML definition file
|
||||
virsh dumpxml "${HOSTNAME}" > "${BOX_NBD_OVERLAY_DIR}/xml/${HOSTNAME}.xml" || exit 8
|
||||
INFO wrote xml `ls -l ${BOX_NBD_OVERLAY_DIR}/xml/${HOSTNAME}.xml`
|
||||
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
set +xv
|
||||
fi
|
||||
|
||||
# problems: type=qemu-vdagent unix unix=on
|
||||
# problems: type="spicevmc
|
||||
# ERROR Unknown --channel options: ['unix']
|
||||
cp "${BOX_NBD_OVERLAY_DIR}/xml/${HOSTNAME}.xml" \
|
||||
"${BOX_NBD_OVERLAY_DIR}/xml/${HOSTNAME}.xml".new
|
||||
|
||||
cat > /tmp/ga.works <<EOF
|
||||
<channel type="unix">
|
||||
<source mode="bind" path="/var/lib/libvirt/qemu/channel/target/domain-25-gentoo1/org.qemu.guest_agent.0"/>
|
||||
<target type="virtio" name="org.qemu.guest_agent.0" state="connected"/>
|
||||
<address type="virtio-serial" controller="0" bus="0" port="2"/>
|
||||
</channel>
|
||||
EOF
|
||||
cat > /tmp/sp.works <<EOF
|
||||
<channel type="spicevmc">
|
||||
<target type="virtio" name="com.redhat.spice.0" state="disconnected"/>
|
||||
<address type="virtio-serial" controller="0" bus="0" port="1"/>
|
||||
</channel>
|
||||
EOF
|
||||
|
||||
# Show running VMs
|
||||
virsh list | grep "${HOSTNAME}" && INFO "${HOSTNAME}" || { ERROR "${HOSTNAME}" ; exit 9$? ; }
|
||||
|
||||
# use the following passwordless demonstration key for testing or
|
||||
# replace with your own key pair
|
||||
#
|
||||
# -----BEGIN OPENSSH PRIVATE KEY-----
|
||||
# b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
|
||||
# NhAAAAAwEAAQAAAYEA0QiQkNVA/ULJVg0sOT8LL22tFrH9aTuIaMOQbTWmZ9MS2aU6tp6h
|
||||
# RCbIVJHf8wlhew1soZjaYUPHPlPsHJnTVXINqSNZD8atFWcwX2e3A8IY4Hi7CL0171Ph1U
|
||||
# bbF4eHORZVF6UY3/8fmt76hUbzbEXdQxPuWakB2zlW57ErZNz2aaWgcjIPgGWTMeejlJNq
|
||||
# WQoL6QsI+iyIsasLsTSj8ZiX+OUcjrD1F8AsJKvVA+JnuY5LEzz5Ld6HlFsNWUkhfBf9eN
|
||||
# ZqFrBsUp3eTcQmz1FhqEX2HB3POuRO9JzeFq2ZDO0RSP7OZr0Lbo/HUS+uyVBML3bxAztB
|
||||
# Ac9tRVf4jq2nF3dqJpU1EivsGK1hrYsEMBIK+K+W4psQysvS/FJWiWfjjYS0z/HnEx2JGl
|
||||
# NQu+bC1/WWHeWLao4jRrDRfsHVulq160Ilnsqxiu2cGwO5WoEsSGu8nqpyg43ZHCb0FwmB
|
||||
# izPQDASlniWjqcKmfnTrpzAy3eVWawwlNpaQkidTAAAFgGKSj8diko/HAAAAB3NzaC1yc2
|
||||
# EAAAGBANEIkJDVQP1CyVYNLDk/Cy9trRax/Wk7iGjDkG01pmfTEtmlOraeoUQmyFSR3/MJ
|
||||
# YXsNbKGY2mFDxz5T7ByZ01VyDakjWQ/GrRVnMF9ntwPCGOB4uwi9Ne9T4dVG2xeHhzkWVR
|
||||
# elGN//H5re+oVG82xF3UMT7lmpAds5VuexK2Tc9mmloHIyD4BlkzHno5STalkKC+kLCPos
|
||||
# iLGrC7E0o/GYl/jlHI6w9RfALCSr1QPiZ7mOSxM8+S3eh5RbDVlJIXwX/XjWahawbFKd3k
|
||||
# 3EJs9RYahF9hwdzzrkTvSc3hatmQztEUj+zma9C26Px1EvrslQTC928QM7QQHPbUVX+I6t
|
||||
# pxd3aiaVNRIr7BitYa2LBDASCvivluKbEMrL0vxSVoln442EtM/x5xMdiRpTULvmwtf1lh
|
||||
# 3li2qOI0aw0X7B1bpatetCJZ7KsYrtnBsDuVqBLEhrvJ6qcoON2Rwm9BcJgYsz0AwEpZ4l
|
||||
# o6nCpn5066cwMt3lVmsMJTaWkJInUwAAAAMBAAEAAAGAEuz77Hu9EEZyujLOdTnAW9afRv
|
||||
# XDOZA6pS7yWEufjw5CSlMLwisR83yww09t1QWyvhRqEyYmvOBecsXgaSUtnYfftWz44apy
|
||||
# /gQYvMVELGKaJAC/q7vjMpGyrxUPkyLMhckALU2KYgV+/rj/j6pBMeVlchmk3pikYrffUX
|
||||
# JDY990WVO194Dm0buLRzJvfMKYF2BcfF4TvarjOXWAxSuR8www050oJ8HdKahW7Cm5S0po
|
||||
# FRnNXFGMnLA62vN00vJW8V7j7vui9ukBbhjRWaJuY5rdG/UYmzAe4wvdIEnpk9xIn6JGCp
|
||||
# FRYTRn7lTh5+/QlQ6FXRP8Ir1vXZFnhKzl0K8Vqh2sf4M79MsIUGAqGxg9xdhjIa5dmgp8
|
||||
# N18IEDoNEVKUbKuKe/Z5yf8Z9tmexfH1YttjmXMOojBvUHIjRS5hdI9NxnPGRLY2kjAzcm
|
||||
# gV9Rv3vtdF/+zalk3fAVLeK8hXK+di/7XTvYpfJ2EZBWiNrTeagfNNGiYydsQy3zjZAAAA
|
||||
# wBNRak7UrqnIHMZn7pkCTgceb1MfByaFtlNzd+Obah54HYIQj5WdZTBAITReMZNt9S5NAR
|
||||
# M8sQB8UoZPaVSC3ppILIOfLhs6KYj6RrGdiYwyIhMPJ5kRWF8xGCLUX5CjwH2EOq7XhIWt
|
||||
# MwEFtd/gF2Du7HUNFPsZGnzJ3e7pDKDnE7w2khZ8CIpTFgD769uBYGAtk45QYTDo5JroVM
|
||||
# ZPDq08Gb/RhIgJLmIpMwyreVpLLLe8SwoMJJ+rihmnJZxO8gAAAMEA0lhiKezeTshht4xu
|
||||
# rWc0NxxD84a29gSGfTphDPOrlKSEYbkSXhjqCsAZHd8S8kMr3iF6poOk3IWSvFJ6mbd3ie
|
||||
# qdRTgXH9Thwk4KgpjUhNsQuYRHBbI59Mo+BxSI1B1qzmJSGdmCBL54wwzZmFKDQPQKPxiL
|
||||
# n0Mlc7GooiDMjT1tbuW/O1EL5EqTRqwgWPTKhBA6r4PnGF150hZRIMooZkD2zX6b1sGojk
|
||||
# QpvKkEykTwnKCzF5TXO8+wJ3qbcEo9AAAAwQD+Z0r68c2YMNpsmyj3ZKtZNPSvJNcLmyD/
|
||||
# lWoNJq3djJN4s2JbK8l5ARUdW3xSFEDI9yx/wpfsXoaqWnygP3PoFw2CM4i0EiJiyvrLFU
|
||||
# r3JLfDUFRy3EJ24RsqbigmEsgQOzTl3xfzeFPfxFoOhokSvTG88PQji1AYHz5kA7p6Zfaz
|
||||
# Ok11rJYIe7+e9B0lhku0AFwGyqlWQmS/MhIpnjHIk5tP4heHGSmzKQWJDbTskNWd6aq1G7
|
||||
# 6HWfDpX4HgoM8AAAALaG9sbWFuYkBhcmM=
|
||||
# -----END OPENSSH PRIVATE KEY-----
|
||||
#
|
80
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_daily.bash
Normal file
80
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_daily.bash
Normal file
@ -0,0 +1,80 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
|
||||
# The idea here is to run ansible_local.bash --tags daily
|
||||
# and then use this to do the parsing and throwing errors based on the output.
|
||||
# This way the ansible run can be free from erroring and this can be
|
||||
# run repeatedly anytime outside of ansible to deal with the issues raised.
|
||||
# It is also run at the end of ansible_local.bash --tags daily to raise the issues.
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
. /usr/locaal/etc/testforge/testforge.bash
|
||||
TOXCORE_LOG_DIR=$PREFIX/var/log
|
||||
[ -d $TOXCORE_LOG_DIR ] || mkdir -p $TOXCORE_LOG_DIR
|
||||
|
||||
MYID=`id -u`
|
||||
[ $MYID -eq 0 ] || WARN $prog should be run as root $MYID
|
||||
|
||||
which ansifilter >/dev/null 2>&1 && ansifilter=ansifilter || ansifilter=cat
|
||||
|
||||
ly=daily
|
||||
i=0
|
||||
errs=0
|
||||
warns=0
|
||||
WLOG="$TOXCORE_LOG_DIR"/$ly/W$prog$$.log
|
||||
ELOG="$TOXCORE_LOG_DIR"/$ly/E$prog$$.log
|
||||
|
||||
#?ols_make_testforge_logs $TOXCORE_LOG_DIR
|
||||
|
||||
find "$TOXCORE_LOG_DIR"/$ly/ -type f -name W${prog}*.log -o -name E${prog}*.log -mtime +1 -delete
|
||||
|
||||
|
||||
if virsh list | grep -q Whonix-Gateway ; then
|
||||
/usr/local/bin/toxcore_libvirt_test_ga.bash
|
||||
fi
|
||||
|
||||
# -%d
|
||||
if ls /var/log/libvirt/qemu/*.log 2>/dev/null ; then
|
||||
sudo grep ^`date +%Y-%m`.*warning /var/log/libvirt/qemu/*.log | tee -a $WLOG
|
||||
fi
|
||||
|
||||
# FixMe missing
|
||||
[ -x $PREFIX/bin/toxcore_libvirt_test_xml.bash ] && \
|
||||
$PREFIX/bin/toxcore_libvirt_test_xml.bash 2>&1 | grep WARN: >> $WLOG
|
||||
|
||||
if which virt-host-validate 2>/dev/null ; then
|
||||
[ -f $TOXCORE_LOG_DIR/daily/virt-host-validate.log ] || \
|
||||
sudo virt-host-validate > $TOXCORE_LOG_DIR/daily/virt-host-validate.log 2>&1
|
||||
b=`grep FAIL $TOXCORE_LOG_DIR/daily/virt-host-validate.log|wc -l|sed -e 's/ .*//'`
|
||||
[ $? -eq 0 -a -n "$b" -a $b -gt 0 ]
|
||||
b=`grep WARN $TOXCORE_LOG_DIR/daily/virt-host-validate.log|wc -l|sed -e 's/ .*//'`
|
||||
[ $? -eq 0 -a -n "$b" -a $b -gt 0 ] && \
|
||||
WARN $b WARN in $TOXCORE_LOG_DIR/$ly/virt-host-validate.log $warns | tee -a $WLOG
|
||||
fi
|
||||
|
||||
if /etc/init.d/libvirtd status ; then
|
||||
virsh list | grep '^ [0-9]' | while read id elt rest ; do
|
||||
[ $rest = running ] || continue
|
||||
virsh dumpxml $elt | grep org.qemu.guest_agent.0.*connected || \
|
||||
WARN org.qemu.guest_agent not connected for $elt |tee -a $WLOG
|
||||
# <target type='virtio' name='com.redhat.spice.0' state='connected'/>
|
||||
# <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
|
||||
done
|
||||
fi
|
||||
|
||||
warns=`grep -c WARN: "$WLOG"`
|
||||
[ $warns -ne 0 ] && \
|
||||
WARN "$prog $ly $warns warnings in $WLOG"
|
||||
|
||||
errs=`grep -c ERROR: "$ELOG"`
|
||||
[ $errs -ne 0 ] && \
|
||||
ERROR "$prog $ly $errs errors in $ELOG" && \
|
||||
exit -$errs
|
||||
|
||||
[ $warns -eq 0 -a $errs -eq 0 ] && \
|
||||
ols_clean_testforge_logs $TOXCORE_LOG_DIR && \
|
||||
INFO "No $ly errors in $TOXCORE_LOG_DIR"
|
||||
|
||||
exit 0
|
61
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_delete-vm.bash
Executable file
61
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_delete-vm.bash
Executable file
@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
# from https://github.com/earlruby/create-vm/
|
||||
|
||||
[ -f /usr/local/bin/usr_local_tput.bash ] && \
|
||||
. /usr/local/bin/usr_local_tput.bash || {
|
||||
DBUG() { echo DEBUG $* ; }
|
||||
INFO() { echo INFO $* ; }
|
||||
WARN() { echo WARN $* ; }
|
||||
ERROR() { echo ERROR $* ; }
|
||||
}
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
|
||||
# delete-vm - Delete a virtual machine created with create-vm
|
||||
|
||||
# Copyright 2018-2023 Earl C. Ruby III
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
VM=$1
|
||||
|
||||
# Set VM_IMAGE_DIR environment variable to override default storage location for VMs
|
||||
VM_IMAGE_DIR=${VM_IMAGE_DIR:-"${HOME}/vms/virsh"}
|
||||
|
||||
VM_IMAGE="${VM_IMAGE_DIR}/images/$VM.img"
|
||||
CI_IMAGE="${VM_IMAGE_DIR}/images/$VM-cidata.img"
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << EOF
|
||||
usage: $0 vmname
|
||||
EOF
|
||||
}
|
||||
|
||||
if [[ -z $VM ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -e $VM_IMAGE ]]; then
|
||||
# VM exists
|
||||
virsh destroy "$VM"
|
||||
virsh undefine "$VM"
|
||||
rm -fv "$VM_IMAGE" "$CI_IMAGE"
|
||||
else
|
||||
echo "Cannot find an VM image file named '$VM_IMAGE'. Attempting undefine..."
|
||||
virsh undefine "$VM"
|
||||
fi
|
55
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_get-vm-ip.bash
Executable file
55
roles/toxcore/overlay/Linux/usr/local/bin/toxcore_get-vm-ip.bash
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
# from https://github.com/earlruby/create-vm/
|
||||
|
||||
[ -f /usr/local/bin/usr_local_tput.bash ] && \
|
||||
. /usr/local/bin/usr_local_tput.bash || {
|
||||
DBUG() { echo DEBUG $* ; }
|
||||
INFO() { echo INFO $* ; }
|
||||
WARN() { echo WARN $* ; }
|
||||
ERROR() { echo ERROR $* ; }
|
||||
}
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
|
||||
. /usr/local/etc/testforge/testforge.bash
|
||||
[ -n "$HOSTVMS_VAR_LOCAL" ] && PREFIX=$HOSTVMS_VAR_LOCAL
|
||||
|
||||
# get-node-ip - Get the IP address of a VM managed by virsh.
|
||||
|
||||
# Copyright 2018-2023 Earl C. Ruby III
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << EOF
|
||||
usage: $0 hostname
|
||||
|
||||
This script will take a virsh-managed VM hostname and return the IP address.
|
||||
EOF
|
||||
}
|
||||
|
||||
HOSTNAME=$1
|
||||
|
||||
if [[ -z $HOSTNAME ]]; then
|
||||
echo "ERROR: Hostname is required"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
|
||||
arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'
|
||||
INFO MAC=$MAC arp=$arp
|
@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
|
||||
|
||||
# The idea here is to run ansible_local.bash --tags daily
|
||||
# and then use this to do the parsing and throwing errors based on the output.
|
||||
# This way the ansible run can be free from erroring and this can be
|
||||
# run repeatedly anytime outside of ansible to deal with the issues raised.
|
||||
# It is also run at the end of ansible_local.bash --tags daily to raise the issues.
|
||||
|
||||
prog=`basename $0 .bash`
|
||||
PREFIX=/usr/local
|
||||
ROLE=toxcore
|
||||
. /usr/locaal/etc/testforge/testforge.bash
|
||||
TOXCORE_LOG_DIR=$PREFIX/var/log
|
||||
[ -d $TOXCORE_LOG_DIR ] || mkdir -p $TOXCORE_LOG_DIR
|
||||
|
||||
MYID=`id -u`
|
||||
[ $MYID -eq 0 ] || WARN $prog should be run as root $MYID
|
||||
|
||||
which ansifilter >/dev/null 2>&1 && ansifilter=ansifilter || ansifilter=cat
|
||||
|
||||
ly=hourly
|
||||
i=0
|
||||
errs=0
|
||||
warns=0
|
||||
WLOG="$TOXCORE_LOG_DIR"/$ly/W$prog$$.log
|
||||
ELOG="$TOXCORE_LOG_DIR"/$ly/E$prog$$.log
|
||||
|
||||
#?ols_make_testforge_logs $TOXCORE_LOG_DIR
|
||||
|
||||
find "$TOXCORE_LOG_DIR"/$ly/ -type f -name W${prog}*.log -o -name E${prog}*.log -mtime +1 -delete
|
||||
|
||||
if virsh list | grep -q Whonix-Gateway ; then
|
||||
/usr/local/bin/toxcore_libvirt_test_ga.bash
|
||||
fi
|
||||
|
||||
# -%d
|
||||
if ls /var/log/libvirt/qemu/*.log 2>/dev/null ; then
|
||||
sudo grep ^`date +%Y-%m`.*warning /var/log/libvirt/qemu/*.log | tee -a $WLOG
|
||||
fi
|
||||
|
||||
|
||||
warns=`grep -c WARN: "$WLOG"`
|
||||
[ $warns -ne 0 ] && \
|
||||
WARN "$prog $ly $warns warnings in $WLOG"
|
||||
|
||||
errs=`grep -c ERROR: "$ELOG"`
|
||||
[ $errs -ne 0 ] && \
|
||||
ERROR "$prog $ly $errs errors in $ELOG" && \
|
||||
exit -$errs
|
||||
|
||||
[ $warns -eq 0 -a $errs -eq 0 ] && \
|
||||
ols_clean_testforge_logs $TOXCORE_LOG_DIR && \
|
||||
INFO "No $ly errors in $TOXCORE_LOG_DIR"
|
||||
|
||||
exit 0
|
@ -0,0 +1,372 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQINBFsL/o0BEADHYSlmnvx5qLBWjXKQRfo564sj94AQMiDHr52vtPlcaeOal8a3
|
||||