Advertisement
Guest User

identify first rar volume

a guest
Mar 20th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. for FILE_PATH; do
  4.         HEAD_FLAGS="0x$(od -x -N20 "$FILE_PATH" | awk 'NR=1{print $7;exit}')" # read first 20 bytes from file
  5.         VOLUME_FLAG="0x0001"
  6.         FIRST_FLAG="0x0100"
  7.  
  8.         if [ $(($HEAD_FLAGS&$VOLUME_FLAG)) -ne 0 ]; then # is volume
  9.                 if [ $(($HEAD_FLAGS&$FIRST_FLAG)) -ne 0 ]; then # is first volume
  10.                         echo "$FILE_PATH is the first volume"
  11.                 else
  12.                         echo "$FILE_PATH is NOT the first volume"
  13.                 fi
  14.         else # is regular, single rar archive
  15.                 echo "$FILE_PATH is a regular, single RAR-file"
  16.         fi
  17. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement