|
|
#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: target/share/initramfs/pack_and_push.sh # Copyright (C) 2008 - 2009 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
die() { echo "ERROR: $*" >&2; exit 127; }
usage() { [ $# -eq 0 ] || echo "ERROR: $*" cat <<-EOT Usage: ${0##*/} -c <config_build> -e <config_early> [-s <suffix>] [<target>] EOT exit 1 }
rsyncopt="-ztP --inplace" config_build= config_early= SUFFIX= force=
while [ $# -gt 0 ]; do case "$1" in -c|--cfg) config_build="$2"; shift ;; -e|--early) config_early="$2"; shift ;; -s|--suffix) SUFFIX="$2"; shift ;; -f|--force) force=yes ;; --) shift; break ;; -*) usage "$1: Invalid option." ;; *) break ;; esac shift done
case "$#" in 0) TARGETDIR= ;; 1) TARGETDIR="$1"; shift ;; *) usage "Too many arguments." ;; esac
[ -n "$config_build" -a -n "$config_early" ] || usage
BUILD=$(grep SDECFG_ID= config/$config_build/config | cut -d"'" -f2) EARLY=$(grep SDECFG_ID= config/$config_early/config | cut -d"'" -f2)
[ -n "$BUILD" -a -d "build/$BUILD/TOOLCHAIN" ] || die "$config_build: Invalid config."
[ -n "$EARLY" -a -d "build/$EARLY/TOOLCHAIN" ] || die "$config_early: Invalid config."
BUILD="build/$BUILD" EARLY="build/$EARLY" INITRD="$EARLY/TOOLCHAIN/initrd.img"
KERVER=$(cd "$BUILD/boot" && ls -1 vmlinuz_* | tail -n1 | cut -d_ -f2-)
[ -n "$KERVER" ] || die "$config_build: no kernel found." [ -s "$INITRD" ] || die "$config_early: no initrd template found."
echo "packing: $config_build + $config_early"
vmlinuz="$BUILD/boot/vmlinuz_$KERVER" initrd="$BUILD/boot/initrd-${SUFFIX:-$KERVER}.img"
errno=0 if [ -n "$force" -o "$vmlinuz" -nt "$initrd" -o "$INITRD" -nt "$initrd" ]; then "$BUILD/usr/sbin/mkinitramfs" -R "$BUILD" -T "$INITRD" ${SUFFIX:+-s "$SUFFIX"} "$KERVER" errno=$? else echo "WARNING: skipping new image creation, use -f to force it." fi
[ $errno -eq 0 ] || exit $errno
[ -s "$vmlinuz" ] || die "\${root}/boot/vmlinuz_$KERVER: not found." [ -s "$initrd" ] || die "\${root}/boot/initrd-$KERVER.img: not found."
if [ -n "$TARGETDIR" ]; then source=$(mktemp -d -p "$BUILD/tmp/") [ -d "$source" ] || die "failed to create tempdir."
[ -n "$SUFFIX" ] || SUFFIX="$KERVER"
cp -l "$initrd" "$source/initrd-$SUFFIX.img" cp -l "$vmlinuz" "$source/vmlinuz_$SUFFIX"
if [ $UID -eq 0 -a -n "$SUDO_UID" ]; then echo "pushing as $SUDO_USER to $TARGETDIR/" chown -R "$SUDO_UID:$SUDO_GID" "$source/" su $SUDO_USER -c "rsync $rsyncopt '$source'/* '$TARGETDIR/'" else echo "pushing to $TARGETDIR/" rsync $rsyncopt "$source"/* "$TARGETDIR/" fi
rm -rf "$source" fi
|