9
by Scott Moser
add 'src' from old ttylinux-uec (revno 55). |
1 |
#!/bin/sh
|
2 |
# vi: ts=4 noexpandtab
|
|
3 |
||
4 |
XN=cloud-userdata |
|
5 |
. /etc/rc.d/init.d/cloud-functions |
|
6 |
||
7 |
start() { |
|
8 |
local iid="" shebang="" a="" udf="${STATE_D}/userdata" |
|
9 |
is_nocloud && return 0 |
|
10 |
mdget instance-id ||
|
|
11 |
{ msg "failed to read instance id"; return 1; } |
|
12 |
||
13 |
iid=${_RET} |
|
14 |
[ -n "${iid}" -a "${iid#i-}" != "${iid}" ] || |
|
15 |
{ echo "failed to read instance-id, found ${iid}"; return 1; } |
|
16 |
||
17 |
marked ${iid} && |
|
18 |
{ msg "user data previously read"; return 0; } |
|
19 |
||
20 |
mark ${iid} |
|
21 |
||
22 |
wget -q -O - "${UDURL}" > "${udf}" || |
|
23 |
{ msg "failed to read user data url: ${UDURL}"; return 1; } |
|
24 |
||
25 |
shebang="#!" |
|
26 |
read a < "${udf}" |
|
27 |
[ "${a#${shebang}}" = "${a}" ] && |
|
28 |
{ msg "user data not a script"; return 0; } |
|
29 |
||
30 |
chmod 755 "${udf}" |
|
31 |
exec "${udf}" |
|
32 |
}
|
|
33 |
||
34 |
case "$1" in |
|
35 |
start) start;; |
|
36 |
*) msg "unknown argument ${1}";; |
|
37 |
esac
|