dot

packages and services management
Log | Files | Refs | README

commit e69762b937d56b3be90db069af3648de4dd4392d
parent 057f077c57fab7b8f27916706767f21e43265026
Author: Josuah Demangeon <mail@josuah.net>
Date:   Wed,  7 Feb 2018 23:21:04 +0100

[add] qemu-*: handle vm creation and start

Diffstat:
Abin/qemu | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/xdg-open | 8+-------
Mdot/profile | 1+
Mtinc/tinc-up | 2+-
4 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/bin/qemu b/bin/qemu @@ -0,0 +1,50 @@ +#!/bin/sh -e + +mkdir -p "${LOG}/qemu" + +case "${1}" in +(new) + [ "${#}" -ne 3 ] || ! [ -r "${LIB}/qemu/${3}" ] || + exec "${0}" + + cp "${LIB}/qemu/${3}" "${VAR}/qemu/${2}.img" + + exec "${0}" start "${VAR}/qemu/${1}.img" + ;; +(start) + [ "${#}" -ne 3 ] || ! [ -r "${LIB}/qemu/${2}" ] || + exec "${0}" + + beg='10000' + end='10100' + + port="$(netstat -natl | awk -v b="${beg}" -v e="${end}" \ + '$6 == "LISTEN" && sub(".*\\.", "", $4) && b <= $4 + 0 && $4 + 0 <= e { + print($4); + }' | sort -ru | sed q)" + port="${port:+$((${port} + 1))}" + port="${port:-${beg}}" + + exec nohup qemu-system-x86_64 \ + -m 500M \ + -device e1000,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::${port}-:22 \ + -display none \ + "${VAR}/qemu/${2}" \ + 1>> "${LOG}/qemu/${2}" & + ;; +(*) + echo 'usage: qemu start <name.img>' 1>&2 + echo ' qemu new <ref.img> <new.img>' 1>&2 + + echo 'store:' 1>&2 + ls "${LIB}/qemu" | sed 's/^/ /' 1>&2 + + echo 'created:' 1>&2 + ls "${VAR}/qemu" | sed 's/^/ /' 1>&2 + + echo 'running:' 1>&2 + pgrep -lf 'qemu-system-.*hostfwd=tcp::' | + sed -r 's|.*hostfwd=tcp::([0-9]+).*/(.+)$| \1 \2|' + ;; +esac diff --git a/bin/xdg-open b/bin/xdg-open @@ -182,13 +182,7 @@ esac exec transmission-cli "${1}" ;; (*.img|*.iso) - exec nohup qemu-system-x86_64 \ - -m 500M \ - -device e1000,netdev=net0 \ - -netdev user,id=net0,hostfwd=tcp::5555-:22 \ - -display none \ - "${1}" \ - >> "${LOG}/qemu" + exec qemu-start "${1}" ;; #--- media --------------------------------------------------------------------- (*.pdf) diff --git a/dot/profile b/dot/profile @@ -20,6 +20,7 @@ export RUN="${HOME}/.cache/run" export LOG="${HOME}/.cache/log" export ETC="${HOME}/.config" export SYS="${HOME}/.local" +export LIB="${HOME}/lib" export MAIL="${VAR}/mail/mbox" diff --git a/tinc/tinc-up b/tinc/tinc-up @@ -6,6 +6,6 @@ case "$(uname)" in ;; (Linux) ip link set "${INTERFACE}" up - ip addr add "${SUBNET}/24 dev "${INTERFACE}" + ip addr add "${SUBNET}/24" dev "${INTERFACE}" ;; esac