Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This utility extracts an SDK image tarball using pseudo, and stores |
| 4 | # the pseudo database in var/pseudo within the rootfs. If you want to |
| 5 | # boot QEMU using an nfsroot, you *must* use this script to create the |
| 6 | # rootfs to ensure it is done correctly with pseudo. |
| 7 | # |
| 8 | # Copyright (c) 2010 Intel Corp. |
| 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 version 2 as |
| 12 | # published by the Free Software Foundation. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 17 | # See the GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program; if not, write to the Free Software |
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | |
| 23 | function usage() { |
| 24 | echo "Usage: $0 <image-tarball> <extract-dir>" |
| 25 | } |
| 26 | |
| 27 | if [ $# -ne 2 ]; then |
| 28 | usage |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null` |
| 33 | if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 34 | echo "Error: Unable to find the oe-find-native-sysroot script" |
| 35 | echo "Did you forget to source your build system environment setup script?" |
| 36 | exit 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | . $SYSROOT_SETUP_SCRIPT meta-ide-support |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr" |
| 40 | |
| 41 | ROOTFS_TARBALL=$1 |
| 42 | SDK_ROOTFS_DIR=$2 |
| 43 | |
| 44 | if [ ! -e "$ROOTFS_TARBALL" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 45 | echo "Error: sdk tarball '$ROOTFS_TARBALL' does not exist" |
| 46 | usage |
| 47 | exit 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | fi |
| 49 | |
| 50 | # Convert SDK_ROOTFS_DIR to a full pathname |
| 51 | if [[ ${SDK_ROOTFS_DIR:0:1} != "/" ]]; then |
| 52 | SDK_ROOTFS_DIR=$(readlink -f $(pwd)/$SDK_ROOTFS_DIR) |
| 53 | fi |
| 54 | |
| 55 | TAR_OPTS="" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | if [[ "$ROOTFS_TARBALL" =~ tar\.xz$ ]]; then |
| 57 | TAR_OPTS="--numeric-owner -xJf" |
| 58 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | if [[ "$ROOTFS_TARBALL" =~ tar\.bz2$ ]]; then |
| 60 | TAR_OPTS="--numeric-owner -xjf" |
| 61 | fi |
| 62 | if [[ "$ROOTFS_TARBALL" =~ tar\.gz$ ]]; then |
| 63 | TAR_OPTS="--numeric-owner -xzf" |
| 64 | fi |
| 65 | if [[ "$ROOTFS_TARBALL" =~ \.tar$ ]]; then |
| 66 | TAR_OPTS="--numeric-owner -xf" |
| 67 | fi |
| 68 | if [ -z "$TAR_OPTS" ]; then |
| 69 | echo "Error: Unable to determine sdk tarball format" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 70 | echo "Accepted types: .tar / .tar.gz / .tar.bz2 / .tar.xz" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | if [ ! -d "$SDK_ROOTFS_DIR" ]; then |
| 75 | echo "Creating directory $SDK_ROOTFS_DIR" |
| 76 | mkdir -p "$SDK_ROOTFS_DIR" |
| 77 | fi |
| 78 | |
| 79 | pseudo_state_dir="$SDK_ROOTFS_DIR/../$(basename "$SDK_ROOTFS_DIR").pseudo_state" |
| 80 | pseudo_state_dir="$(readlink -f $pseudo_state_dir)" |
| 81 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 82 | debug_image="`echo $ROOTFS_TARBALL | grep '\-dbg\.tar\.'`" |
| 83 | |
| 84 | if [ -e "$pseudo_state_dir" -a -z "$debug_image" ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | echo "Error: $pseudo_state_dir already exists!" |
| 86 | echo "Please delete the rootfs tree and pseudo directory manually" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 87 | echo "if this is really what you want." |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | exit 1 |
| 89 | fi |
| 90 | |
| 91 | mkdir -p "$pseudo_state_dir" |
| 92 | touch "$pseudo_state_dir/pseudo.pid" |
| 93 | PSEUDO_LOCALSTATEDIR="$pseudo_state_dir" |
| 94 | export PSEUDO_LOCALSTATEDIR |
| 95 | |
| 96 | echo "Extracting rootfs tarball using pseudo..." |
| 97 | echo "$PSEUDO $PSEUDO_OPTS tar -C \"$SDK_ROOTFS_DIR\" $TAR_OPTS \"$ROOTFS_TARBALL\"" |
| 98 | $PSEUDO $PSEUDO_OPTS tar -C "$SDK_ROOTFS_DIR" $TAR_OPTS "$ROOTFS_TARBALL" |
| 99 | |
| 100 | DIRCHECK=`ls -l "$SDK_ROOTFS_DIR" | wc -l` |
| 101 | if [ "$DIRCHECK" -lt 5 ]; then |
| 102 | echo "Warning: I don't see many files in $SDK_ROOTFS_DIR" |
| 103 | echo "Please double-check the extraction worked as intended" |
| 104 | exit 0 |
| 105 | fi |
| 106 | |
| 107 | echo "SDK image successfully extracted to $SDK_ROOTFS_DIR" |
| 108 | |
| 109 | exit 0 |