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

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