OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.6 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: target/share/initramfs/pack_and_push.sh
  6. # Copyright (C) 2008 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. die() { echo "ERROR: $*" >&2; exit 127; }
  16. usage() {
  17. [ $# -eq 0 ] || echo "ERROR: $*"
  18. cat <<-EOT
  19. Usage: ${0##*/} -c <config_build> -e <config_early> [-s <suffix>] [<target>]
  20. EOT
  21. exit 1
  22. }
  23. rsyncopt="-ztqP"
  24. config_build=
  25. config_early=
  26. SUFFIX=
  27. while [ $# -gt 0 ]; do
  28. case "$1" in
  29. -c|--cfg)
  30. config_build="$2"; shift ;;
  31. -e|--early)
  32. config_early="$2"; shift ;;
  33. -s|--suffix)
  34. SUFFIX="$2"; shift ;;
  35. --)
  36. shift; break ;;
  37. -*)
  38. usage "$1: Invalid option."
  39. ;;
  40. *)
  41. break
  42. ;;
  43. esac
  44. shift
  45. done
  46. case "$#" in
  47. 0) TARGETDIR= ;;
  48. 1) TARGETDIR="$1"; shift ;;
  49. *) usage "Too many arguments." ;;
  50. esac
  51. [ -n "$config_build" -a -n "$config_early" ] || usage
  52. BUILD=$(grep SDECFG_ID= config/$config_build/config | cut -d"'" -f2)
  53. EARLY=$(grep SDECFG_ID= config/$config_early/config | cut -d"'" -f2)
  54. [ -n "$BUILD" -a -d "build/$BUILD/TOOLCHAIN" ] ||
  55. die "$config_build: Invalid config."
  56. [ -n "$EARLY" -a -d "build/$EARLY/TOOLCHAIN" ] ||
  57. die "$config_early: Invalid config."
  58. BUILD="build/$BUILD"
  59. EARLY="build/$EARLY"
  60. INITRD="$EARLY/TOOLCHAIN/initrd.img"
  61. KERVER=$(cd "$BUILD/boot" && ls -1 vmlinuz_* | tail -n1 | cut -d_ -f2-)
  62. [ -n "$KERVER" ] || die "$config_build: no kernel found."
  63. [ -s "$INITRD" ] || die "$config_early: no initrd template found."
  64. echo "packing: $config_build + $config_early"
  65. vmlinuz="$BUILD/boot/vmlinuz_$KERVER"
  66. initrd="$BUILD/boot/initrd-$KERVER.img"
  67. errno=0
  68. if [ "$vmlinuz" -nt "$initrd" -o "$INITRD" -nt "$initrd" ]; then
  69. "$BUILD/usr/sbin/mkinitramfs" -R "$BUILD" -T "$INITRD" "$KERVER"
  70. errno=$?
  71. fi
  72. [ $errno -eq 0 ] || exit $errno
  73. [ -s "$vmlinuz" ] || die "\${root}/boot/vmlinuz_$KERVER: not found."
  74. [ -s "$initrd" ] || die "\${root}/boot/initrd-$KERVER.img: not found."
  75. if [ -n "$TARGETDIR" ]; then
  76. source=$(mktemp -d -p "$BUILD/tmp/")
  77. [ -d "$source" ] || die "failed to create tempdir."
  78. cp -l "$initrd" "$source/initrd${SUFFIX:+-$SUFFIX}.img"
  79. cp -l "$vmlinuz" "$source/vmlinuz${SUFFIX:+-$SUFFIX}"
  80. rsync $rsyncopt "$source"/* "$TARGETDIR/"
  81. rm -rf "$source"
  82. fi