4
# This script is meant to "kvmify" an image. Its not meant to be
5
# terribly robust, or a good idea to ever run in a "real image".
6
# its' only intended method of invocation is from the kernel as 'init'
7
# in which case it will then invoke /sbin/init after it is done
8
# init=/path/to/kvmify-init
13
MARK=/var/lib/cloud/sem/uncloud-init.once
17
if [ -n "$ROOT_RW" ]; then
18
mkdir -p "${MARK%/*}";
22
log "invoking /sbin/init $*"
25
log() { echo "::${0##*/}:" "$@"; }
27
[ -z "${UMOUNT}" ] || { umount "${UMOUNT}" && unset UMOUNT; }
28
[ -z "${RMDIR}" ] || { rm -Rf "${RMDIR}" && unset RMDIR; }
29
[ -z "${ROOT_RW}" ] || { mount -o remount,ro / ; unset ROOT_RW; }
36
[ "${fmt}" = "tar" -o "${fmt}" = "mnt" ] ||
37
{ log FAIL "unknown format ${fmt}"; return 1; }
39
log INFO "updating from ${dev} format ${fmt}"
40
[ ! -e "${dev}" -a -e "/dev/${dev}" ] && dev="/dev/${dev}"
41
[ -e "${dev}" ] || { echo "no file $dev"; return 2; }
43
mp=$(mktemp -d "${TEMPDIR:-/tmp}/update.XXXXXX") &&
45
{ log FAIL "failed to mktemp"; return 1; }
47
if [ "$fmt" = "tar" ]; then
48
dd "if=${dev}" | ( tar -C "${mp}" -xf - ) ||
49
{ log FAIL "failed to extract ${dev}"; return 1; }
50
elif [ "$fmt" = "mnt" ]; then
51
mount -o ro "${dev}" "${mp}" && UMOUNT=${mp} ||
52
{ log FAIL "failed mount ${mp}"; return 1; }
54
log FAIL "unknown format ${fmt}"; return 1;
57
if [ -d "${mp}/updates" ]; then
58
rsync -av "${mp}/updates/" "/" ||
59
{ log FAIL "failed rsync updates/ /"; return 1; }
61
if [ -f "${mp}/updates.tar" ]; then
62
tar -C / -xvf "${mp}/updates.tar" ||
63
{ log FAIL "failed tar -C / -xvf ${mp}/updates.tar"; return 1; }
65
script="${mp}/updates.script"
66
if [ -f "${script}" -a -x "${script}" ]; then
67
MP_DIR=${mp} "${mp}/updates.script" ||
68
{ log FAIL "failed to run updates.script"; return 1; }
72
fail() { { [ $# -eq 0 ] && log "FAILING" ; } || log "$@"; exit 1; }
74
[ -s "$MARK" ] && { log "already updated" ; doexec "$@"; }
76
mount -o remount,rw / || fail "failed to mount rw"
79
if [ ! -e /proc/cmdline ]; then
80
mount -t proc /proc /proc
81
read cmdline < /proc/cmdline
84
read cmdline < /proc/cmdline
89
for x in ${cmdline}; do
94
[ "${dev}" = "${val}" ] && fmt="" || fmt=${val#${dev}:}
95
log "update from ${dev},${fmt}"
96
updateFrom "${dev}" "${fmt}" || fail "update failed"
97
log "end update ${dev},${fmt}"
99
ubuntu-pass=*|ubuntu_pass=*) ubuntu_pass=${x#*=};;
100
helpmount) helpmount=1;;
101
root=*) rootspec=${x#root=};;
105
if [ "${ubuntu_pass}" = "R" -o "${ubuntu_pass}" = "random" ]; then
106
ubuntu_pass=$(python -c 'import string, random;
107
random.seed(); print "".join(random.sample(string.letters+string.digits, 8))')
108
log "settting ubuntu pass = ${ubuntu_pass}"
109
printf "\n===\nubuntu_pass = %s\n===\n" "${ubuntu_pass}" >/dev/ttyS0
112
[ -z "${ubuntu_pass}" ] ||
113
printf "ubuntu:%s\n" "${ubuntu_pass}" > /root/ubuntu-user-pass
115
if [ -e /root/ubuntu-user-pass ]; then
116
log "changing ubuntu user's password!"
117
chpasswd < /root/ubuntu-user-pass ||
118
log "FAIL: failed changing pass"
121
cp /etc/init/tty2.conf /etc/init/ttyS0.conf &&
122
sed -i s,tty2,ttyS0,g /etc/init/ttyS0.conf 2>/dev/null &&
123
log "enabled console on ttyS0"
125
pa=PasswordAuthentication
126
sed -i "s,${pa} no,${pa} yes," /etc/ssh/sshd_config 2>/dev/null &&
127
log "enabled passwd auth in ssh" ||
128
log "failed to enable passwd ssh"
130
grep -q vga16fb /etc/modprobe.d/blacklist.conf || {
131
echo "blacklist vga16fb" >> /etc/modprobe.d/blacklist.conf &&
132
log "blacklisted vga16fb"
136
#if ! grep -q "^${lstr}[[:space:]]" /etc/fstab; then
137
# log "changing / in /etc/ftab to agree with cmdline (${lstr}) (bug 509841)"
138
# sed -i "s,^\([^[[:space:]#]\+\)\([[:space:]]\+\)/\([[:space:]]\+\),${lstr}\2/\3," /etc/fstab