]> 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:

66b70aa087442fa7e2ee48c5f112e964f77bcdb7
[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     (-g|--gateway)
39       shift
40       if [ -z "$1" ]; then
41         echo >&2 'E: --gateway/-g needs IP address'
42         exit 1
43       fi
44       GATEWAY="$1"
45       ;;
46     (-r|--ram)
47       shift
48       if [ -z "$1" ]; then
49         echo >&2 'E: --ram/-r needs number (megabytes)'
50         exit 1
51       fi
52       RAM="$1"
53       ;;
54     (-s|--size)
55       shift
56       if [ -z "$1" ]; then
57         echo >&2 'E: --size/-s needs size argument'
58         exit 1
59       fi
60       DISK="$1"
61       ;;
62   esac
63   shift
64 done
65
66 if [ -z "${HOSTNAME:-}" ]; then
67   echo >&2 'E: hostname is required'
68   exit 2
69 fi
70
71 BASEDIR=$(cd ${0%/*}; pwd)
72
73 tmpdir=$(mktemp -d)
74 tar -C $BASEDIR/preseed/$SUITE -cf $tmpdir/commands.tar commands
75
76 extra_args="auto $CONSOLE \
77 hostname=${HOSTNAME%%.*} \
78 domain=${HOSTNAME#*.}"
79
80 if [ -n "$IPADDRESS" ]; then
81   if [ -z "$GATEWAY" ] && [ -x $(command -v ipcalc) ]; then
82     # default to the first IP in the network
83     GATEWAY=$(ipcalc $IPADDRESS | grep HostMin | awk '{print $2}')
84   fi
85   NETMASK="${IPADDRESS#*/}"
86   IPADDRESS="${IPADDRESS%/*}"
87   : ${NAMESERVER:=$GATEWAY}
88
89   extra_args="$extra_args netcfg/disable_dhcp=true \
90   netcfg/get_ipaddress=$IPADDRESS \
91   netcfg/get_netmask=$NETMASK \
92   netcfg/get_gateway=$GATEWAY \
93   netcfg/get_nameservers=$NAMESERVER"
94
95 else
96   extra_args="$extra_args netcfg/disable_dhcp=false"
97 fi
98
99 cat >&2 <<_eof
100   hostname: $HOSTNAME
101        ram: $RAM MiB
102       disk: $DISK GiB
103    console: $CONSOLE
104 _eof
105 if [ -n "$IPADDRESS" ]; then
106   cat >&2 <<_eof
107  ipaddress: $IPADDRESS
108    netmask: $NETMASK
109    gateway: $GATEWAY
110 nameserver: $NAMESERVER
111 _eof
112 else
113   cat >&2 <<_eof
114       dhcp: true
115 _eof
116 fi
117
118 exit 0
119
120 exec virt-install --connect=$QEMU_URI \
121   -n $HOSTNAME \
122   -r $RAM \
123   --disk pool=default,size=$SIZE \
124   -w bridge=virt-br \
125   --graphics=vnc \
126   --serial=pty \
127   --watchdog i6300esb,action=reset \
128   --os-variant=debian$SUITE \
129   -l $BASEDIR/installer-amd64 \
130   --initrd-inject=$BASEDIR/preseed/$SUITE/preseed.cfg \
131   --initrd-inject=$tmpdir/commands.tar \
132   --extra-args="$extra_args" \
133   --autostart \
134   "$@"