tolikpunkoff

addarh (add current dir to archive)

Mar 4th, 2019
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. print_help()
  4. {
  5.     echo "Add current directory and subdirectories to tar.gz archive"
  6.     echo "Use "`basename $0`" [-nc]"
  7.     echo "[-nc] - add only content current directory (and subdirectories)."
  8.     echo
  9.     echo "Archive name == current directory name."
  10.     echo "Archive will be created to up-directory."
  11.     exit 1
  12. }
  13.  
  14. if [[ "$1" == "-h" || "$1" == "--help" ]]; then
  15.     print_help
  16. fi
  17.  
  18. CURDIR=`pwd`
  19.  
  20. if [ "$CURDIR" == "/" ]; then
  21.     echo "Oh, no! It's root directory!"
  22.     exit 1
  23. fi
  24.  
  25. DIRNAME=`basename $CURDIR`
  26. ARHNAME="../"$DIRNAME".tar.gz"
  27.  
  28. if [ $# -ne 1 ]; then
  29.     tar -czvf $ARHNAME "../"$DIRNAME
  30. else
  31.     if [ "$1" == "-nc" ]; then
  32.     tar -czvf $ARHNAME "."
  33.     else
  34.     echo "Wrong parameter(s)!"
  35.     echo
  36.     print_help
  37.     fi
  38. fi
Add Comment
Please, Sign In to add comment