| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# This code is covered by the GNU General Public License (GPLv2 or higher) |
| 4 |
|
| 5 |
set -e |
| 6 |
|
| 7 |
FK_DIR="/usr/share/flash-kernel" |
| 8 |
|
| 9 |
. "${FK_CHECKOUT:-$FK_DIR}/functions" |
| 10 |
|
| 11 |
. /usr/share/debconf/confmodule |
| 12 |
|
| 13 |
log() { |
| 14 |
logger -t flash-kernel-installer "$@" |
| 15 |
} |
| 16 |
|
| 17 |
error() { |
| 18 |
log "error: $@" |
| 19 |
db_progress STOP |
| 20 |
exit 1 |
| 21 |
} |
| 22 |
|
| 23 |
findfs () { |
| 24 |
mount | grep "on /target${1%/} " | tail -n1 | cut -d' ' -f1 |
| 25 |
} |
| 26 |
|
| 27 |
tac () { |
| 28 |
sed '1!G;h;$!d' |
| 29 |
} |
| 30 |
|
| 31 |
get_machine |
| 32 |
|
| 33 |
if machine_uses_flash "$machine"; then |
| 34 |
db_progress START 0 3 flash-kernel-installer/progress |
| 35 |
else |
| 36 |
db_progress START 0 3 flash-kernel-installer/progress_disk |
| 37 |
fi |
| 38 |
db_progress INFO flash-kernel-installer/prepare |
| 39 |
|
| 40 |
# Stop fsck from prompting the user for input since most users don't |
| 41 |
# have a serial console. |
| 42 |
if [ -e /target/etc/default/rcS ]; then |
| 43 |
sed -i -e "s/^FSCKFIX=no$/FSCKFIX=yes/" /target/etc/default/rcS || true |
| 44 |
fi |
| 45 |
if [ -e /target/etc/default/fsck ]; then |
| 46 |
sed -i -e "s/^#FSCKFIX=no$/FSCKFIX=yes/" -e "s/^FSCKFIX=no$/FSCKFIX=yes/" /target/etc/default/fsck || true |
| 47 |
fi |
| 48 |
|
| 49 |
def_params="@DEFAULT_CMDLINE@" |
| 50 |
# reverse them so we prefix them in the right order |
| 51 |
rev_def_params="$(echo $def_params | tr ' ' '\n' | tac)" |
| 52 |
user_params=$(user-params) || true |
| 53 |
kopt_params="$user_params" |
| 54 |
for d_param in $rev_def_params; do |
| 55 |
# Don't add redundant default params |
| 56 |
if echo $kopt_params | tr ' ' '\n' | grep -q "^${d_param}$"; then |
| 57 |
continue |
| 58 |
else |
| 59 |
kopt_params="$d_param${kopt_params:+ $kopt_params}" |
| 60 |
fi |
| 61 |
done |
| 62 |
|
| 63 |
echo flash-kernel flash-kernel/linux_cmdline string $kopt_params | \ |
| 64 |
chroot /target debconf-set-selections |
| 65 |
|
| 66 |
if ! apt-install flash-kernel; then |
| 67 |
error "apt-install flash-kernel failed" |
| 68 |
fi |
| 69 |
|
| 70 |
# Temporarily move flash-kernel out of the way so update-initramfs |
| 71 |
# won't call flash-kernel; otherwise we might call it twice. |
| 72 |
mv /target/usr/sbin/flash-kernel /target/tmp/flash-kernel.$$ |
| 73 |
trap "mv /target/tmp/flash-kernel.$$ /target/usr/sbin/flash-kernel" EXIT HUP INT QUIT TERM |
| 74 |
|
| 75 |
db_progress STEP 1 |
| 76 |
|
| 77 |
for package in $(get_machine_field "$machine" "Optional-Packages"); do |
| 78 |
if ! apt-install "$package"; then |
| 79 |
log "apt-install $package failed" |
| 80 |
fi |
| 81 |
done |
| 82 |
for package in $(get_machine_field "$machine" "Required-Packages"); do |
| 83 |
if ! apt-install "$package"; then |
| 84 |
error "apt-install $package failed" |
| 85 |
fi |
| 86 |
done |
| 87 |
|
| 88 |
case "$machine" in |
| 89 |
"Linksys NSLU2") |
| 90 |
# installing nslu2-utils will call update-initramfs -u |
| 91 |
: |
| 92 |
;; |
| 93 |
*) |
| 94 |
in-target update-initramfs -u || true |
| 95 |
;; |
| 96 |
esac |
| 97 |
|
| 98 |
if [ "$machine" = "HP Media Vault mv2120" ]; then |
| 99 |
# The firmware loads /boot/uImage from the first partition |
| 100 |
# but uImage will be in / if a separate boot partition is |
| 101 |
# used. In this case, create a /boot/boot -> /boot symlink. |
| 102 |
# Note that a partman check will make sure that /boot (if |
| 103 |
# it exists) or / (if there's no separate /boot) are on the |
| 104 |
# first partition. |
| 105 |
rootfs=$(findfs /) |
| 106 |
bootfs=$(findfs /boot) |
| 107 |
if [ "$rootfs" != "$bootfs" ]; then |
| 108 |
if [ ! -e /target/boot/boot ]; then |
| 109 |
ln -s . /target/boot/boot |
| 110 |
fi |
| 111 |
fi |
| 112 |
fi |
| 113 |
|
| 114 |
db_progress STEP 1 |
| 115 |
if machine_uses_flash "$machine"; then |
| 116 |
db_progress INFO flash-kernel-installer/flashing |
| 117 |
else |
| 118 |
db_progress INFO flash-kernel-installer/generating_image |
| 119 |
fi |
| 120 |
|
| 121 |
trap - EXIT HUP INT QUIT TERM |
| 122 |
mv /target/tmp/flash-kernel.$$ /target/usr/sbin/flash-kernel |
| 123 |
|
| 124 |
# We need the udev /dev which has the MTD devices |
| 125 |
mount -o bind /dev /target/dev |
| 126 |
if ! in-target flash-kernel; then |
| 127 |
umount /target/dev || true |
| 128 |
error "flash-kernel failed" |
| 129 |
fi |
| 130 |
umount /target/dev || true |
| 131 |
|
| 132 |
db_progress STEP 1 |
| 133 |
db_progress STOP |
| 134 |
|
| 135 |
# vim:noexpandtab shiftwidth=8 |