#!/bin/sh -u # unpack some tar archives containing image fragments and assemble a JPEG image # ----- # Syntax: $0 # ----- # Purpose: # (Sample solution to Exercise #3) # Examine a tar archive and locate 2,725 image fragment files hidden # in various places. Assemble the image fragments into a JPEG image. # Issue status reports at each step of the process, showing that we # have the correct files available at each step. # ----- # Student Name: Ben Dover # Algonquin EMail Address: abcd0001 # Student Number: 074-210-779 # Course Number: DAT2330 # Lab Section Number: 014 # Professor Name: Ian Allen # Assignment Name/Number/Date: Exercise #3 due March 9, 2004 # Comment: number one of two files # ----- # -IAN! idallen@idallen.ca # Use a standard search path and friendly umask for the commands in this script. # PATH=/bin:/usr/bin export PATH umask 022 # Set the name of the temporary directory we will use; # this directory will be removed at the end of the script. # tmpdir=tmpdir # Silently remove any previous existing "$tmpdir". # Create a new temporary directory and make it the current directory. # Show the current directory. # echo "--- Part (a) ---" rm -rf "$tmpdir" mkdir "$tmpdir" || exit 1 cd "$tmpdir" || exit 1 pwd # Link the hidden tar file from the instructor to the current directory. # I know that this is a compressed tar archive, so I name it "my.tar.gz". # Expand the tar file and remove (unlink) it. # Show a count of files in the current directory. # echo "--- Part (b) ---" ln ~idallen/public_html/teaching/dat2330/04w/notes/.exercise03 my.tar.gz \ || exit 1 tar xzf my.tar.gz || exit 1 rm my.tar.gz ls -a | wc # We already determined which of the contained files were tar files. # Do a verbose count of their contents. # echo "--- Part (c) ---" tar tvf part1 | wc tar tvf part2 | wc tar tzvf part3 | wc # Expand these tar files and delete them. # Run a word count on the directory to show how many files it contains. # Run a second count to show how many pathnames are under this directory. # echo "--- Part (d) ---" tar xf part1 || exit 1 tar xf part2 || exit 1 tar xzf part3 || exit 1 rm part[123] ls -a | wc find | wc # Count pathnames containing "/x". # Count pathnames containing "/x" and containing "part1". # Count pathnames containing "/x" and NOT containing "part1". # echo "--- Part (e) ---" find | grep "/x" | wc find | grep "/x" | grep "part1" | wc find | grep "/x" | grep -v "part1" | wc # Go to the directory containing compressed files and uncompress them. # Show a file count and name checksum on each of the two directories. # echo "--- Part (f) ---" cd ".part 2/.Part 2/. Part2" gunzip *.gz || exit 1 ls | wc ls | sum cd ../../.. || exit 1 cd ".part1/.parT1/.paRt1" || exit 1 ls | wc ls | sum cd ../../.. || exit 1 # We already determined where the "mystery" file was. # We examined it and found that it was a compressed tar archive full # of bzip2 compressed image fragments. Make a new temp directory and # expand the archive there, then uncompress the fragments. # Show a file count and name checksum on the directory. # echo "--- Part (g) ---" mkdir p3 || exit 1 cd p3 || exit 1 tar xzf "../.?????/.*****/.[][][]/mystery" || exit 1 bunzip2 *.bz2 || exit 1 ls | wc ls | sum cd .. || exit 1 # Set the name of the output file for the image. # Create the image from the pieces. # Show some stats on the image. # Move the image up to the parent directory (where we started). # Move to the parent. # Delete the entire temp directory used to create the image. # echo "--- Part (h) ---" tuxfile=tux-kong.jpg cat ".part1/.parT1/.paRt1"/* ".part 2/.Part 2/. Part2"/* p3/* >"$tuxfile" \ || exit 1 wc "$tuxfile" sum "$tuxfile" mv "$tuxfile" .. || exit 1 cd .. || exit 1 rm -r "$tmpdir" # The script exits with the return status of the last command executed.