4 # take a Snapgear upgrade image (or just an image) and try to extract the
5 # filesystem (minus dev nodes) creating a tar file based on the name of the
6 # original image. This way we can easily extract proprietry files form a
7 # released image and add them to the romfs directory of a public tree for a
8 # customer to play with
10 # David McCullough <davidm@snapgear.com>
12 ############################################################################
18 ############################################################################
23 echo "usage: $EXE flash-upgrade-image [optional-output-filename]"
27 ############################################################################
33 find . -depth \( ! -type c -a ! -type b \) -print |
34 tar cvzfT $TARFILE - --no-recursion
38 ############################################################################
42 mkdir -p /tmp/image.$$/romfs
43 if mount -o loop $1 /tmp/image.$$/romfs; then
44 INITRD="`find /tmp/image.$$ -name initrd.gz`"
45 [ "$INITRD" ] || INITRD="`find /tmp/image.$$ -name initrd`"
46 if [ -f "$INITRD" ]; then
49 transfer /tmp/image.$$
51 umount /tmp/image.$$/romfs
55 echo "Failed to mount filesystem"
56 echo "Ensure loopback and cramfs/romfs/etc work"
62 ############################################################################
64 if [ $# -lt 1 -o $# -gt 2 ]; then
65 usage "bad number of arguments"
68 if [ ! -f "$IMAGE" ]; then
69 usage "image '$IMAGE' does not exist."
75 TARFILE="`basename $IMAGE | sed 's/\.[^.]*$//'`_romfs.tar.gz"
80 *) TARFILE="`pwd`/$TARFILE" ;;
84 if [ -f "$TARFILE" ]; then
85 usage "Output file '$TARFILE' already exists, will not overwrite, exiting."
88 if ! id 2>&1 | fgrep "uid=0(" > /dev/null 2>&1
90 echo "You must be root to run this script."
91 echo "You may also need to add loopback/cramfs/romfs or other"
92 echo "support to your linux system. Watch for errors."
96 echo "Creating '$TARFILE'"
97 echo "From '$IMAGE' ..."
102 *"Linux Compressed ROM File System"*)
103 echo "$IMAGE is a CRAMFS image, extracting..."
107 *"romfs filesystem"*)
108 echo "$IMAGE is a ROMFS image, extracting..."
113 echo "$IMAGE is a ISO 9660 image, extracting..."
117 *"gzip compressed data"*)
118 echo "$IMAGE is a COMPRESSED image, extracting..."
119 gunzip < $IMAGE > /tmp/image.$$
125 # find the romfs (use last one if many)
126 ROFF="`strings -t d $IMAGE | grep -e -rom1fs- |tail -1|awk '{ print $1 }'`"
128 echo "Trying romfs@$ROFF ..."
129 dd if=$IMAGE bs=$ROFF skip=1 of=/tmp/image.$$
133 [ "$OK" -eq 0 ] && exit 0
135 echo "$IMAGE is an unknown/unhandled file type: $TYPE"
142 ############################################################################