#!/bin/sh
#
# unlock -- unlocking for 'lock'
# (C) Christian Peper, 08/1995, v1.0
#
#   Usage: unlock file 
#   A non-existing file is not processed. If the file is edited by another 
#   user 'user', the file name suffix is extended to 'file.mudit.user'.
#   Note, that 
#     - you must have read/write permission to both file and directory, 
#     - the file you wish to 'unlock' must already exist 

continue=:
while $continue; do
   case $1 in
#    -ed)
#      shift
#      ed=$1
#      shift
#      ;;
    *)
      efile=$1
      continue=false
      ;;
  esac
done

ext1=lock 
ext2=$USER
efmvd=$efile.$ext1
efcpd=$efile.$ext1.$ext2

if [ $efile ] 
then
  if [ -f $efcpd ] 
  then                     # END CRITICAL SECTION
     cp  $efcpd $efmvd        # Restore edited file with old rights by cp.
     mv  $efmvd $efile        # Move back to original name.
     rm  $efcpd               # Remove temporary copy
     echo $efile unlocked.

  else echo 'unlock: File <'$efile'> is not locked or something worse.'
  fi
else echo 'unlock: No file specified. Usage: unlock filename'
fi
