]> git.madduck.net Git - code/vinst.git/blob - vinst

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

set default storage pool name
[code/vinst.git] / vinst
1 #!/bin/sh
2
3 set -e
4
5 # defaults
6 RAM=512
7 DISK=20
8 STORAGE_POOL=default
9 QEMU_URI=qemu:///system
10 SUITE=wheezy
11 CONSOLE='console=tty0 console=ttyS0,115200n8'
12
13 while [ -n "$1" ]; do
14   case "$1" in
15     (-n|--name)
16       shift
17       if [ -z "$1" ]; then
18         echo >&2 'E: --name/-n needs hostname argument'
19         exit 1
20       fi
21       HOSTNAME="$1"
22       ;;
23     (-i|--ipaddress)
24       shift
25       if [ -z "$1" ]; then
26         echo >&2 'E: --ipaddress/-i needs IP address/netmask'
27         exit 1
28       fi
29       case "$1" in
30         (*/*) :;;
31         (*)
32           echo >&2 'E: missing netmask'
33           exit 1
34           ;;
35       esac
36       IPADDRESS="$1"
37       ;;
38     (-r|--ram)
39       shift
40       if [ -z "$1" ]; then
41         echo >&2 'E: --ram/-r needs number (megabytes)'
42         exit 1
43       fi
44       RAM="$1"
45       ;;
46     (-s|--size)
47       shift
48       if [ -z "$1" ]; then
49         echo >&2 'E: --size/-s needs size argument'
50         exit 1
51       fi
52       DISK="$1"
53       ;;
54   esac
55   shift
56 done
57
58 if [ -z "${HOSTNAME:-}" ]; then
59   echo >&2 'E: hostname is required'
60   exit 2
61 fi
62
63 BASEDIR=$(cd ${0%/*}; pwd)
64
65 tmpdir=$(mktemp -d)
66 tar -C $BASEDIR/preseed/$SUITE -cf $tmpdir/commands.tar commands
67
68 extra_args="auto $CONSOLE \
69 hostname=${HOSTNAME%%.*} \
70 domain=${HOSTNAME#*.}"
71
72 if [ -n "$IPADDRESS" ]; then
73   if [ -z "$GATEWAY" ]; then
74     # default to the first IP in the network
75     GATEWAY=$(ipcalc $IPADDRESS | grep HostMin | awk '{print $2}')
76   fi
77   NETMASK="${IPADDRESS#*/}"
78   IPADDRESS="${IPADDRESS%/*}"
79   : ${NAMESERVER:=$GATEWAY}
80
81   extra_args="$extra_args netcfg/disable_dhcp=true \
82   netcfg/get_ipaddress=$IPADDRESS \
83   netcfg/get_netmask=$NETMASK \
84   netcfg/get_gateway=$GATEWAY \
85   netcfg/get_nameservers=$NAMESERVER"
86
87 else
88   extra_args="$extra_args netcfg/disable_dhcp=false"
89 fi
90
91 cat >&2 <<_eof
92   hostname: $HOSTNAME
93        ram: $RAM MiB
94       disk: $DISK GiB
95    console: $CONSOLE
96 _eof
97 if [ -n "$IPADDRESS" ]; then
98   cat >&2 <<_eof
99  ipaddress: $IPADDRESS
100    netmask: $NETMASK
101    gateway: $GATEWAY
102 nameserver: $NAMESERVER
103 _eof
104 else
105   cat >&2 <<_eof
106       dhcp: true
107 _eof
108 fi
109
110 exit 0
111
112 exec virt-install --connect=$QEMU_URI \
113   -n $HOSTNAME \
114   -r $RAM \
115   --disk pool=default,size=$SIZE \
116   -w bridge=virt-br \
117   --graphics=vnc \
118   --serial=pty \
119   --watchdog i6300esb,action=reset \
120   --os-variant=debian$SUITE \
121   -l $BASEDIR/installer-amd64 \
122   --initrd-inject=$BASEDIR/preseed/$SUITE/preseed.cfg \
123   --initrd-inject=$tmpdir/commands.tar \
124   --extra-args="$extra_args" \
125   --autostart \
126   "$@"