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

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