Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # This is an actually-safe install command which installs the new
  4. # file atomically in the new location, rather than overwriting
  5. # existing files.
  6. #
  7. # Examples
  8. #./smart_install.sh -D -m 644 libproxychains4.so /home/aha/.local/stow/proxychains/lib/libproxychains4.so
  9. #./smart_install.sh -D -m 755 proxychains4 /home/aha/.local/stow/proxychains/bin/proxychains4
  10. #
  11.  
  12. usage() {
  13. printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
  14. exit 1
  15. }
  16.  
  17. mkdirp=
  18. symlink=
  19. mode=755
  20.  
  21. while getopts Dlm: name ; do
  22. case "$name" in
  23. D) mkdirp=yes ;;
  24. l) symlink=yes ;;
  25. m) mode=$OPTARG ;;
  26. ?) usage ;;
  27. esac
  28. done
  29. shift $(($OPTIND - 1))
  30.  
  31. test "$#" -eq 2 || usage
  32. src=$1
  33. dst=$2
  34. tmp="$dst.tmp.$$"
  35.  
  36. case "$dst" in
  37. */) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
  38. esac
  39.  
  40. set -C
  41. set -e
  42.  
  43. if test "$mkdirp" ; then
  44. umask 022
  45. case "$2" in
  46. */*) mkdir -p "${dst%/*}" ;;
  47. esac
  48. fi
  49.  
  50. trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
  51.  
  52. umask 077
  53.  
  54. if test "$symlink" ; then
  55. ln -s "$1" "$tmp"
  56. else
  57. cat < "$1" > "$tmp"
  58. chmod "$mode" "$tmp"
  59. fi
  60.  
  61. mv -f "$tmp" "$2"
  62. test -d "$2" && {
  63. rm -f "$2/$tmp"
  64. printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
  65. exit 1
  66. }
  67.  
  68. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement