~free.ekanayaka/landscape-client/karmic-1.5.4-0ubuntu0.9.10.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/sh -e

help () {
    cat <<EOF
$0 [OPTION] ... <release>: build a landscape-client VM for the specified release

Available options:

  -m, --mirror <mirror>      The Ubuntu mirror to use to build the VM, and
                             for the APT sources inside the VM itself.

                             If you want to use apt-proxy, you have to modify the
                             apt-proxy-v2.conf file to make apt-proxy listen to
                             your actual network interface address, instead of
                             the loopback one. For example:

                             ;; Server IP to listen on
                             address = 192.168.1.162

  -s, --server <host>        The hostname of the Landscape server the client
                             should connect to.

  -a, --account <account>    The name of the Landscape account to use.

  -p, --password <password>  The password for the Landscape account.

  -P, --profile <profile>    Package profile to use, can be server or desktop.

  -k, --ssl-key <key>        Specify an SSL key to be used in the client config.

For example, this script can be invoked like this:

./dev/landscape-client-vm --password <LANDSCAPE_DEVEL_ACCOUNT_PW> intrepid

where <LANDSCAPE_DEVEL_ACCOUNT_PW> is the account password of the landscape-devel
account on the Landscape staging server (or you can specify another account with
the --account parameter).

The built VM will be stored under ./build/intrepid along with some other
files. To launch the VM, cd to ./build/intrepid and issue:

./run

Once it's booted you can log into it with:

./ssh

EOF
}

OPTS=$(getopt -o hm:s:a:p:P:k: --long help,mirror:,server:,account:,password:,profile:,ssl-key: -- "$@")

if [ $? != 0 ]; then
    exit 1
fi

eval set -- "$OPTS"

MIRROR=http://archive.ubuntu.com/ubuntu
SERVER=staging.landscape.canonical.com
ACCOUNT=landscape-devel
PASSWORD=
PROFILE=server
SSL_KEY=

while true ; do
    case "$1" in
	-h|--help) help; exit 1; shift ;;
	-m|--mirror) MIRROR=$2; shift 2 ;;
	-s|--server) SERVER=$2; shift 2;;
	-a|--account) ACCOUNT=$2; shift 2;;
	-p|--password) PASSWORD=$2; shift 2;;
	-P|--profile) PROFILE=$2; shift 2;;
	-S|--ssl-key) SSL_KEY=$2; shift 2;;
	--) shift ; break ;;
	*) echo "Internal error!" ; exit 1 ;;
    esac
done

if [ "$1" = "" ]; then
    help
    exit
fi

RELEASE=$1
TOPDIR=$(pwd)/build/${RELEASE}-${PROFILE}
SSH_KEY=$TOPDIR/ssh_key
SSH_PORT=3322
PPA=landscape/ppa
ROOTSIZE=8192

rm -fR $TOPDIR
mkdir -p $TOPDIR
ssh-keygen -N '' -f $SSH_KEY

cd $TOPDIR

cat > config <<EOF
[client]
url = https://${SERVER}/message-system
computer_title = ${RELEASE} test VM $$
data_path = /var/lib/landscape/client
script_users = ALL
ping_url = http://${SERVER}/ping
include_manager_plugins = ScriptExecution
account_name = ${ACCOUNT}
registration_password = ${PASSWORD}
#log_level = debug
EOF

if ! [ "$WITH_SSL" = "" ]; then
    echo ssl_public_key = $SSL_KEY >> config
fi

cat > script-wrapper <<EOF
#!/bin/sh -e
chroot \$1 /root/script
EOF
chmod 755 script-wrapper

cat> ppa-key <<EOF
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.0.10

mI0ESXN/egEEAOgRYISU9dnQm4BB5ZEEwKT+NKUDNd/DhMYdtBMw9Yk7S5cyoqpbtwoPJVzK
AXxq+ng5e3yYypSv98pLMr5UF09FGaeyGlD4s1uaVFWkFCO4jsTg7pWIY6qzO/jMxB5+Yu/G
0GjWQMNKxFk0oHMa0PhNBZtdPacVz65mOVmCsh/lABEBAAG0G0xhdW5jaHBhZCBQUEEgZm9y
IExhbmRzY2FwZYi2BBMBAgAgBQJJc396AhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AACgkQ
boWobkZStOb+rwP+ONKUWeX+MTIPqGWkknBPV7jm8nyyIUojC4IhS+9YR6GYnn0hMABSkEHm
IV73feKmrT2GESYI1UdYeKiOkWsPN/JyBk+eTvKet0qsw5TluqiHSW+LEi/+zUyrS3dDMX3o
yaLgYa+UkjIyxnaKLkQuCiS+D+fYwnJulIkhaKObtdE=
=UwRd
-----END PGP PUBLIC KEY BLOCK-----
EOF

cat > script <<EOF
#!/bin/sh -e
chown landscape /etc/landscape/client.conf
chmod 600 /etc/landscape/client.conf
apt-key add /root/ppa-key
echo "RUN=1" > /etc/default/landscape-client
EOF
chmod 755 script

cat > manifest <<EOF
ppa-key /root
script /root/script
config /etc/landscape/client.conf
EOF

if [ "$WITH_SSL" = "yes" ]; then
    echo /etc/landscape/certs/sample_ca.crt /etc/landscape/client.conf.ssl_public_key >> manifest
fi

cat > ssh <<EOF
#!/bin/sh
exec ssh -p $SSH_PORT -i $SSH_KEY -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost
EOF
chmod 755 ssh

cat > run <<EOF
#!/bin/sh
exec kvm --redir tcp:$SSH_PORT::22 -m 1280 -smp 1 -drive file=$TOPDIR/ubuntu-kvm/disk0.qcow2 "$@"
EOF
chmod 755 run

ADDPKGS="--addpkg=landscape-client --addpkg=openssh-server"

if [ "$PROFILE" = "server" ]; then
    ADDPKGS="$ADDPKGS --addpkg apache2-mpm-prefork --addpkg postgresql --addpkg postfix"
else
    ADDPKGS="$ADDPKGS --addpkg ubuntu-desktop"
fi

if [ -n "$TMPDIR" ]; then
    TEMP_DIR_OPT="-t $TMPDIR"
fi

sudo ubuntu-vm-builder kvm "$RELEASE" --rootsize=$ROOTSIZE --mirror="$MIRROR" --ppa="$PPA" $ADDPKGS --execscript=./script-wrapper --copy=manifest --ssh-key=$SSH_KEY.pub $TEMP_DIR_OPT