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.

117 lines
3.0 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 - 2009 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="-ztP --inplace"
  24. config_build=
  25. config_early=
  26. SUFFIX=
  27. force=
  28. while [ $# -gt 0 ]; do
  29. case "$1" in
  30. -c|--cfg)
  31. config_build="$2"; shift ;;
  32. -e|--early)
  33. config_early="$2"; shift ;;
  34. -s|--suffix)
  35. SUFFIX="$2"; shift ;;
  36. -f|--force)
  37. force=yes ;;
  38. --)
  39. shift; break ;;
  40. -*)
  41. usage "$1: Invalid option."
  42. ;;
  43. *)
  44. break
  45. ;;
  46. esac
  47. shift
  48. done
  49. case "$#" in
  50. 0) TARGETDIR= ;;
  51. 1) TARGETDIR="$1"; shift ;;
  52. *) usage "Too many arguments." ;;
  53. esac
  54. [ -n "$config_build" -a -n "$config_early" ] || usage
  55. BUILD=$(grep SDECFG_ID= config/$config_build/config | cut -d"'" -f2)
  56. EARLY=$(grep SDECFG_ID= config/$config_early/config | cut -d"'" -f2)
  57. [ -n "$BUILD" -a -d "build/$BUILD/TOOLCHAIN" ] ||
  58. die "$config_build: Invalid config."
  59. [ -n "$EARLY" -a -d "build/$EARLY/TOOLCHAIN" ] ||
  60. die "$config_early: Invalid config."
  61. BUILD="build/$BUILD"
  62. EARLY="build/$EARLY"
  63. INITRD="$EARLY/TOOLCHAIN/initrd.img"
  64. KERVER=$(cd "$BUILD/boot" && ls -1 vmlinuz_* | tail -n1 | cut -d_ -f2-)
  65. [ -n "$KERVER" ] || die "$config_build: no kernel found."
  66. [ -s "$INITRD" ] || die "$config_early: no initrd template found."
  67. echo "packing: $config_build + $config_early"
  68. vmlinuz="$BUILD/boot/vmlinuz_$KERVER"
  69. initrd="$BUILD/boot/initrd-${SUFFIX:-$KERVER}.img"
  70. errno=0
  71. if [ -n "$force" -o "$vmlinuz" -nt "$initrd" -o "$INITRD" -nt "$initrd" ]; then
  72. "$BUILD/usr/sbin/mkinitramfs" -R "$BUILD" -T "$INITRD" ${SUFFIX:+-s "$SUFFIX"} "$KERVER"
  73. errno=$?
  74. else
  75. echo "WARNING: skipping new image creation, use -f to force it."
  76. fi
  77. [ $errno -eq 0 ] || exit $errno
  78. [ -s "$vmlinuz" ] || die "\${root}/boot/vmlinuz_$KERVER: not found."
  79. [ -s "$initrd" ] || die "\${root}/boot/initrd-$KERVER.img: not found."
  80. if [ -n "$TARGETDIR" ]; then
  81. source=$(mktemp -d -p "$BUILD/tmp/")
  82. [ -d "$source" ] || die "failed to create tempdir."
  83. [ -n "$SUFFIX" ] || SUFFIX="$KERVER"
  84. cp -l "$initrd" "$source/initrd-$SUFFIX.img"
  85. cp -l "$vmlinuz" "$source/vmlinuz_$SUFFIX"
  86. if [ $UID -eq 0 -a -n "$SUDO_UID" ]; then
  87. echo "pushing as $SUDO_USER to $TARGETDIR/"
  88. chown -R "$SUDO_UID:$SUDO_GID" "$source/"
  89. su $SUDO_USER -c "rsync $rsyncopt '$source'/* '$TARGETDIR/'"
  90. else
  91. echo "pushing to $TARGETDIR/"
  92. rsync $rsyncopt "$source"/* "$TARGETDIR/"
  93. fi
  94. rm -rf "$source"
  95. fi