XAR="xar" # Create an archive. # 1st arg: the archive to create # 2nd arg: the file to add to the archive create_archive() { ${XAR} -cf $1 $2 if [ $? -ne 0 ]; then echo "Error creating archive" exit 1 fi } # Extract an archive. Exit on failure # 1st argument: archive to extract # 2nd argument (optional): file to extract from archive extract_archive() { ${XAR} -xf $1 $2 if [ $? -ne 0 ]; then echo "Error extracting archive" exit 1 fi } # Check if 2 files are linked. Exit on failure # 1st and 2nd argument: files to see if they are the same check_hardlink() { local a=$1 local b=$2 local inode1 inode2 if [ ! -f "${a}" ]; then echo "Didn't extract file from archive 1" exit 1 fi if [ ! -f "${b}" ]; then echo "Didn't extract file from archive 1" exit 1 fi inode1=`ls -i "${a}" | awk '{print $1}'` inode2=`ls -i "${b}" | awk '{print $1}'` if [ "$inode1" != "$inode2" ]; then echo "Inodes of extracted hardlinks not the same" exit1 fi }