Advertisement
rockdrilla

APT shortcuts

Sep 17th, 2014
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.65 KB | None | 0 0
  1. #!/bin/bash
  2. this=$(basename "$0")
  3. there=$(dirname "$0")
  4.  
  5. idle='nice -n +40 chrt -i 0 ionice -c 3'
  6. dir_cache=/var/cache/apt/archives
  7. dir_lists=/var/lib/apt/lists
  8. f_storage=/opt/apt.lists.tar.xz
  9. compress='xz -C none -v'
  10. ratio=1
  11. N00B=1
  12.  
  13. __install()   { for i in ${shortcuts}; do ln -vfs ${N00B:+-i} "${this}" "${there}/$i"; done; }
  14. __uninstall() { for i in ${shortcuts}; do rm -vf  ${N00B:+-i} "${there}/$i"; done; }
  15.  
  16. shortcuts='a-u a-s a-r a-p'
  17.  
  18. __help() { cat >&2 <<-EOF
  19. usage:
  20.   ${this} {cmd} [args]
  21.     {a-u|u|update}
  22.     {a-s|s|save}
  23.     {a-r|r|restore}
  24.     {a-p|p|purge}
  25.  
  26.     {install}
  27.     {uninstall}
  28. EOF
  29. exit 1; }
  30. __try_file()  { local d=$(dirname "$1"); test \( -f "$1" -a -w "$1" \) -o \( ! -e "$1" -a -w "$d" \) ; }
  31. __try_dir()   { test -d "$1" -a -w "$1"; }
  32. __test_file() { test -f "$1" -a -r "$1"; }
  33. __action() {
  34.     case "$1" in
  35.     a-u|u|update)
  36.         exec ${idle} apt-get update
  37.     ;;
  38.     a-s|s|save)
  39.         __try_file "${f_storage}" || exit 1
  40.         du -hd0 "${dir_lists}"
  41.         tar cPf - "${dir_lists}" | ${idle} ${compress} -${ratio} > "${f_storage}"
  42.     ;;
  43.     a-r|r|restore)
  44.         __test_file "${f_storage}" || exit 1
  45.         ls -lh "${f_storage}"
  46.         ${idle} ${compress} -d < "${f_storage}" | tar xPf -
  47.     ;;
  48.     a-p|p|purge)
  49.         __try_dir "${dir_lists}" || exit 1
  50.         __try_dir "${dir_cache}" || exit 1
  51.         find "${dir_lists}" "${dir_cache}" -mindepth 1 -delete
  52.     ;;
  53.     install)      __install ;;
  54.     uninstall)    __uninstall ;;
  55.     *)            __help ;;
  56.     esac
  57. }
  58.  
  59. case "${this}" in
  60. apt.cmd)  [ $# -eq 0 ] && __help; __action "$@" ;;
  61. *)        __action "${this}" "$@" ;;
  62. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement